提交 aad393f5 编写于 作者: P pchelko

8034038: [parfait] JNI exception pending in macosx/native/sun/awt/CDataTransferer.m

Reviewed-by: serb, azvegint
上级 fffc6497
...@@ -28,6 +28,7 @@ ...@@ -28,6 +28,7 @@
#import <AppKit/AppKit.h> #import <AppKit/AppKit.h>
#import <JavaNativeFoundation/JavaNativeFoundation.h> #import <JavaNativeFoundation/JavaNativeFoundation.h>
#import "jni_util.h"
#include "ThreadUtilities.h" #include "ThreadUtilities.h"
...@@ -172,7 +173,9 @@ JNF_COCOA_ENTER(env); ...@@ -172,7 +173,9 @@ JNF_COCOA_ENTER(env);
NSData *tiffImage = [imageRep TIFFRepresentation]; NSData *tiffImage = [imageRep TIFFRepresentation];
jsize tiffSize = (jsize)[tiffImage length]; // #warning 64-bit: -length returns NSUInteger, but NewByteArray takes jsize jsize tiffSize = (jsize)[tiffImage length]; // #warning 64-bit: -length returns NSUInteger, but NewByteArray takes jsize
returnValue = (*env)->NewByteArray(env, tiffSize); returnValue = (*env)->NewByteArray(env, tiffSize);
CHECK_NULL_RETURN(returnValue, nil);
jbyte *tiffData = (jbyte *)(*env)->GetPrimitiveArrayCritical(env, returnValue, 0); jbyte *tiffData = (jbyte *)(*env)->GetPrimitiveArrayCritical(env, returnValue, 0);
CHECK_NULL_RETURN(tiffData, nil);
[tiffImage getBytes:tiffData]; [tiffImage getBytes:tiffData];
(*env)->ReleasePrimitiveArrayCritical(env, returnValue, tiffData, 0); // Do not use JNI_COMMIT, as that will not free the buffer copy when +ProtectJavaHeap is on. (*env)->ReleasePrimitiveArrayCritical(env, returnValue, tiffData, 0); // Do not use JNI_COMMIT, as that will not free the buffer copy when +ProtectJavaHeap is on.
[imageRep release]; [imageRep release];
...@@ -184,12 +187,13 @@ JNF_COCOA_EXIT(env); ...@@ -184,12 +187,13 @@ JNF_COCOA_EXIT(env);
static jobject getImageForByteStream(JNIEnv *env, jbyteArray sourceData) static jobject getImageForByteStream(JNIEnv *env, jbyteArray sourceData)
{ {
if (sourceData == NULL) return NULL; CHECK_NULL_RETURN(sourceData, NULL);
jsize sourceSize = (*env)->GetArrayLength(env, sourceData); jsize sourceSize = (*env)->GetArrayLength(env, sourceData);
if (sourceSize == 0) return NULL; if (sourceSize == 0) return NULL;
jbyte *sourceBytes = (*env)->GetPrimitiveArrayCritical(env, sourceData, NULL); jbyte *sourceBytes = (*env)->GetPrimitiveArrayCritical(env, sourceData, NULL);
CHECK_NULL_RETURN(sourceBytes, NULL);
NSData *rawData = [NSData dataWithBytes:sourceBytes length:sourceSize]; NSData *rawData = [NSData dataWithBytes:sourceBytes length:sourceSize];
NSImage *newImage = [[NSImage alloc] initWithData:rawData]; NSImage *newImage = [[NSImage alloc] initWithData:rawData];
...@@ -197,8 +201,7 @@ static jobject getImageForByteStream(JNIEnv *env, jbyteArray sourceData) ...@@ -197,8 +201,7 @@ static jobject getImageForByteStream(JNIEnv *env, jbyteArray sourceData)
[newImage release]; [newImage release];
(*env)->ReleasePrimitiveArrayCritical(env, sourceData, sourceBytes, JNI_ABORT); (*env)->ReleasePrimitiveArrayCritical(env, sourceData, sourceBytes, JNI_ABORT);
CHECK_NULL_RETURN(newImage, NULL);
if (newImage == nil) return NULL;
// The ownership of the NSImage is passed to the new CImage jobject. No need to release it. // The ownership of the NSImage is passed to the new CImage jobject. No need to release it.
static JNF_CLASS_CACHE(jc_CImage, "sun/lwawt/macosx/CImage"); static JNF_CLASS_CACHE(jc_CImage, "sun/lwawt/macosx/CImage");
...@@ -231,7 +234,8 @@ static jobjectArray CreateJavaFilenameArray(JNIEnv *env, NSArray *filenameArray) ...@@ -231,7 +234,8 @@ static jobjectArray CreateJavaFilenameArray(JNIEnv *env, NSArray *filenameArray)
if (filenameCount == 0) return nil; if (filenameCount == 0) return nil;
// Get the java.lang.String class object: // Get the java.lang.String class object:
jclass stringClazz = (*env)->FindClass(env, "java/lang/String"); // can't be null jclass stringClazz = (*env)->FindClass(env, "java/lang/String");
CHECK_NULL_RETURN(stringClazz, nil);
jobject jfilenameArray = (*env)->NewObjectArray(env, filenameCount, stringClazz, NULL); // AWT_THREADING Safe (known object) jobject jfilenameArray = (*env)->NewObjectArray(env, filenameCount, stringClazz, NULL); // AWT_THREADING Safe (known object)
if ((*env)->ExceptionOccurred(env)) { if ((*env)->ExceptionOccurred(env)) {
(*env)->ExceptionDescribe(env); (*env)->ExceptionDescribe(env);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册