commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mt...@apache.org
Subject svn commit: r1098530 - in /commons/sandbox/runtime/trunk/src/main: java/org/apache/commons/runtime/ java/org/apache/commons/runtime/net/ native/os/win32/ native/shared/ test/org/apache/commons/runtime/
Date Mon, 02 May 2011 11:25:56 GMT
Author: mturk
Date: Mon May  2 11:25:55 2011
New Revision: 1098530

URL: http://svn.apache.org/viewvc?rev=1098530&view=rev
Log:
Use IllegalArgumentException for EINVAL

Modified:
    commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/Unsafe.java
    commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/net/DatagramSocketInstance.java
    commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/net/LocalSocketAddress.java
    commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/net/SocketInstance.java
    commons/sandbox/runtime/trunk/src/main/native/os/win32/wpipe.c
    commons/sandbox/runtime/trunk/src/main/native/shared/string.c
    commons/sandbox/runtime/trunk/src/main/test/org/apache/commons/runtime/TestString.java

Modified: commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/Unsafe.java
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/Unsafe.java?rev=1098530&r1=1098529&r2=1098530&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/Unsafe.java (original)
+++ commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/Unsafe.java Mon
May  2 11:25:55 2011
@@ -103,11 +103,20 @@ public final class Unsafe
         return getOffset1(field);
     }
 
+    private static native char[] getchr0(String str);
     /**
      *  Get the {@code str} private character array.
      */
-    public static native final char[] getStringChars(String str);
+    public static char[] getChars(String str)
+        throws IllegalArgumentException
+    {
+        if (str == null)
+            throw new IllegalArgumentException("string can't be null");
+        if (str.isEmpty())
+            return new char[0];
+        else
+            return getchr0(str);
+    }
 
 
-    
 }

Modified: commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/net/DatagramSocketInstance.java
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/net/DatagramSocketInstance.java?rev=1098530&r1=1098529&r2=1098530&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/net/DatagramSocketInstance.java
(original)
+++ commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/net/DatagramSocketInstance.java
Mon May  2 11:25:55 2011
@@ -42,26 +42,26 @@ public final class DatagramSocketInstanc
     private static native int            nb0(DatagramSocket s, boolean on);
 
     public static FileDescriptor getFileDescriptor(DatagramSocket s)
-        throws NullPointerException
+        throws IllegalArgumentException
     {
         if (s == null)
-            throw new NullPointerException();
+            throw new IllegalArgumentException();
         return fd0(s);
     }
 
     public static int getNativeDescriptor(DatagramSocket s)
-        throws NullPointerException
+        throws IllegalArgumentException
     {
         if (s == null)
-            throw new NullPointerException();
+            throw new IllegalArgumentException();
         return nd0(s);
     }
 
     public static void configureBlocking(DatagramSocket s, boolean on)
