Author: peter_firmstone
Date: Thu Feb 28 08:17:50 2013
New Revision: 1451135

URL: http://svn.apache.org/r1451135
Log:
RIVER-416

Added fail safe mechanism in case of future Level serial form breakage based on 
suggestion made by Robert Gibson that only uses public API.

Modified:
    river/jtsk/skunk/qa_refactor/trunk/src/com/sun/jini/logging/Levels.java

Modified: 
river/jtsk/skunk/qa_refactor/trunk/src/com/sun/jini/logging/Levels.java
URL: 
http://svn.apache.org/viewvc/river/jtsk/skunk/qa_refactor/trunk/src/com/sun/jini/logging/Levels.java?rev=1451135&r1=1451134&r2=1451135&view=diff
==============================================================================
--- river/jtsk/skunk/qa_refactor/trunk/src/com/sun/jini/logging/Levels.java 
(original)
+++ river/jtsk/skunk/qa_refactor/trunk/src/com/sun/jini/logging/Levels.java Thu 
Feb 28 08:17:50 2013
@@ -24,6 +24,7 @@ import java.io.IOException;
 import java.io.ObjectInputStream;
 import java.io.ObjectOutputStream;
 import java.io.ObjectStreamClass;
+import java.io.ObjectStreamException;
 import java.io.OutputStream;
 import java.io.Serializable;
 import java.util.logging.Level;
@@ -115,7 +116,16 @@ public class Levels {
     * Creates an instance of the Level class. This method works around the
     * fact that there is no public constructor for the Level class by
     * constructing the serialized form for an instance with the specified
-    * field values and deserializing it.
+    * field values and deserializing it. 
+    * 
+    * If deserialization fails, it creates a Level with a numerical name that 
+    * can be de-serialised by a remote client that doesn't have
+    * com.sun.jini.logging.Levels bytecode.
+    * 
+    * Local logging code still enjoys the benefit of a meaningful name even
+    * when deserialization fails.
+    * 
+    * See River-416 for details, the serial form of Levels was broken in Java 
1.6.0_41.
     */
     private static Level createLevel(String name, int value, String 
resourceBundleName) {
         try {
@@ -126,9 +136,17 @@ public class Levels {
             ObjectInputStream in = new ObjectInputStream(new 
ByteArrayInputStream(bytes.toByteArray()));
             Level result = (Level) in.readObject();
             in.close();
+            // If this suceeds, Level.readResolve has added the new Level to 
its internal List.
             return result;
         } catch (Exception e) {
-            throw new RuntimeException("Unexpected exception", e);
+            final Level withoutName = 
Level.parse(Integer.valueOf(value).toString());
+            Level l =  new Level(name, value, resourceBundleName) {
+                Object writeReplace() throws ObjectStreamException {
+                    return withoutName;
+                }
+            };
+            return l;
         }
+        
     }
-}
\ No newline at end of file
+}


Reply via email to