Index: src/main/java/java/io/ObjectInputStream.java =================================================================== --- src/main/java/java/io/ObjectInputStream.java (revision 491036) +++ src/main/java/java/io/ObjectInputStream.java (working copy) @@ -2292,11 +2292,12 @@ */ 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) { + // 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) { + if (object != 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. @@ -2326,10 +2327,10 @@ validations[i] = desc; } } else { - throw new NotActiveException(); + throw new InvalidObjectException(Msg.getString("K00d9")); //$NON-NLS-1$ } } else { - throw new InvalidObjectException(Msg.getString("K00d9")); //$NON-NLS-1$ + throw new NotActiveException(); } } Index: src/test/java/tests/api/java/io/ObjectInputStreamTest.java =================================================================== --- src/test/java/tests/api/java/io/ObjectInputStreamTest.java (revision 491034) +++ src/test/java/tests/api/java/io/ObjectInputStreamTest.java (working copy) @@ -756,8 +756,23 @@ 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 * is called before a test is executed.