RFR: JDK-8057057: Cleanup DIO JNI code

Alexey Konstantinov alexey.konstantinov at oracle.com
Tue Sep 2 17:45:02 UTC 2014


Hi Jen,

jni_i2c.cpp:
   55     jfieldID addressID = deviceNumberID ?
   56             env->GetFieldID(configClass, "address", "I") :
   57             NULL;
   58     jint address = addressID ?
   59             env->GetIntField(config, addressID) :
   60             0;
   61
   62     jfieldID addressSizeID = addressID ?
   63             env->GetFieldID(configClass, "addressSize", "I") :
   64             NULL;
   65     jint addressSize = addressSizeID ?
   66             env->GetIntField(config, addressSizeID) :
   67             0;
Looks like in line 62 address should be tested instead of addressID.

jni_i2c.cpp:
   84         device_reference device = INVALID_DEVICE_REFERENCE;
   85         if (result == JAVACALL_DIO_OK) {
   86             device = createDeviceReference(handle, _i2c_close,
   87                                            javacall_i2c_lock, 
javacall_i2c_unlock);
   88             if (device == INVALID_DEVICE_REFERENCE) {
   89                 javacall_i2c_close(handle);
   90                 result = JAVACALL_DIO_OUT_OF_MEMORY;
   91             } else {
   92                 result = saveDeviceReferenceToDeviceObject(env, 
obj, device);
   93             }
   94         }
   95     }
   96
   97     if (env->ExceptionCheck() != JNI_TRUE) {
   98         checkJavacallFailure(env, result);
   99     }
Would you agree with that the implementation would be even more robust 
if there were a call to javacall_i2c_close(handle) to handle an 
exception that might happen in line 92?

Thanks,
Alexey

On 9/2/2014 8:08 PM, Jen Dority wrote:
> issue: https://bugs.openjdk.java.net/browse/JDK-8057057
> webrev: http://cr.openjdk.java.net/~jld/8057057/
>
> Hi All,
>
> Need a review for a bunch of JNI fixes. The code was missing 
> Exception/NULL checks in a bunch of key places and I even found a 
> missing return value.
>
> Thanks,
> Jen



More information about the dio-dev mailing list