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/04/17 15:02:56 UTC

svn commit: r765975 - in /commons/sandbox/runtime/trunk/src/main: java/org/apache/commons/runtime/ native/include/ native/shared/

Author: mturk
Date: Fri Apr 17 13:02:56 2009
New Revision: 765975

URL: http://svn.apache.org/viewvc?rev=765975&view=rev
Log:
Throw InstatntiationException if operation made on unitialized library

Modified:
    commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/Descriptor.java
    commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/Pointer.java
    commons/sandbox/runtime/trunk/src/main/native/include/acr_error.h
    commons/sandbox/runtime/trunk/src/main/native/shared/descriptor.c
    commons/sandbox/runtime/trunk/src/main/native/shared/error.c
    commons/sandbox/runtime/trunk/src/main/native/shared/pointer.c

Modified: commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/Descriptor.java
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/Descriptor.java?rev=765975&r1=765974&r2=765975&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/Descriptor.java (original)
+++ commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/Descriptor.java Fri Apr 17 13:02:56 2009
@@ -44,10 +44,10 @@
     }
 
     private native void close0()
-        throws IOException;
+        throws IOException, InstantiationException;
 
     private native void sync0()
-        throws SyncFailedException, IOException;
+        throws SyncFailedException, IOException, InstantiationException;
 
     /**
      * Called by the garbage collector when the object is destroyed.
@@ -58,7 +58,12 @@
     protected final void finalize()
         throws Throwable
     {
-        close0();
+        try {
+            close0();
+        } catch (InstantiationException ex) {
+            // Class is alreay uninitialized.
+            // Ignore.
+        }
     }
 
     /**
@@ -70,20 +75,27 @@
      * </p>
      * @see java.io.Closeable#close()
      * @throws IOException if an I/O error occurs.
+     * @thrown InstantiationException if native class loader was not initialized.
      */
     public final void close()
         throws IOException
     {
-        close0();
+        try {
+            close0();
+        } catch (InstantiationException ex) {
+            // Class is alreay uninitialized.
+            // TODO: We could rethrow IOException here.
+        }
     }
 
     /**
      * Force the underlying object to synchonize any buffered data.
      * @throws SyncFailedException when the object cannot be flushed.
      * @throws IOException if an I/O error occurs.
+     * @thrown InstantiationException if native class loader was not initialized.
      */
     public final void sync()
-        throws SyncFailedException, IOException
+        throws SyncFailedException, IOException, InstantiationException
     {
         sync0();
     }

Modified: commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/Pointer.java
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/Pointer.java?rev=765975&r1=765974&r2=765975&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/Pointer.java (original)
+++ commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/Pointer.java Fri Apr 17 13:02:56 2009
@@ -77,8 +77,13 @@
      */
     protected final void finalize()
         throws Throwable
