harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From telli...@apache.org
Subject svn commit: r491091 - in /harmony/enhanced/classlib/trunk/modules/luni/src: main/java/java/io/ObjectInputStream.java test/java/tests/api/java/io/ObjectInputStreamTest.java
Date Fri, 29 Dec 2006 20:24:56 GMT
Author: tellison
Date: Fri Dec 29 12:24:55 2006
New Revision: 491091

URL: http://svn.apache.org/viewvc?view=rev&rev=491091
Log:
Fix for HARMONY-2402 ([classlib][luni] java.io.ObjectInputStream.registerValidation throws
InvalidObjectException while RI throws NotActiveException)

Modified:
    harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/io/ObjectInputStream.java
    harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/io/ObjectInputStreamTest.java

Modified: harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/io/ObjectInputStream.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/io/ObjectInputStream.java?view=diff&rev=491091&r1=491090&r2=491091
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/io/ObjectInputStream.java
(original)
+++ harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/io/ObjectInputStream.java
Fri Dec 29 12:24:55 2006
@@ -2292,44 +2292,42 @@
      */
     public synchronized void registerValidation(ObjectInputValidation object,
             int priority) throws NotActiveException, InvalidObjectException {
-        if (object != null) {
-            // Validation can only be registered when inside readObject calls
-            Object instanceBeingRead = this.currentObject;
-            // We can't be called from just anywhere. There are rules.
-            if (instanceBeingRead != null) {
-                // From now on it is just insertion in a SortedCollection. Since
-                // the Java class libraries don't provide that, we have to
-                // implement it from scratch here.
-                InputValidationDesc desc = new InputValidationDesc();
-                desc.validator = object;
-                desc.priority = priority;
-                // No need for this, validateObject does not take a parameter
-                // desc.toValidate = instanceBeingRead;
-                if (validations == null) {
-                    validations = new InputValidationDesc[1];
-                    validations[0] = desc;
-                } else {
-                    int i = 0;
-                    for (; i < validations.length; i++) {
-                        InputValidationDesc validation = validations[i];
-                        // Sorted, higher priority first.
-                        if (priority >= validation.priority) {
-                            break; // Found the index where to insert
-                        }
-                    }
-                    InputValidationDesc[] oldValidations = validations;
-                    int currentSize = oldValidations.length;
-                    validations = new InputValidationDesc[currentSize + 1];
-                    System.arraycopy(oldValidations, 0, validations, 0, i);
-                    System.arraycopy(oldValidations, i, validations, i + 1,
-                            currentSize - i);
-                    validations[i] = desc;
+        // Validation can only be registered when inside readObject calls
+        Object instanceBeingRead = this.currentObject;
+
+        // We can't be called from just anywhere. There are rules.
+        if (instanceBeingRead == null) {
+            throw new NotActiveException();
+        }
+        if (object == null) {
+            throw new InvalidObjectException(Msg.getString("K00d9")); //$NON-NLS-1$
+        }
+        // From now on it is just insertion in a SortedCollection. Since
+        // the Java class libraries don't provide that, we have to
+        // implement it from scratch here.
+        InputValidationDesc desc = new InputValidationDesc();
+        desc.validator = object;
+        desc.priority = priority;
+        // No need for this, validateObject does not take a parameter
+        // desc.toValidate = instanceBeingRead;
+        if (validations == null) {
+            validations = new InputValidationDesc[1];
+            validations[0] = desc;
+        } else {
+            int i = 0;
+            for (; i < validations.length; i++) {
+                InputValidationDesc validation = validations[i];
+                // Sorted, higher priority first.
+                if (priority >= validation.priority) {
+                    break; // Found the index where to insert
                 }
-            } else {
-                throw new NotActiveException();
             }
-        } else {
-            throw new InvalidObjectException(Msg.getString("K00d9")); //$NON-NLS-1$
+            InputValidationDesc[] oldValidations = validations;
+            int currentSize = oldValidations.length;
+            validations = new InputValidationDesc[currentSize + 1];
+            System.arraycopy(oldValidations, 0, validations, 0, i);
+            System.arraycopy(oldValidations, i, validations, i + 1, currentSize - i);
+            validations[i] = desc;
         }
     }
 

Modified: harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/io/ObjectInputStreamTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/io/ObjectInputStreamTest.java?view=diff&rev=491091&r1=491090&r2=491091
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/io/ObjectInputStreamTest.java
(original)
+++ harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/io/ObjectInputStreamTest.java
Fri Dec 29 12:24:55 2006
@@ -756,7 +756,22 @@
 		ois.close();
 		assertEquals(desc.getClass(), obj.getClass());
 	}
-   
+
+    // Regression Test for Harmony-2402
+    public void test_registerValidation() throws Exception {
+        ByteArrayOutputStream baos = new ByteArrayOutputStream();
+        new ObjectOutputStream(baos);
+        ObjectInputStream ois = new ObjectInputStream(
+                new ByteArrayInputStream(baos.toByteArray()));
+
+        try {
+            ois.registerValidation(null, 256);
+            fail("NotActiveException should be thrown");
+        } catch (NotActiveException nae) {
+            // expected
+        }
+    }
+
 
     /**
      * Sets up the fixture, for example, open a network connection. This method



Mime
View raw message