harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From apetre...@apache.org
Subject svn commit: r484623 - in /harmony/enhanced/drlvm/trunk/vm: tests/kernel/java/lang/RuntimeTest.java vmcore/src/kernel_classes/javasrc/java/lang/Runtime.java
Date Fri, 08 Dec 2006 14:59:44 GMT
Author: apetrenko
Date: Fri Dec  8 06:59:43 2006
New Revision: 484623

URL: http://svn.apache.org/viewvc?view=rev&rev=484623
Log:
Patch for HARMONY-690 "[classlib][lang]Compatibility: Harmony Runtime.removeShutdownHook(null)
does not throw unspecified NPE while RI does."

Modified:
    harmony/enhanced/drlvm/trunk/vm/tests/kernel/java/lang/RuntimeTest.java
    harmony/enhanced/drlvm/trunk/vm/vmcore/src/kernel_classes/javasrc/java/lang/Runtime.java

Modified: harmony/enhanced/drlvm/trunk/vm/tests/kernel/java/lang/RuntimeTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/drlvm/trunk/vm/tests/kernel/java/lang/RuntimeTest.java?view=diff&rev=484623&r1=484622&r2=484623
==============================================================================
--- harmony/enhanced/drlvm/trunk/vm/tests/kernel/java/lang/RuntimeTest.java (original)
+++ harmony/enhanced/drlvm/trunk/vm/tests/kernel/java/lang/RuntimeTest.java Fri Dec  8 06:59:43
2006
@@ -333,7 +333,7 @@
         for (int ind2 = 0; ind2 < 1000; ind2++) {
             //assertSame("Runtime.maxMemory() must always return the same value!",
             //        r2, Runtime.getRuntime().maxMemory());
-			assertTrue( "FAILED: test_maxMemory: Runtime.maxMemory method should return same value
each time!", r2==Runtime.getRuntime().maxMemory());
+            assertTrue( "FAILED: test_maxMemory: Runtime.maxMemory method should return same
value each time!", r2==Runtime.getRuntime().maxMemory());
         }
     }
 
@@ -415,5 +415,33 @@
         //System.out.println("test_exit");
         //Runtime.getRuntime().exit(777);
         //fail("what's wrong  ;) ?");
+    }
+
+    /**
+     * Regression test for HARMONY-690 
+     */
+    public void test_addShutdownHook() {
+        // Test for method long java.lang.Runtime.addShutdownHook()
+        boolean exception = false; 
+        try {
+            Runtime.getRuntime().addShutdownHook(null);
+        } catch (NullPointerException npe) {
+            exception = true;
+        }
+        assertTrue("NullPointerException expected!", exception);
+    }
+
+    /**
+     * Regression test for HARMONY-690 
+     */
+    public void test_removeShutdownHook() {
+        // Test for method long java.lang.Runtime.removeShutdownHook()
+        boolean exception = false; 
+        try {
+            Runtime.getRuntime().removeShutdownHook(null);
+        } catch (NullPointerException npe) {
+            exception = true;
+        }
+        assertTrue("NullPointerException expected!", exception);
     }
 }

Modified: harmony/enhanced/drlvm/trunk/vm/vmcore/src/kernel_classes/javasrc/java/lang/Runtime.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/drlvm/trunk/vm/vmcore/src/kernel_classes/javasrc/java/lang/Runtime.java?view=diff&rev=484623&r1=484622&r2=484623
==============================================================================
--- harmony/enhanced/drlvm/trunk/vm/vmcore/src/kernel_classes/javasrc/java/lang/Runtime.java
(original)
+++ harmony/enhanced/drlvm/trunk/vm/vmcore/src/kernel_classes/javasrc/java/lang/Runtime.java
Fri Dec  8 06:59:43 2006
@@ -467,7 +467,11 @@
         if (sm != null) {
             sm.checkPermission(RuntimePermissionCollection.SHUTDOWN_HOOKS_PERMISSION);
         }
-        if (hook == null || hook.getState() != Thread.State.NEW) {
+        // Check hook for null
+        if (hook == null)
+            throw new NullPointerException("null is not allowed here");
+                
+        if (hook.getState() != Thread.State.NEW) {
             throw new IllegalArgumentException();
         }
         if (VMState > 0) {
@@ -489,11 +493,15 @@
         if (sm != null) {
             sm.checkPermission(RuntimePermissionCollection.SHUTDOWN_HOOKS_PERMISSION);
         }
+        // Check hook for null
+        if (hook == null)
+            throw new NullPointerException("null is not allowed here");
+                
         if (VMState > 0) {
             throw new IllegalStateException();
         }
         synchronized (hooksList) {
-            return hook == null ? false : hooksList.remove((Object) hook);
+            return hooksList.remove((Object) hook);
         }
     }
 



Mime
View raw message