Catch IOException in ConfigureGerritAfterCloneTask

This task must not make the git clone be reported as failed -- the
repository was already successfully cloned. Catch the exception and
return false, which is the safe thing to do: in the worst case, the
user may have to do the Gerrit config setup him- or herself via the
ConfigureGerritWizard.

Also clean up closing streams and disconnecting.

Bug: 494342
Change-Id: Ie10cb12da8e8d732c956e7352c15702898e23710
Signed-off-by: Thomas Wolf <thomas.wolf@paranor.ch>
diff --git a/org.eclipse.egit.core/src/org/eclipse/egit/core/op/ConfigureGerritAfterCloneTask.java b/org.eclipse.egit.core/src/org/eclipse/egit/core/op/ConfigureGerritAfterCloneTask.java
index 579e6ff..62eb62d 100644
--- a/org.eclipse.egit.core/src/org/eclipse/egit/core/op/ConfigureGerritAfterCloneTask.java
+++ b/org.eclipse.egit.core/src/org/eclipse/egit/core/op/ConfigureGerritAfterCloneTask.java
@@ -162,8 +162,8 @@
 			if (HTTPS.equals(s) && (u.getPort() == 443 || u.getPort() == -1)
 					&& path != null && path.startsWith(GERRIT_CONTEXT_ROOT)) {
 				return true;
-			} else
-				if (SSH.equals(s) && u.getPort() == GERRIT_SSHD_DEFAULT_PORT) {
+			} else if (SSH.equals(s)
+					&& u.getPort() == GERRIT_SSHD_DEFAULT_PORT) {
 				return true;
 			}
 		}
@@ -172,52 +172,45 @@
 			String baseURL = u.setPath("/").toString(); //$NON-NLS-1$
 			baseURL = baseURL.substring(0, baseURL.length() - 1);
 			String tmpPath = ""; //$NON-NLS-1$
-			HttpURLConnection httpConnection = null;
-			try {
-				int slash = 1;
-				while (true) {
-					InputStream in = null;
-					try {
-						httpConnection = (HttpURLConnection) new URL(baseURL
-								+ tmpPath + GERRIT_CONFIG_SERVER_VERSION_API)
-								.openConnection();
-						NetUtil.setSslVerification(repo, httpConnection);
-						httpConnection.setRequestMethod("GET"); //$NON-NLS-1$
-						httpConnection.setReadTimeout(1000 * timeout);
-						int responseCode = httpConnection.getResponseCode();
-						switch (responseCode) {
-						case HttpURLConnection.HTTP_OK:
-							in = httpConnection.getInputStream();
+			int slash = 1;
+			while (true) {
+				HttpURLConnection httpConnection = null;
+				try {
+					httpConnection = (HttpURLConnection) new URL(baseURL
+							+ tmpPath + GERRIT_CONFIG_SERVER_VERSION_API)
+									.openConnection();
+					NetUtil.setSslVerification(repo, httpConnection);
+					httpConnection.setRequestMethod("GET"); //$NON-NLS-1$
+					httpConnection.setReadTimeout(1000 * timeout);
+					int responseCode = httpConnection.getResponseCode();
+					switch (responseCode) {
+					case HttpURLConnection.HTTP_OK:
+						try (InputStream in = httpConnection.getInputStream()) {
 							String response = readFully(in, "UTF-8"); //$NON-NLS-1$
-							if (response.startsWith(GERRIT_XSSI_MAGIC_STRING)) {
-								return true;
-							} else {
-								return false;
-							}
-						case HttpURLConnection.HTTP_NOT_FOUND:
-							if (slash > path.length()) {
-								return false;
-							}
-							slash = path.indexOf('/', slash);
-							if (slash == -1) {
-								// try the entire path
-								slash = path.length();
-							}
-							tmpPath = path.substring(0, slash);
-							slash++;
-							break;
-						default:
+							return response
+									.startsWith(GERRIT_XSSI_MAGIC_STRING);
+						}
+					case HttpURLConnection.HTTP_NOT_FOUND:
+						if (slash > path.length()) {
 							return false;
 						}
-					} finally {
-						if (in != null) {
-							in.close();
+						slash = path.indexOf('/', slash);
+						if (slash == -1) {
+							// try the entire path
+							slash = path.length();
 						}
+						tmpPath = path.substring(0, slash);
+						slash++;
+						break;
+					default:
+						return false;
 					}
-				}
-			} finally {
-				if (httpConnection != null) {
-					httpConnection.disconnect();
+				} catch (IOException e) {
+					return false;
+				} finally {
+					if (httpConnection != null) {
+						httpConnection.disconnect();
+					}
 				}
 			}
 		} else if (SSH.equals(s)) {