-        throws NullPointerException, IOException
+        throws IllegalArgumentException, IOException
     {
         if (s == null)
-            throw new NullPointerException();
+            throw new IllegalArgumentException();
         int rc = nb0(s, !on);
         if (rc != 0)
             throw new IOException(Status.describe(rc));

Modified: commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/net/LocalSocketAddress.java
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/net/LocalSocketAddress.java?rev=1098530&r1=1098529&r2=1098530&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/net/LocalSocketAddress.java
(original)
+++ commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/net/LocalSocketAddress.java
Mon May  2 11:25:55 2011
@@ -43,7 +43,7 @@ public final class LocalSocketAddress ex
     public LocalSocketAddress(String name)
     {
         if (name == null)
-            throw new NullPointerException();
+            throw new IllegalArgumentException("name can't be null");
         StringBuilder pn = new StringBuilder(prefix);
         // Normalize the pipe or unix socket name
         //
@@ -59,7 +59,7 @@ public final class LocalSocketAddress ex
     public LocalSocketAddress(File path)
     {
         if (path == null)
-            throw new NullPointerException();
+            throw new IllegalArgumentException("path can't be null");
         // path is presumed to be correctly
         // formatted.
         this.path = path.getPath();

Modified: commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/net/SocketInstance.java
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/net/SocketInstance.java?rev=1098530&r1=1098529&r2=1098530&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/net/SocketInstance.java
(original)
+++ commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/net/SocketInstance.java
Mon May  2 11:25:55 2011
@@ -46,52 +46,52 @@ public final class SocketInstance
     private static native int            nb1(ServerSocket s, boolean on);
 
     public static FileDescriptor getFileDescriptor(Socket s)
-        throws NullPointerException
+        throws IllegalArgumentException
     {
         if (s == null)
-            throw new NullPointerException();
+            throw new IllegalArgumentException();
         return fd0(s);
     }
 
     public static FileDescriptor getFileDescriptor(ServerSocket s)
-        throws NullPointerException
+        throws IllegalArgumentException
     {
         if (s == null)
-            throw new NullPointerException();
+            throw new IllegalArgumentException();
         return fd1(s);
     }
 
     public static int getNativeDescriptor(Socket s)
-        throws NullPointerException
+        throws IllegalArgumentException
     {
         if (s == null)
-            throw new NullPointerException();
+            throw new IllegalArgumentException();
         return nd0(s);
     }
 
     public static int getNativeDescriptor(ServerSocket s)
-        throws NullPointerException
+        throws IllegalArgumentException
     {
         if (s == null)
-            throw new NullPointerException();
+            throw new IllegalArgumentException();
         return nd1(s);
     }
 
     public static void configureBlocking(Socket s, boolean on)
-        throws NullPointerException, IOException
+        throws IllegalArgumentException, IOException
     {
         if (s == null)
-            throw new NullPointerException();
+            throw new IllegalArgumentException();
         int rc = nb0(s, !on);
         if (rc != 0)
             throw new IOException(Status.describe(rc));
     }
 
     public static void configureBlocking(ServerSocket s, boolean on)
-        throws NullPointerException, IOException
+        throws IllegalArgumentException, IOException
     {
         if (s == null)
-            throw new NullPointerException();
+            throw new IllegalArgumentException();
         int rc = nb1(s, !on);
         if (rc != 0)
             throw new IOException(Status.describe(rc));

Modified: commons/sandbox/runtime/trunk/src/main/native/os/win32/wpipe.c
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/os/win32/wpipe.c?rev=1098530&r1=1098529&r2=1098530&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/os/win32/wpipe.c (original)
+++ commons/sandbox/runtime/trunk/src/main/native/os/win32/wpipe.c Mon May  2 11:25:55 2011
@@ -25,7 +25,7 @@
 
 ACR_NET_EXPORT(jstring, LocalSocketAddress, prefix0)(JNI_STDARGS)
 {
-    return WSTR_TO_JSTRING(L"\\\\.\\PIPE\\");
+    return WSTR_TO_JSTRING(L"\\\\.\\pipe\\");
 }
 
 ACR_NET_EXPORT(jlong, LocalSocketAddress, addr0)(JNI_STDARGS, jstring name)

Modified: commons/sandbox/runtime/trunk/src/main/native/shared/string.c
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/shared/string.c?rev=1098530&r1=1098529&r2=1098530&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/shared/string.c (original)
+++ commons/sandbox/runtime/trunk/src/main/native/shared/string.c Mon May  2 11:25:55 2011
@@ -1231,17 +1231,15 @@ AcrGetJavaStringArrayW(JNI_STDENV, jobje
     return ret;
 }
 
-ACR_JNI_EXPORT(jcharArray, Unsafe, getStringChars)(JNI_STDARGS, jstring str)
+ACR_JNI_EXPORT(jcharArray, Unsafe, getchr0)(JNI_STDARGS, jstring str)
 {
-    if (IS_JOBJECT_VALID(str)) {
-        if (J4FLD_OFF(0000) != INVALID_FIELD_OFFSET) {
-            char *oa = *(char **)str;
-            if (oa != 0)
-                return (jobject)(oa + J4FLD_PTR(0000));
-        }
-        else if (CLAZZ_LOADED) {
-            return GET_IFIELD_O(0000, str);
-        }
+    if (J4FLD_OFF(0000) != INVALID_FIELD_OFFSET) {
+        char *oa = *(char **)str;
+        if (oa != 0)
+            return (jobject)(oa + J4FLD_PTR(0000));
+    }
+    else if (CLAZZ_LOADED) {
+        return GET_IFIELD_O(0000, str);
     }
     return 0;
 }

Modified: commons/sandbox/runtime/trunk/src/main/test/org/apache/commons/runtime/TestString.java
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/test/org/apache/commons/runtime/TestString.java?rev=1098530&r1=1098529&r2=1098530&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/test/org/apache/commons/runtime/TestString.java
(original)
+++ commons/sandbox/runtime/trunk/src/main/test/org/apache/commons/runtime/TestString.java
Mon May  2 11:25:55 2011
@@ -61,10 +61,17 @@ public class TestString extends Assert
     public void stringPrivate()
         throws Exception
     {
-        final char[] ca = Unsafe.getStringChars("string");
-        assertEquals((int)ca[0], 's');
-        assertEquals((int)ca[1], 't');
-        assertEquals((int)ca[2], 'r');
+        String s = new String("Quick brown fox jumps over the lazy dog");
+        char[] ca = Unsafe.getChars(s);
+        assertEquals(ca.length, s.length());
+        assertEquals((int)ca[12], 'f');
+        assertEquals((int)ca[13], 'o');
+        assertEquals((int)ca[14], 'x');
+        // Modify String private
+        assertEquals(s.charAt(0), 'Q');
+        ca[0] = 'q';
+        assertEquals(s.charAt(0), 'q');
+        
     }
 
 



Mime
View raw message