-    {
-        cleanup0();
+    {        
+        try {
+            cleanup0();
+        } catch (InstantiationException ex) {
+            // Class is alreay uninitialized.
+            // Ignore.
+        }        
     }
 
     /**

Modified: commons/sandbox/runtime/trunk/src/main/native/include/acr_error.h
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/include/acr_error.h?rev=765975&r1=765974&r2=765975&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/include/acr_error.h (original)
+++ commons/sandbox/runtime/trunk/src/main/native/include/acr_error.h Fri Apr 17 13:02:56 2009
@@ -44,6 +44,7 @@
     ACR_EX_EINVAL,          /* java/lang/IllegalArgumentException */
     ACR_EX_EINDEX,          /* java/lang/IndexOutOfBoundsException */
     ACR_EX_ECCAST,          /* java/lang/ClassCastException */
+    ACR_EX_EINSTANCE,       /* java/lang/InstatntiationException */
     ACR_EX_EIO,             /* java/io/IOException */
     ACR_EX_ESYNC,           /* java/io/SyncFailedException */
     ACR_EX_ESOCK            /* java/net/SocketException */

Modified: commons/sandbox/runtime/trunk/src/main/native/shared/descriptor.c
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/shared/descriptor.c?rev=765975&r1=765974&r2=765975&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/shared/descriptor.c (original)
+++ commons/sandbox/runtime/trunk/src/main/native/shared/descriptor.c Fri Apr 17 13:02:56 2009
@@ -123,60 +123,69 @@
 
 ACR_JNI_EXPORT_DECLARE(void, Descriptor, close0)(ACR_JNISTDARGS)
 {
-    acr_descriptor_callback_fn_t *callback;
-    jint  i = GET_IFIELD_I(0000, _O);
+    if (_clazzn.i && _m0000n.i) {
+        acr_descriptor_callback_fn_t *callback;
+        jint  i = GET_IFIELD_I(0000, _O);
 #if CC_SIZEOF_VOIDP == 8
-    jlong p = GET_IFIELD_J(0001, _O);
-    jlong c = GET_IFIELD_J(0002, _O);
+        jlong p = GET_IFIELD_J(0001, _O);
+        jlong c = GET_IFIELD_J(0002, _O);
 
-    if (p) {
-        SET_IFIELD_J(0001, _O, 0);
-    }
+        if (p) {
+            SET_IFIELD_J(0001, _O, 0);
+        }
 #else
-    jlong p = GET_IFIELD_I(0001, _O);
-    jlong c = GET_IFIELD_I(0002, _O);
+        jlong p = GET_IFIELD_I(0001, _O);
+        jlong c = GET_IFIELD_I(0002, _O);
 
-    if (p) {
-        SET_IFIELD_I(0001, _O, 0);
-    }
+        if (p) {
+            SET_IFIELD_I(0001, _O, 0);
+        }
 #endif
-    if (i >= 0) {
-        SET_IFIELD_I(0000, _O, -1);
-    }
+        if (i >= 0) {
+            SET_IFIELD_I(0000, _O, -1);
+        }
 
-    callback = (acr_descriptor_callback_fn_t *)((acr_ptr_t)c);
-    if (callback) {
-        int rc = (*callback)(ACR_DESC_CLOSE, i, (void *)((acr_ptr_t)p));
-        if (rc) {
-            /* Throw IOException with errno message */
-            ACR_ThrowException(_E, THROW_FMARK, ACR_EX_EIO, rc);
+        callback = (acr_descriptor_callback_fn_t *)((acr_ptr_t)c);
+        if (callback) {
+            int rc = (*callback)(ACR_DESC_CLOSE, i, (void *)((acr_ptr_t)p));
+            if (rc) {
+                /* Throw IOException with errno message */
+                ACR_ThrowException(_E, THROW_FMARK, ACR_EX_EIO, rc);
+            }
         }
     }
+    else
+        ACR_ThrowException(_E, THROW_NMARK, ACR_EX_EINSTANCE, 0);
 }
 
 ACR_JNI_EXPORT_DECLARE(void, Descriptor, sync0)(ACR_JNISTDARGS)
 {
-    acr_descriptor_callback_fn_t *callback;
-    jint  i = GET_IFIELD_I(0000, _O);
+    if (_clazzn.i && _m0000n.i) {
+        acr_descriptor_callback_fn_t *callback;
+        jint  i = GET_IFIELD_I(0000, _O);
 #if CC_SIZEOF_VOIDP == 8
-    jlong p = GET_IFIELD_J(0001, _O);
-    jlong c = GET_IFIELD_J(0002, _O);
+        jlong p = GET_IFIELD_J(0001, _O);
+        jlong c = GET_IFIELD_J(0002, _O);
 
 #else
-    jlong p = GET_IFIELD_I(0001, _O);
-    jlong c = GET_IFIELD_I(0002, _O);
+        jlong p = GET_IFIELD_I(0001, _O);
+        jlong c = GET_IFIELD_I(0002, _O);
 
 #endif
-    callback = (acr_descriptor_callback_fn_t *)((acr_ptr_t)c);
-    if (callback) {
-        int rc = (*callback)(ACR_DESC_SYNC, i, (void *)((acr_ptr_t)p));
-        if (rc) {
-            if (rc == ACR_EINVAL)
-                ACR_ThrowException(_E, THROW_NMARK, ACR_EX_ESYNC, 0);
-            else
-                ACR_ThrowException(_E, THROW_FMARK, ACR_EX_EIO, rc);
+        callback = (acr_descriptor_callback_fn_t *)((acr_ptr_t)c);
+        if (callback) {
+            int rc = (*callback)(ACR_DESC_SYNC, i, (void *)((acr_ptr_t)p));
+            if (rc) {
+                if (rc == ACR_EINVAL)
+                    ACR_ThrowException(_E, THROW_NMARK, ACR_EX_ESYNC, 0);
+                else
+                    ACR_ThrowException(_E, THROW_FMARK, ACR_EX_EIO, rc);
+            }
         }
     }
+    else
+        ACR_ThrowException(_E, THROW_NMARK, ACR_EX_EINSTANCE, 0);
+
 }
 
 ACR_DECLARE(jobject) ACR_DescriptorCreate(JNIEnv *_E, int i, void *p,

Modified: commons/sandbox/runtime/trunk/src/main/native/shared/error.c
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/shared/error.c?rev=765975&r1=765974&r2=765975&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/shared/error.c (original)
+++ commons/sandbox/runtime/trunk/src/main/native/shared/error.c Fri Apr 17 13:02:56 2009
@@ -30,6 +30,7 @@
     "java/lang/IllegalArgumentException",
     "java/lang/IndexOutOfBoundsException",
     "java/lang/ClassCastException",
+    "java/lang/InstatntiationException",
     "java/io/IOException",
     "java/io/SyncFailedException",
     "java/net/SocketException",

Modified: commons/sandbox/runtime/trunk/src/main/native/shared/pointer.c
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/shared/pointer.c?rev=765975&r1=765974&r2=765975&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/shared/pointer.c (original)
+++ commons/sandbox/runtime/trunk/src/main/native/shared/pointer.c Fri Apr 17 13:02:56 2009
@@ -110,30 +110,35 @@
 
 ACR_JNI_EXPORT_DECLARE(void, Pointer, cleanup0)(ACR_JNISTDARGS)
 {
-    acr_pointer_cleanup_fn_t *cleanup;
+    if (_clazzn.i && _m0000n.i) {
+        acr_pointer_cleanup_fn_t *cleanup;
 #if CC_SIZEOF_VOIDP == 8
-    jlong h = GET_IFIELD_J(0000, _O);
-    jlong c = GET_IFIELD_J(0001, _O);
+        jlong h = GET_IFIELD_J(0000, _O);
+        jlong c = GET_IFIELD_J(0001, _O);
 
-    if (h) {
-        SET_IFIELD_J(0000, _O, 0);
-    }
+        if (h) {
+            SET_IFIELD_J(0000, _O, 0);
+        }
 #else
-    jint h  = GET_IFIELD_I(0000, _O);
-    jint c  = GET_IFIELD_I(0001, _O);
+        jint h  = GET_IFIELD_I(0000, _O);
+        jint c  = GET_IFIELD_I(0001, _O);
 
-    if (h) {
-        SET_IFIELD_I(0000, _O, 0);
-    }
+        if (h) {
+            SET_IFIELD_I(0000, _O, 0);
+        }
 #endif
-    cleanup = (acr_pointer_cleanup_fn_t *)((acr_ptr_t)c);
-    if (cleanup) {
-        int rc = (*cleanup)((void *)((acr_ptr_t)h));
-        if (rc) {
-            /* Throw RuntimeException with errno message */
-            ACR_ThrowException(_E, THROW_FMARK, ACR_EX_ERUNTIME, rc);
+        cleanup = (acr_pointer_cleanup_fn_t *)((acr_ptr_t)c);
+        if (cleanup) {
+            int rc = (*cleanup)((void *)((acr_ptr_t)h));
+            if (rc) {
+                /* Throw RuntimeException with errno message */
+                ACR_ThrowException(_E, THROW_FMARK, ACR_EX_ERUNTIME, rc);
+            }
         }
     }
+    else
+        ACR_ThrowException(_E, THROW_NMARK, ACR_EX_EINSTANCE, 0);
+
 }
 
 ACR_DECLARE(jobject) ACR_PointerCreate(JNIEnv *_E, void *p,