Erik Hetzner avatar Erik Hetzner committed bcf0636

catch errors when calling toString

Comments (0)

Files changed (1)

src/main/java/org/cdlib/mrt/queue/Item.java

 package org.cdlib.mrt.queue;
 
-import java.io.*;
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.DataInputStream;
+import java.io.DataOutputStream;
+import java.io.IOException;
+import java.io.ObjectInputStream;
+
 import java.util.Date;
 import java.util.Properties;
 
     }
     
     public String toString () {
-	ByteArrayInputStream bis = null;
-	ObjectInputStream ois = null;
-        try {    
-            String statusStr;
-	    Properties p = new Properties();
-            if (this.status == Item.PENDING) {
-                statusStr = "pending";
-            } else if (this.status == Item.CONSUMED) {
-                statusStr = "consumed";
-            } else if (this.status == Item.DELETED) {
-                statusStr = "deleted";
-            } else if (this.status == Item.COMPLETED) {
-                statusStr = "completed";
-            } else {
-                statusStr = "error in status retrieval";
-            }
-            String retval;
-
-	    bis = new ByteArrayInputStream(this.data);
-	    ois = new ObjectInputStream(bis);
+        String statusStr;
+        if (this.status == Item.PENDING) {
+            statusStr = "pending";
+        } else if (this.status == Item.CONSUMED) {
+            statusStr = "consumed";
+        } else if (this.status == Item.DELETED) {
+            statusStr = "deleted";
+        } else if (this.status == Item.COMPLETED) {
+            statusStr = "completed";
+        } else {
+            statusStr = "error in status retrieval";
+        }
+        
+        ByteArrayInputStream bis = null;
+        ObjectInputStream ois = null;
+        Properties p = new Properties();
+        try {
+            bis = new ByteArrayInputStream(this.data);
+            ois = new ObjectInputStream(bis);
             p = (Properties) ois.readObject();
-    
-            if (this.timestamp != null && this.timestamp.getTime() != 0L) {
-                return String.format("[%s: %s] %s", statusStr, 
+        } catch (IOException ex) {
+            /* ... */
+        } catch (ClassNotFoundException ex) {
+            /* ... */
+        } finally {
+            try {
+                ois.close();
+            } catch (Exception e) {}
+            try {
+                bis.close();
+            } catch (Exception e) {}
+        }
+        if (this.timestamp != null && this.timestamp.getTime() != 0L) {
+            return String.format("[%s: %s] %s", 
+                                 statusStr, 
                                  this.timestamp.toString(),
                                  p.toString());
-            } else {
-                return String.format("[%s] %s", statusStr, 
+        } else {
+            return String.format("[%s] %s", 
+                                 statusStr,
                                  p.toString());
-            }
-        } catch (IOException ioe) {
-            ioe.printStackTrace(System.err);
-            return null;
-        } catch (Exception ex) {
-            ex.printStackTrace(System.err);
-            return null;
-        } finally {
-	    try {
-	        ois.close();
-	        bis.close();
-	    } catch (Exception e) {
-	    }
-	}
+        }
     }
 
     public static Item fromBytes(byte[] bytes) {
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.