You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by mt...@apache.org on 2009/06/26 14:46:38 UTC

svn commit: r788679 - in /commons/sandbox/runtime/trunk/src: main/java/org/apache/commons/runtime/Memory.java main/native/shared/memory.c test/org/apache/commons/runtime/TestMemory.java

Author: mturk
Date: Fri Jun 26 12:46:38 2009
New Revision: 788679

URL: http://svn.apache.org/viewvc?rev=788679&view=rev
Log:
ACR_PointerGet already checks for NULL pointer, so no need to duplicate that check in Java

Modified:
    commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/Memory.java
    commons/sandbox/runtime/trunk/src/main/native/shared/memory.c
    commons/sandbox/runtime/trunk/src/test/org/apache/commons/runtime/TestMemory.java

Modified: commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/Memory.java
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/Memory.java?rev=788679&r1=788678&r2=788679&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/Memory.java (original)
+++ commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/Memory.java Fri Jun 26 12:46:38 2009
@@ -161,8 +161,6 @@
         throws IndexOutOfBoundsException, IllegalArgumentException,
                NullPointerException
     {
-        if (src == null || src.IsNull())
-            throw new NullPointerException();
         if (offset < 0L || size < 1L)
             throw new IllegalArgumentException();
 
@@ -193,8 +191,6 @@
         throws IndexOutOfBoundsException, IllegalArgumentException,
                NullPointerException, RuntimeException, OutOfMemoryError
     {
-        if (src == null || src.IsNull())
-            throw new NullPointerException();
         if (offset < 0L || size < 1L)
             throw new IllegalArgumentException();
 
@@ -233,10 +229,6 @@
         throws IndexOutOfBoundsException, IllegalArgumentException,
                NullPointerException, RuntimeException
     {
-        if (src == null || src.IsNull())
-            throw new NullPointerException();
-        if (dst == null || dst.IsNull())
-            throw new NullPointerException();
         if (srcPos < 0L || dstPos < 0L)
             throw new IllegalArgumentException();
         if (length < 1L)
@@ -276,10 +268,6 @@
         throws IndexOutOfBoundsException, IllegalArgumentException,
                NullPointerException, RuntimeException
     {
-        if (src == null || src.IsNull())
-            throw new NullPointerException();
-        if (dst == null || dst.IsNull())
-            throw new NullPointerException();
         if (srcPos < 0L || dstPos < 0L)
             throw new IllegalArgumentException();
         if (length < 1L)
@@ -309,8 +297,6 @@
         throws IndexOutOfBoundsException, IllegalArgumentException,
                NullPointerException, RuntimeException
     {
-        if (ptr == null || ptr.IsNull())
-            throw new NullPointerException();
         if (offset < 0L || length < 1L)
             throw new IllegalArgumentException();
 
@@ -339,8 +325,6 @@
         throws IndexOutOfBoundsException, IllegalArgumentException,
                NullPointerException, RuntimeException
     {
-        if (ptr == null || ptr.IsNull())
-            throw new NullPointerException();
         if (offset < 0L || length < 1L)
             throw new IllegalArgumentException();
 
@@ -369,8 +353,6 @@
         throws IndexOutOfBoundsException, IllegalArgumentException,
                NullPointerException, OutOfMemoryError
     {
-        if (ptr == null || ptr.IsNull())
-            throw new NullPointerException();
         if (offset < 0L || length < 1)
             throw new IllegalArgumentException();
 
@@ -399,8 +381,6 @@
         throws IndexOutOfBoundsException, IllegalArgumentException,
                NullPointerException, OutOfMemoryError
     {
-        if (ptr == null || ptr.IsNull())
-            throw new NullPointerException();
         if (offset < 0L || length < 1)
             throw new IllegalArgumentException();
 
@@ -429,8 +409,6 @@
         throws IndexOutOfBoundsException, IllegalArgumentException,
                NullPointerException, OutOfMemoryError
     {
-        if (ptr == null || ptr.IsNull())
-            throw new NullPointerException();
         if (offset < 0L || length < 1)
             throw new IllegalArgumentException();
 
@@ -459,8 +437,6 @@
         throws IndexOutOfBoundsException, IllegalArgumentException,
                NullPointerException, OutOfMemoryError
     {
-        if (ptr == null || ptr.IsNull())
-            throw new NullPointerException();
         if (offset < 0L || length < 1)
             throw new IllegalArgumentException();
 
@@ -490,8 +466,6 @@
         throws IndexOutOfBoundsException, IllegalArgumentException,
                NullPointerException, OutOfMemoryError
     {
-        if (ptr == null || ptr.IsNull())
-            throw new NullPointerException();
         if (offset < 0L || length < 1)
             throw new IllegalArgumentException();
 
@@ -524,9 +498,7 @@
         throws IndexOutOfBoundsException, IllegalArgumentException,
                NullPointerException
     {
-        if (src == null || src.IsNull())
-            throw new NullPointerException();
-        else if (srcPos < 0 || dstPos < 0 || length == 0)
+        if (srcPos < 0L || dstPos < 0 || length == 0)
             throw new IllegalArgumentException();
         else if ((dstPos + length) > dst.length)
             throw new IndexOutOfBoundsException();
@@ -559,9 +531,7 @@
         throws IndexOutOfBoundsException, IllegalArgumentException,
                NullPointerException
     {
-        if (src == null || src.IsNull())
-            throw new NullPointerException();
-        else if (srcPos < 0 || dstPos < 0 || length == 0)
+        if (srcPos < 0L || dstPos < 0 || length == 0)
             throw new IllegalArgumentException();
         else if ((dstPos + length) > dst.length)
             throw new IndexOutOfBoundsException();
@@ -594,9 +564,7 @@
         throws IndexOutOfBoundsException, IllegalArgumentException,
                NullPointerException
     {
-        if (src == null || src.IsNull())
-            throw new NullPointerException();
-        else if (srcPos < 0 || dstPos < 0 || length == 0)
+        if (srcPos < 0L || dstPos < 0 || length == 0)
             throw new IllegalArgumentException();
         else if ((dstPos + length) > dst.length)
             throw new IndexOutOfBoundsException();
@@ -629,9 +597,7 @@
         throws IndexOutOfBoundsException, IllegalArgumentException,
                NullPointerException
     {
-        if (src == null || src.IsNull())
-            throw new NullPointerException();
-        else if (srcPos < 0 || dstPos < 0 || length == 0)
+        if (srcPos < 0L || dstPos < 0 || length == 0)
             throw new IllegalArgumentException();
         else if ((dstPos + length) > dst.length)
             throw new IndexOutOfBoundsException();
@@ -664,9 +630,7 @@
         throws IndexOutOfBoundsException, IllegalArgumentException,
                NullPointerException
     {
-        if (src == null || src.IsNull())
-            throw new NullPointerException();
-        else if (srcPos < 0 || dstPos < 0 || length == 0)
+        if (srcPos < 0L || dstPos < 0 || length == 0)
             throw new IllegalArgumentException();
         else if ((dstPos + length) > dst.length)
             throw new IndexOutOfBoundsException();
@@ -699,9 +663,7 @@
         throws IndexOutOfBoundsException, IllegalArgumentException,
                NullPointerException
     {
-        if (dst == null || dst.IsNull())
-            throw new NullPointerException();
-        else if (srcPos < 0 || dstPos < 0 || length == 0)
+        if (srcPos < 0 || dstPos < 0L || length == 0)
             throw new IllegalArgumentException();
         else if ((dstPos + length) > src.length)
             throw new IndexOutOfBoundsException();
@@ -734,9 +696,7 @@
         throws IndexOutOfBoundsException, IllegalArgumentException,
                NullPointerException
     {
-        if (dst == null || dst.IsNull())
-            throw new NullPointerException();
-        else if (srcPos < 0 || dstPos < 0 || length == 0)
+        if (srcPos < 0 || dstPos < 0L || length == 0)
             throw new IllegalArgumentException();
         else if ((dstPos + length) > src.length)
             throw new IndexOutOfBoundsException();
@@ -769,9 +729,7 @@
         throws IndexOutOfBoundsException, IllegalArgumentException,
                NullPointerException
     {
-        if (dst == null || dst.IsNull())
-            throw new NullPointerException();
-        else if (srcPos < 0 || dstPos < 0 || length == 0)
+        if (srcPos < 0 || dstPos < 0L || length == 0)
             throw new IllegalArgumentException();
         else if ((dstPos + length) > src.length)
             throw new IndexOutOfBoundsException();
@@ -804,9 +762,7 @@
         throws IndexOutOfBoundsException, IllegalArgumentException,
                NullPointerException
     {
-        if (dst == null || dst.IsNull())
-            throw new NullPointerException();
-        else if (srcPos < 0 || dstPos < 0 || length == 0)
+        if (srcPos < 0 || dstPos < 0L || length == 0)
             throw new IllegalArgumentException();
         else if ((dstPos + length) > src.length)
             throw new IndexOutOfBoundsException();
@@ -839,9 +795,7 @@
         throws IndexOutOfBoundsException, IllegalArgumentException,
                NullPointerException
     {
-        if (dst == null || dst.IsNull())
-            throw new NullPointerException();
-        else if (srcPos < 0 || dstPos < 0 || length == 0)
+        if (srcPos < 0 || dstPos < 0L || length == 0)
             throw new IllegalArgumentException();
         else if ((dstPos + length) > src.length)
             throw new IndexOutOfBoundsException();

Modified: commons/sandbox/runtime/trunk/src/main/native/shared/memory.c
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/shared/memory.c?rev=788679&r1=788678&r2=788679&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/shared/memory.c (original)
+++ commons/sandbox/runtime/trunk/src/main/native/shared/memory.c Fri Jun 26 12:46:38 2009
@@ -326,6 +326,10 @@
 
     UNREFERENCED_O;
 
+    if (!sp) {
+        ACR_ThrowException(_E, THROW_NMARK, ACR_EX_ENULL, 0);
+        return NULL;
+    }
     if ((so + ss) > sl) {
         ACR_ThrowException(_E, THROW_NMARK, ACR_EX_EINDEX, 0);
         return NULL;
@@ -350,6 +354,10 @@
 
     UNREFERENCED_O;
 
+    if (!sp) {
+        ACR_ThrowException(_E, THROW_NMARK, ACR_EX_ENULL, 0);
+        return NULL;
+    }
     if ((so + ss) > sl) {
         ACR_ThrowException(_E, THROW_NMARK, ACR_EX_EINDEX, 0);
         return NULL;
@@ -388,6 +396,10 @@
     char    *d = (char *)ACR_PointerGet(_E, dst, &dl);
     char    *s = (char *)ACR_PointerGet(_E, src, &sl);
 
+    if (!d || !s) {
+        ACR_ThrowException(_E, THROW_NMARK, ACR_EX_ENULL, 0);
+        return;
+    }
     if ((dn + cs) > dl) {
         ACR_ThrowException(_E, THROW_NMARK, ACR_EX_EINDEX, 0);
         return;
@@ -417,6 +429,10 @@
     char    *d = (char *)ACR_PointerGet(_E, dst, &dl);
     char    *s = (char *)ACR_PointerGet(_E, src, &sl);
 
+    if (!d || !s) {
+        ACR_ThrowException(_E, THROW_NMARK, ACR_EX_ENULL, 0);
+        return;
+    }
     if ((dn + cs) > dl) {
         ACR_ThrowException(_E, THROW_NMARK, ACR_EX_EINDEX, 0);
         return;
@@ -499,6 +515,10 @@
     size_t  cs = (size_t)size;
     jbyte   *p = (jbyte *)ACR_PointerGet(_E, ptr, &pl);
 
+    if (!p) {
+        ACR_ThrowException(_E, THROW_NMARK, ACR_EX_ENULL, 0);
+        return NULL;
+    }
     if ((poff + cs) > pl) {
         ACR_ThrowException(_E, THROW_NMARK, ACR_EX_EINDEX, 0);
         return NULL;
@@ -519,6 +539,10 @@
     size_t  cs = (size_t)size;
     jchar   *p = (jchar *)ACR_PointerGet(_E, ptr, &pl);
 
+    if (!p) {
+        ACR_ThrowException(_E, THROW_NMARK, ACR_EX_ENULL, 0);
+        return NULL;
+    }
     if (((poff + cs) * sizeof(jchar)) > pl) {
         ACR_ThrowException(_E, THROW_NMARK, ACR_EX_EINDEX, 0);
         return NULL;
@@ -539,6 +563,10 @@
     size_t  cs = (size_t)size;
     jshort  *p = (jshort *)ACR_PointerGet(_E, ptr, &pl);
 
+    if (!p) {
+        ACR_ThrowException(_E, THROW_NMARK, ACR_EX_ENULL, 0);
+        return NULL;
+    }
     if (((poff + cs) * sizeof(jshort)) > pl) {
         ACR_ThrowException(_E, THROW_NMARK, ACR_EX_EINDEX, 0);
         return NULL;
@@ -559,6 +587,10 @@
     size_t  cs = (size_t)size;
     jint    *p = (jint *)ACR_PointerGet(_E, ptr, &pl);
 
+    if (!p) {
+        ACR_ThrowException(_E, THROW_NMARK, ACR_EX_ENULL, 0);
+        return NULL;
+    }
     if (((poff + cs) * sizeof(jint)) > pl) {
         ACR_ThrowException(_E, THROW_NMARK, ACR_EX_EINDEX, 0);
         return NULL;
@@ -579,6 +611,10 @@
     size_t  cs = (size_t)size;
     jlong   *p = (jlong *)ACR_PointerGet(_E, ptr, &pl);
 
+    if (!p) {
+        ACR_ThrowException(_E, THROW_NMARK, ACR_EX_ENULL, 0);
+        return NULL;
+    }
     if (((poff + cs) * sizeof(jlong)) > pl) {
         ACR_ThrowException(_E, THROW_NMARK, ACR_EX_EINDEX, 0);
         return NULL;
@@ -602,6 +638,10 @@
 
     UNREFERENCED_O;
 
+    if (!p) {
+        ACR_ThrowException(_E, THROW_NMARK, ACR_EX_ENULL, 0);
+        return;
+    }
     if (((po + cs) * sizeof(jbyte)) > pl) {
         ACR_ThrowException(_E, THROW_NMARK, ACR_EX_EINDEX, 0);
         return;
@@ -620,6 +660,10 @@
 
     UNREFERENCED_O;
 
+    if (!p) {
+        ACR_ThrowException(_E, THROW_NMARK, ACR_EX_ENULL, 0);
+        return;
+    }
     if (((po + cs) * sizeof(jchar)) > pl) {
         ACR_ThrowException(_E, THROW_NMARK, ACR_EX_EINDEX, 0);
         return;
@@ -638,6 +682,10 @@
 
     UNREFERENCED_O;
 
+    if (!p) {
+        ACR_ThrowException(_E, THROW_NMARK, ACR_EX_ENULL, 0);
+        return;
+    }
     if (((po + cs) * sizeof(jshort)) > pl) {
         ACR_ThrowException(_E, THROW_NMARK, ACR_EX_EINDEX, 0);
         return;
@@ -656,6 +704,10 @@
 
     UNREFERENCED_O;
 
+    if (!p) {
+        ACR_ThrowException(_E, THROW_NMARK, ACR_EX_ENULL, 0);
+        return;
+    }
     if (((po + cs) * sizeof(jint)) > pl) {
         ACR_ThrowException(_E, THROW_NMARK, ACR_EX_EINDEX, 0);
         return;
@@ -674,6 +726,10 @@
 
     UNREFERENCED_O;
 
+    if (!p) {
+        ACR_ThrowException(_E, THROW_NMARK, ACR_EX_ENULL, 0);
+        return;
+    }
     if (((po + cs) * sizeof(jlong)) > pl) {
         ACR_ThrowException(_E, THROW_NMARK, ACR_EX_EINDEX, 0);
         return;
@@ -692,6 +748,10 @@
 
     UNREFERENCED_O;
 
+    if (!p) {
+        ACR_ThrowException(_E, THROW_NMARK, ACR_EX_ENULL, 0);
+        return;
+    }
     if (((po + cs) * sizeof(jbyte)) > pl) {
         ACR_ThrowException(_E, THROW_NMARK, ACR_EX_EINDEX, 0);
         return;
@@ -710,6 +770,10 @@
 
     UNREFERENCED_O;
 
+    if (!p) {
+        ACR_ThrowException(_E, THROW_NMARK, ACR_EX_ENULL, 0);
+        return;
+    }
     if (((po + cs) * sizeof(jchar)) > pl) {
         ACR_ThrowException(_E, THROW_NMARK, ACR_EX_EINDEX, 0);
         return;
@@ -728,6 +792,10 @@
 
     UNREFERENCED_O;
 
+    if (!p) {
+        ACR_ThrowException(_E, THROW_NMARK, ACR_EX_ENULL, 0);
+        return;
+    }
     if (((po + cs) * sizeof(jshort)) > pl) {
         ACR_ThrowException(_E, THROW_NMARK, ACR_EX_EINDEX, 0);
         return;
@@ -746,6 +814,10 @@
 
     UNREFERENCED_O;
 
+    if (!p) {
+        ACR_ThrowException(_E, THROW_NMARK, ACR_EX_ENULL, 0);
+        return;
+    }
     if (((po + cs) * sizeof(jint)) > pl) {
         ACR_ThrowException(_E, THROW_NMARK, ACR_EX_EINDEX, 0);
         return;
@@ -764,6 +836,10 @@
 
     UNREFERENCED_O;
 
+    if (!p) {
+        ACR_ThrowException(_E, THROW_NMARK, ACR_EX_ENULL, 0);
+        return;
+    }
     if (((po + cs) * sizeof(jlong)) > pl) {
         ACR_ThrowException(_E, THROW_NMARK, ACR_EX_EINDEX, 0);
         return;

Modified: commons/sandbox/runtime/trunk/src/test/org/apache/commons/runtime/TestMemory.java
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/test/org/apache/commons/runtime/TestMemory.java?rev=788679&r1=788678&r2=788679&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/test/org/apache/commons/runtime/TestMemory.java (original)
+++ commons/sandbox/runtime/trunk/src/test/org/apache/commons/runtime/TestMemory.java Fri Jun 26 12:46:38 2009
@@ -138,7 +138,7 @@
             // Succedded.
         }
         try {
-            Pointer t = Memory.slice(null, 0, 0);
+            Pointer t = Memory.slice(null, 1, 1);
             fail("Missing NullPointerException");
         } catch (NullPointerException no) {
             // Succedded.