Commit d0ec5054 authored by Joshua Pawlicki's avatar Joshua Pawlicki Committed by Commit Bot

Android Omaha client: Avoid catching "programmer error" exceptions.

I've tried to remove exception handling for unchecked exceptions caused
by programmer error - catching these hides bugs that we would otherwise
detect.

Bug: 1110340
Change-Id: Id06136367c7b342ff5714118305eda6bf8ba652b
Fixed: 1110340
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2412134
Commit-Queue: Tommy Nyquist <nyquist@chromium.org>
Reviewed-by: default avatarTommy Nyquist <nyquist@chromium.org>
Auto-Submit: Joshua Pawlicki <waffles@chromium.org>
Cr-Commit-Position: refs/heads/master@{#810509}
parent b5ceaaa7
...@@ -29,7 +29,6 @@ import java.io.OutputStreamWriter; ...@@ -29,7 +29,6 @@ import java.io.OutputStreamWriter;
import java.lang.annotation.Retention; import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy; import java.lang.annotation.RetentionPolicy;
import java.net.HttpURLConnection; import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.URL; import java.net.URL;
import java.util.Date; import java.util.Date;
...@@ -423,12 +422,8 @@ public class OmahaBase { ...@@ -423,12 +422,8 @@ public class OmahaBase {
* @throws RequestFailureException if the request fails. * @throws RequestFailureException if the request fails.
*/ */
private String postRequest(long timestamp, String xml) throws RequestFailureException { private String postRequest(long timestamp, String xml) throws RequestFailureException {
String response = null; HttpURLConnection urlConnection = createConnection();
HttpURLConnection urlConnection = null;
try { try {
urlConnection = createConnection();
// Prepare the HTTP header. // Prepare the HTTP header.
urlConnection.setDoOutput(true); urlConnection.setDoOutput(true);
urlConnection.setFixedLengthStreamingMode( urlConnection.setFixedLengthStreamingMode(
...@@ -438,20 +433,10 @@ public class OmahaBase { ...@@ -438,20 +433,10 @@ public class OmahaBase {
urlConnection.addRequestProperty("X-RequestAge", age); urlConnection.addRequestProperty("X-RequestAge", age);
} }
response = OmahaBase.sendRequestToServer(urlConnection, xml); return OmahaBase.sendRequestToServer(urlConnection, xml);
} catch (IllegalAccessError e) {
throw new RequestFailureException("Caught an IllegalAccessError:", e);
} catch (IllegalArgumentException e) {
throw new RequestFailureException("Caught an IllegalArgumentException:", e);
} catch (IllegalStateException e) {
throw new RequestFailureException("Caught an IllegalStateException:", e);
} finally { } finally {
if (urlConnection != null) { urlConnection.disconnect();
urlConnection.disconnect();
}
} }
return response;
} }
/** /**
...@@ -465,8 +450,6 @@ public class OmahaBase { ...@@ -465,8 +450,6 @@ public class OmahaBase {
connection.setConnectTimeout(MS_CONNECTION_TIMEOUT); connection.setConnectTimeout(MS_CONNECTION_TIMEOUT);
connection.setReadTimeout(MS_CONNECTION_TIMEOUT); connection.setReadTimeout(MS_CONNECTION_TIMEOUT);
return connection; return connection;
} catch (MalformedURLException e) {
throw new RequestFailureException("Caught a malformed URL exception.", e);
} catch (IOException e) { } catch (IOException e) {
throw new RequestFailureException("Failed to open connection to URL", e, throw new RequestFailureException("Failed to open connection to URL", e,
RequestFailureException.ERROR_CONNECTIVITY); RequestFailureException.ERROR_CONNECTIVITY);
...@@ -594,7 +577,9 @@ public class OmahaBase { ...@@ -594,7 +577,9 @@ public class OmahaBase {
writer.write(request, 0, request.length()); writer.write(request, 0, request.length());
StreamUtil.closeQuietly(writer); StreamUtil.closeQuietly(writer);
checkServerResponseCode(urlConnection); checkServerResponseCode(urlConnection);
} catch (IOException | SecurityException | ArrayIndexOutOfBoundsException e) { } catch (IOException | SecurityException | IndexOutOfBoundsException e) {
// IndexOutOfBoundsException is thought to be triggered by a bug in okio.
// TODO(crbug.com/1111334): Record IndexOutOfBoundsException specifically.
throw new RequestFailureException("Failed to write request to server: ", e, throw new RequestFailureException("Failed to write request to server: ", e,
RequestFailureException.ERROR_CONNECTIVITY); RequestFailureException.ERROR_CONNECTIVITY);
} }
......
...@@ -126,12 +126,6 @@ public abstract class RequestGenerator { ...@@ -126,12 +126,6 @@ public abstract class RequestGenerator {
serializer.endDocument(); serializer.endDocument();
} catch (IOException e) { } catch (IOException e) {
throw new RequestFailureException("Caught an IOException creating the XML: ", e); throw new RequestFailureException("Caught an IOException creating the XML: ", e);
} catch (IllegalArgumentException e) {
throw new RequestFailureException(
"Caught an IllegalArgumentException creating the XML: ", e);
} catch (IllegalStateException e) {
throw new RequestFailureException(
"Caught an IllegalStateException creating the XML: ", e);
} }
return writer.toString(); return writer.toString();
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment