summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJames Cook <jamescook@google.com>2015-06-12 17:48:35 +0000
committerAndroid (Google) Code Review <android-gerrit@google.com>2015-06-12 17:48:36 +0000
commit20cfe15c82b8bb755f4d05a27b6f42affe73e3e1 (patch)
tree9e6e9b5bd1c73f0746689713c4ddc67ab4e8a771
parent3641c822d6263ea90969ad037153f59efbac04bf (diff)
parent1aeb03925d39b56f92afad487488c6a832f03972 (diff)
downloadandroid_external_doclava-20cfe15c82b8bb755f4d05a27b6f42affe73e3e1.tar.gz
android_external_doclava-20cfe15c82b8bb755f4d05a27b6f42affe73e3e1.tar.bz2
android_external_doclava-20cfe15c82b8bb755f4d05a27b6f42affe73e3e1.zip
Merge "Fix NPE on checkapi with malformed text input" into mnc-dev
-rw-r--r--src/com/google/doclava/apicheck/ApiCheck.java25
1 files changed, 10 insertions, 15 deletions
diff --git a/src/com/google/doclava/apicheck/ApiCheck.java b/src/com/google/doclava/apicheck/ApiCheck.java
index 47a8b5e..d9e8a01 100644
--- a/src/com/google/doclava/apicheck/ApiCheck.java
+++ b/src/com/google/doclava/apicheck/ApiCheck.java
@@ -157,6 +157,7 @@ public class ApiCheck {
public static ApiInfo parseApi(String filename) throws ApiParseException {
InputStream stream = null;
Throwable textParsingError = null;
+ Throwable xmlParsingError = null;
// try it as our format
try {
stream = new FileInputStream(filename);
@@ -165,11 +166,8 @@ public class ApiCheck {
}
try {
return ApiFile.parseApi(filename, stream);
- } catch (ApiParseException ignored) {
- textParsingError = ignored;
- if (false) {
- return null;
- }
+ } catch (ApiParseException exception) {
+ textParsingError = exception;
} finally {
try {
stream.close();
@@ -183,21 +181,18 @@ public class ApiCheck {
}
try {
return XmlApiFile.parseApi(stream);
- } catch (ApiParseException ignored) {
- System.out.println("Couldn't parse API file \"" + filename + "\"");
- System.out.println(" ...as text: " + textParsingError.toString());
- System.out.println(" ...as XML: " + ignored.toString());
- if (false) {
- if (textParsingError != null) textParsingError.printStackTrace();
- ignored.printStackTrace();
- return null;
- }
+ } catch (ApiParseException exception) {
+ xmlParsingError = exception;
} finally {
try {
stream.close();
} catch (IOException ignored) {}
}
- return null;
+ // The file has failed to parse both as XML and as text. Build the string in this order as
+ // the message is easier to read with that error at the end.
+ throw new ApiParseException(filename +
+ " failed to parse as xml: \"" + xmlParsingError.getMessage() +
+ "\" and as text: \"" + textParsingError.getMessage() + "\"");
}
public ApiInfo parseApi(URL url) throws ApiParseException {