Fixes Util.readAsObject to actually report useful errors
Previously, it would just swallow IOExceptions and return null, which completely obscured the underlying problem.
Review by: spoon, fabbott
git-svn-id: https://google-web-toolkit.googlecode.com/svn/trunk@5403 8db76d5a-ed1c-0410-87a9-c151d255dfc7
diff --git a/dev/core/src/com/google/gwt/dev/PrecompilationFile.java b/dev/core/src/com/google/gwt/dev/PrecompilationFile.java
index 279b67f..231daf2 100644
--- a/dev/core/src/com/google/gwt/dev/PrecompilationFile.java
+++ b/dev/core/src/com/google/gwt/dev/PrecompilationFile.java
@@ -120,22 +120,15 @@
public Precompilation newInstance(TreeLogger logger)
throws UnableToCompleteException {
- Precompilation toReturn;
-
try {
- toReturn = Util.readStreamAsObject(jarFile.getInputStream(zipEntry),
+ return Util.readStreamAsObject(jarFile.getInputStream(zipEntry),
Precompilation.class);
} catch (IOException e) {
- toReturn = null;
+ logger.log(TreeLogger.ERROR, "Unable to instantiate object", e);
+ throw new UnableToCompleteException();
} catch (ClassNotFoundException e) {
logger.log(TreeLogger.ERROR, "Missing class definition", e);
throw new UnableToCompleteException();
}
-
- if (toReturn == null) {
- logger.log(TreeLogger.ERROR, "Unable to instantiate object");
- throw new UnableToCompleteException();
- }
- return toReturn;
}
}
diff --git a/dev/core/src/com/google/gwt/dev/util/DiskCache.java b/dev/core/src/com/google/gwt/dev/util/DiskCache.java
index 5eacbf7..34568ea 100644
--- a/dev/core/src/com/google/gwt/dev/util/DiskCache.java
+++ b/dev/core/src/com/google/gwt/dev/util/DiskCache.java
@@ -107,6 +107,9 @@
} catch (ClassNotFoundException e) {
throw new RuntimeException(
"Unexpected exception deserializing from disk cache", e);
+ } catch (IOException e) {
+ throw new RuntimeException(
+ "Unexpected exception deserializing from disk cache", e);
}
}
diff --git a/dev/core/src/com/google/gwt/dev/util/FileBackedObject.java b/dev/core/src/com/google/gwt/dev/util/FileBackedObject.java
index af62425..c572b29 100644
--- a/dev/core/src/com/google/gwt/dev/util/FileBackedObject.java
+++ b/dev/core/src/com/google/gwt/dev/util/FileBackedObject.java
@@ -71,15 +71,13 @@
*/
public T newInstance(TreeLogger logger) throws UnableToCompleteException {
try {
- T toReturn = Util.readFileAsObject(backingFile, clazz);
- if (toReturn == null) {
- logger.log(TreeLogger.ERROR, "Unable to instantiate object");
- throw new UnableToCompleteException();
- }
- return toReturn;
+ return Util.readFileAsObject(backingFile, clazz);
} catch (ClassNotFoundException e) {
logger.log(TreeLogger.ERROR, "Missing class definition", e);
throw new UnableToCompleteException();
+ } catch (IOException e) {
+ logger.log(TreeLogger.ERROR, "Unable to instantiate object", e);
+ throw new UnableToCompleteException();
}
}
diff --git a/dev/core/src/com/google/gwt/dev/util/Util.java b/dev/core/src/com/google/gwt/dev/util/Util.java
index 63f8603..1ce3b0a 100644
--- a/dev/core/src/com/google/gwt/dev/util/Util.java
+++ b/dev/core/src/com/google/gwt/dev/util/Util.java
@@ -615,13 +615,11 @@
}
public static <T extends Serializable> T readFileAsObject(File file,
- Class<T> type) throws ClassNotFoundException {
+ Class<T> type) throws ClassNotFoundException, IOException {
FileInputStream fileInputStream = null;
try {
fileInputStream = new FileInputStream(file);
return readStreamAsObject(fileInputStream, type);
- } catch (IOException e) {
- return null;
} finally {
Utility.close(fileInputStream);
}
@@ -658,14 +656,12 @@
}
}
- public static <T> T readStreamAsObject(
- InputStream inputStream, Class<T> type) throws ClassNotFoundException {
+ public static <T> T readStreamAsObject(InputStream inputStream, Class<T> type)
+ throws ClassNotFoundException, IOException {
ObjectInputStream objectInputStream = null;
try {
objectInputStream = new ObjectInputStream(inputStream);
return type.cast(objectInputStream.readObject());
- } catch (IOException e) {
- return null;
} finally {
Utility.close(objectInputStream);
}