From 5736716ed0598c97273583717ffb9d22a60ca7a4 Mon Sep 17 00:00:00 2001 From: Sven Gothel Date: Fri, 6 Dec 2019 09:10:14 +0100 Subject: Bug 1412 - JNI: GlueGen JavaEmitter: Check & Handle Exception after calling back into Java The generated JNI code JVMUtil_NewDirectByteBufferCopy(..) calls Buffers.newDirectByteBuffer(..) and potential exceptions should be checked. --- src/java/com/jogamp/gluegen/JavaEmitter.java | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'src/java/com/jogamp') diff --git a/src/java/com/jogamp/gluegen/JavaEmitter.java b/src/java/com/jogamp/gluegen/JavaEmitter.java index 02e56a4..577bca4 100644 --- a/src/java/com/jogamp/gluegen/JavaEmitter.java +++ b/src/java/com/jogamp/gluegen/JavaEmitter.java @@ -2554,6 +2554,7 @@ public class JavaEmitter implements GlueEmitter { "#define JINT_MAX_VALUE ((size_t)0x7fffffffU)\n"+ "static const char * sNewBufferImplNotCalled = \"initializeImpl() not called\";\n"+ "static const char * sNewBufferMAX_INT = \"capacity > MAX_INT\";\n"+ + "static const char * sNewBufferEXCPT = \"New direct ByteBuffer threw Exception\";\n"+ "static const char * sNewBufferNULL = \"New direct ByteBuffer is NULL\";\n"+ "\n"+ "static jobject JVMUtil_NewDirectByteBufferCopy(JNIEnv *env, void * source_address, size_t capacity) {\n"+ @@ -2571,6 +2572,12 @@ public class JavaEmitter implements GlueEmitter { " return NULL;\n"+ " }\n"+ " jbyteBuffer = (*env)->CallStaticObjectMethod(env, clazzBuffers, cstrBuffersNew, (jint)capacity);\n"+ + " if( (*env)->ExceptionCheck(env) ) {\n"+ + " (*env)->ExceptionDescribe(env);\n"+ + " (*env)->ExceptionClear(env);\n"+ + " (*env)->FatalError(env, sNewBufferEXCPT);\n"+ + " return NULL;\n"+ + " }\n"+ " if( NULL == jbyteBuffer ) {\n"+ " fprintf(stderr, \"%s %s: size %lu\\n\", sFatalError, sNewBufferNULL, (unsigned long)capacity);\n"+ " (*env)->FatalError(env, sNewBufferNULL);\n"+ -- cgit v1.2.3