Author: [email protected]
Date: Fri May 15 16:23:01 2009
New Revision: 5403

Modified:
    trunk/dev/core/src/com/google/gwt/dev/PrecompilationFile.java
    trunk/dev/core/src/com/google/gwt/dev/util/DiskCache.java
    trunk/dev/core/src/com/google/gwt/dev/util/FileBackedObject.java
    trunk/dev/core/src/com/google/gwt/dev/util/Util.java

Log:
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

Modified: trunk/dev/core/src/com/google/gwt/dev/PrecompilationFile.java
==============================================================================
--- trunk/dev/core/src/com/google/gwt/dev/PrecompilationFile.java       
(original)
+++ trunk/dev/core/src/com/google/gwt/dev/PrecompilationFile.java       Fri May 
 
15 16:23:01 2009
@@ -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;
    }
  }

Modified: trunk/dev/core/src/com/google/gwt/dev/util/DiskCache.java
==============================================================================
--- trunk/dev/core/src/com/google/gwt/dev/util/DiskCache.java   (original)
+++ trunk/dev/core/src/com/google/gwt/dev/util/DiskCache.java   Fri May 15  
16:23:01 2009
@@ -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);
      }
    }


Modified: trunk/dev/core/src/com/google/gwt/dev/util/FileBackedObject.java
==============================================================================
--- trunk/dev/core/src/com/google/gwt/dev/util/FileBackedObject.java     
(original)
+++ trunk/dev/core/src/com/google/gwt/dev/util/FileBackedObject.java    Fri  
May 15 16:23:01 2009
@@ -71,14 +71,12 @@
     */
    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();
      }
    }

Modified: trunk/dev/core/src/com/google/gwt/dev/util/Util.java
==============================================================================
--- trunk/dev/core/src/com/google/gwt/dev/util/Util.java        (original)
+++ trunk/dev/core/src/com/google/gwt/dev/util/Util.java        Fri May 15  
16:23:01 2009
@@ -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);
      }

--~--~---------~--~----~------------~-------~--~----~
http://groups.google.com/group/Google-Web-Toolkit-Contributors
-~----------~----~----~----~------~----~------~--~---

Reply via email to