Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

8260616: Removing remaining JNF dependencies in the java.desktop module #2305

Closed
wants to merge 7 commits into from
@@ -986,7 +986,7 @@ - (void) insertText:(id)aString replacementRange:(NSRange)replacementRange

DECLARE_METHOD(jm_insertText, jc_CInputMethod, "insertText", "(Ljava/lang/String;)V");
jstring insertedText = NSStringToJavaString(env, useString);
(*env)->CallVoidMethod(env, fInputMethodLOCKABLE, jm_insertText, insertedText); // AWT_THREADING Safe (AWTRunLoopMode)
(*env)->CallVoidMethod(env, fInputMethodLOCKABLE, jm_insertText, insertedText);
CHECK_EXCEPTION();
(*env)->DeleteLocalRef(env, insertedText);

@@ -1052,7 +1052,7 @@ - (void) setMarkedText:(id)aString selectedRange:(NSRange)selectionRange replace
// the underlining and color that should be done to the string. We need to look at the underline
// style and color to determine what kind of Java hilighting needs to be done.
jstring inProcessText = NSStringToJavaString(env, incomingString);
(*env)->CallVoidMethod(env, fInputMethodLOCKABLE, jm_startIMUpdate, inProcessText); // AWT_THREADING Safe (AWTRunLoopMode)
(*env)->CallVoidMethod(env, fInputMethodLOCKABLE, jm_startIMUpdate, inProcessText);
CHECK_EXCEPTION();
(*env)->DeleteLocalRef(env, inProcessText);

@@ -1077,7 +1077,7 @@ - (void) setMarkedText:(id)aString selectedRange:(NSRange)selectionRange replace
isGray = !([underlineColorObj isEqual:[NSColor blackColor]]);

(*env)->CallVoidMethod(env, fInputMethodLOCKABLE, jm_addAttribute, isThickUnderline,
isGray, effectiveRange.location, effectiveRange.length); // AWT_THREADING Safe (AWTRunLoopMode)
isGray, effectiveRange.location, effectiveRange.length);
CHECK_EXCEPTION();
}
}
@@ -1092,7 +1092,7 @@ - (void) setMarkedText:(id)aString selectedRange:(NSRange)selectionRange replace
}

(*env)->CallVoidMethod(env, fInputMethodLOCKABLE, jm_dispatchText,
selectionRange.location, selectionRange.length, JNI_FALSE); // AWT_THREADING Safe (AWTRunLoopMode)
selectionRange.location, selectionRange.length, JNI_FALSE);
CHECK_EXCEPTION();
// If the marked text is being cleared (zero-length string) don't handle the key event.
if ([incomingString length] == 0) {
@@ -1114,7 +1114,7 @@ - (void) unmarkText
JNIEnv *env = [ThreadUtilities getJNIEnv];
GET_CIM_CLASS();
DECLARE_METHOD(jm_unmarkText, jc_CInputMethod, "unmarkText", "()V");
(*env)->CallVoidMethod(env, fInputMethodLOCKABLE, jm_unmarkText); // AWT_THREADING Safe (AWTRunLoopMode)
(*env)->CallVoidMethod(env, fInputMethodLOCKABLE, jm_unmarkText);
CHECK_EXCEPTION();
}

@@ -1167,7 +1167,7 @@ - (NSAttributedString *) attributedSubstringForProposedRange:(NSRange)theRange a

JNIEnv *env = [ThreadUtilities getJNIEnv];
DECLARE_METHOD_RETURN(jm_substringFromRange, jc_CInputMethod, "attributedSubstringFromRange", "(II)Ljava/lang/String;", nil);
jobject theString = (*env)->CallObjectMethod(env, fInputMethodLOCKABLE, jm_substringFromRange, theRange.location, theRange.length); // AWT_THREADING Safe (AWTRunLoopMode)
jobject theString = (*env)->CallObjectMethod(env, fInputMethodLOCKABLE, jm_substringFromRange, theRange.location, theRange.length);
CHECK_EXCEPTION_NULL_RETURN(theString, nil);

id result = [[[NSAttributedString alloc] initWithString:JavaStringToNSString(env, theString)] autorelease];
@@ -1201,7 +1201,7 @@ - (NSRange) markedRange
GET_CIM_CLASS_RETURN(range);
DECLARE_METHOD_RETURN(jm_markedRange, jc_CInputMethod, "markedRange", "()[I", range);

array = (*env)->CallObjectMethod(env, fInputMethodLOCKABLE, jm_markedRange); // AWT_THREADING Safe (AWTRunLoopMode)
array = (*env)->CallObjectMethod(env, fInputMethodLOCKABLE, jm_markedRange);
CHECK_EXCEPTION();

if (array) {
@@ -1242,7 +1242,7 @@ - (NSRange) selectedRange
fprintf(stderr, "AWTView InputMethod Selector Called : [selectedRange]\n");
#endif // IM_DEBUG

array = (*env)->CallObjectMethod(env, fInputMethodLOCKABLE, jm_selectedRange); // AWT_THREADING Safe (AWTRunLoopMode)
array = (*env)->CallObjectMethod(env, fInputMethodLOCKABLE, jm_selectedRange);
CHECK_EXCEPTION();
if (array) {
_array = (*env)->GetIntArrayElements(env, array, &isCopy);
@@ -1281,7 +1281,7 @@ - (NSRect) firstRectForCharacterRange:(NSRange)theRange actualRange:(NSRangePoin
#endif // IM_DEBUG

array = (*env)->CallObjectMethod(env, fInputMethodLOCKABLE, jm_firstRectForCharacterRange,
theRange.location); // AWT_THREADING Safe (AWTRunLoopMode)
theRange.location);
CHECK_EXCEPTION();

_array = (*env)->GetIntArrayElements(env, array, &isCopy);
@@ -1322,7 +1322,7 @@ - (NSUInteger)characterIndexForPoint:(NSPoint)thePoint
#endif // IM_DEBUG

jint index = (*env)->CallIntMethod(env, fInputMethodLOCKABLE, jm_characterIndexForPoint,
(jint)flippedLocation.x, (jint)flippedLocation.y); // AWT_THREADING Safe (AWTRunLoopMode)
(jint)flippedLocation.x, (jint)flippedLocation.y);
CHECK_EXCEPTION();

#ifdef IM_DEBUG
@@ -291,7 +291,7 @@ - (void)_handleOpenURLEvent:(NSAppleEventDescriptor *)openURLEvent withReplyEven
jstring jURL = NSStringToJavaString(env, url);
GET_APPEVENTHANDLER_CLASS();
DECLARE_STATIC_METHOD(jm_handleOpenURI, sjc_AppEventHandler, "handleOpenURI", "(Ljava/lang/String;)V");
(*env)->CallStaticVoidMethod(env, sjc_AppEventHandler, jm_handleOpenURI, jURL); // AWT_THREADING Safe (event)
(*env)->CallStaticVoidMethod(env, sjc_AppEventHandler, jm_handleOpenURI, jURL);
CHECK_EXCEPTION();
(*env)->DeleteLocalRef(env, jURL);

@@ -310,7 +310,7 @@ - (jobject)_createFilePathArrayFrom:(NSArray *)filenames withEnv:(JNIEnv *)env {
DECLARE_METHOD_RETURN(jm_ArrayList_ctor, sjc_ArrayList, "<init>", "(I)V", NULL);
DECLARE_METHOD_RETURN(jm_ArrayList_add, sjc_ArrayList, "add", "(Ljava/lang/Object;)Z", NULL);

jobject jFileNamesArray = (*env)->NewObject(env, sjc_ArrayList, jm_ArrayList_ctor, (jint)[filenames count]); // AWT_THREADING Safe (known object)
jobject jFileNamesArray = (*env)->NewObject(env, sjc_ArrayList, jm_ArrayList_ctor, (jint)[filenames count]);
CHECK_EXCEPTION_NULL_RETURN(jFileNamesArray, NULL);

for (NSString *filename in filenames) {
@@ -363,7 +363,7 @@ - (NSApplicationPrintReply)application:(NSApplication *)application printFiles:(
GET_APPEVENTHANDLER_CLASS_RETURN(NSPrintingCancelled);
DECLARE_STATIC_METHOD_RETURN(jm_handlePrintFile, sjc_AppEventHandler,
"handlePrintFiles", "(Ljava/util/List;)V", NSPrintingCancelled);
(*env)->CallStaticVoidMethod(env, sjc_AppEventHandler, jm_handlePrintFile, jFileNamesArray); // AWT_THREADING Safe (event)
(*env)->CallStaticVoidMethod(env, sjc_AppEventHandler, jm_handlePrintFile, jFileNamesArray);
CHECK_EXCEPTION();
(*env)->DeleteLocalRef(env, jFileNamesArray);

@@ -378,7 +378,7 @@ + (void)_notifyJava:(jint)notificationType {
JNIEnv *env = [ThreadUtilities getJNIEnv];
GET_APPEVENTHANDLER_CLASS();
DECLARE_STATIC_METHOD(jm_handleNativeNotification, sjc_AppEventHandler, "handleNativeNotification", "(I)V");
(*env)->CallStaticVoidMethod(env, sjc_AppEventHandler, jm_handleNativeNotification, notificationType); // AWT_THREADING Safe (event)
(*env)->CallStaticVoidMethod(env, sjc_AppEventHandler, jm_handleNativeNotification, notificationType);
CHECK_EXCEPTION();
}

@@ -622,7 +622,7 @@ + (NSImage *)_dockIconImage {
[ThreadUtilities performOnMainThread:@selector(_registerForNotification:)
on:[ApplicationDelegate class]
withObject:[NSNumber numberWithInt:notificationType]
waitUntilDone:NO]; // AWT_THREADING Safe (non-blocking)
waitUntilDone:NO];
JNI_COCOA_EXIT(env);
}

@@ -98,7 +98,7 @@ - (void)checkPasteboard:(id)sender {
DECLARE_METHOD(jm_lostOwnership, jc_CClipboard, "notifyLostOwnership", "()V");
@synchronized(self) {
if (self.clipboardOwner) {
(*env)->CallVoidMethod(env, self.clipboardOwner, jm_lostOwnership); // AWT_THREADING Safe (event)
(*env)->CallVoidMethod(env, self.clipboardOwner, jm_lostOwnership);
CHECK_EXCEPTION();
(*env)->DeleteGlobalRef(env, self.clipboardOwner);
self.clipboardOwner = NULL;
@@ -135,7 +135,7 @@ static jobjectArray CreateJavaFilenameArray(JNIEnv *env, NSArray *filenameArray)
// Get the java.lang.String class object:
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);
if ((*env)->ExceptionOccurred(env)) {
(*env)->ExceptionDescribe(env);
(*env)->ExceptionClear(env);
@@ -571,7 +571,7 @@ - (void)doDrag
GET_DSCP_CLASS();
DECLARE_METHOD(dragDropFinishedMethod, CDragSourceContextPeerClass, "dragDropFinished", "(ZIII)V");
DLog3(@" -> posting dragDropFinished, point %f, %f", point.x, point.y);
(*env)->CallVoidMethod(env, fDragSourceContextPeer, dragDropFinishedMethod, success, dragOp, (jint) point.x, (jint) point.y); // AWT_THREADING Safe (event)
(*env)->CallVoidMethod(env, fDragSourceContextPeer, dragDropFinishedMethod, success, dragOp, (jint) point.x, (jint) point.y);
CHECK_EXCEPTION();
DECLARE_METHOD(resetHoveringMethod, CDragSourceContextPeerClass, "resetHovering", "()V");
(*env)->CallVoidMethod(env, fDragSourceContextPeer, resetHoveringMethod); // Hust reset static variable
@@ -593,7 +593,7 @@ - (void)drag
{
AWT_ASSERT_NOT_APPKIT_THREAD;

[self performSelectorOnMainThread:@selector(doDrag) withObject:nil waitUntilDone:YES]; // AWT_THREADING Safe (called from unique asynchronous thread)
[self performSelectorOnMainThread:@selector(doDrag) withObject:nil waitUntilDone:YES];
}

/******************************** BEGIN NSDraggingSource Interface ********************************/
@@ -612,7 +612,7 @@ - (void)draggingOperationChanged:(NSDragOperation)dragOp {

GET_DSCP_CLASS();
DECLARE_METHOD(operationChangedMethod, CDragSourceContextPeerClass, "operationChanged", "(IIII)V");
(*env)->CallVoidMethod(env, fDragSourceContextPeer, operationChangedMethod, targetActions, modifiedModifiers, (jint) point.x, (jint) point.y); // AWT_THREADING Safe (event)
(*env)->CallVoidMethod(env, fDragSourceContextPeer, operationChangedMethod, targetActions, modifiedModifiers, (jint) point.x, (jint) point.y);
CHECK_EXCEPTION();
}

@@ -687,11 +687,11 @@ - (void)draggedImage:(NSImage *)image movedTo:(NSPoint)screenPoint {
DLog3(@" -> posting dragMotion, point %f, %f", point.x, point.y);
GET_DSCP_CLASS();
DECLARE_METHOD(dragMotionMethod, CDragSourceContextPeerClass, "dragMotion", "(IIII)V");
(*env)->CallVoidMethod(env, fDragSourceContextPeer, dragMotionMethod, targetActions, (jint) fModifiers, (jint) point.x, (jint) point.y); // AWT_THREADING Safe (event)
(*env)->CallVoidMethod(env, fDragSourceContextPeer, dragMotionMethod, targetActions, (jint) fModifiers, (jint) point.x, (jint) point.y);
CHECK_EXCEPTION();
DLog3(@" -> posting dragMouseMoved, point %f, %f", point.x, point.y);
DECLARE_METHOD(dragMouseMovedMethod, CDragSourceContextPeerClass, "dragMouseMoved", "(IIII)V");
(*env)->CallVoidMethod(env, fDragSourceContextPeer, dragMouseMovedMethod, targetActions, (jint) fModifiers, (jint) point.x, (jint) point.y); // AWT_THREADING Safe (event)
(*env)->CallVoidMethod(env, fDragSourceContextPeer, dragMouseMovedMethod, targetActions, (jint) fModifiers, (jint) point.x, (jint) point.y);
CHECK_EXCEPTION();
}
JNI_COCOA_EXIT(env);
@@ -718,7 +718,7 @@ - (void) postDragEnter {
DLog3(@" -> posting dragEnter, point %f, %f", point.x, point.y);
GET_DSCP_CLASS();
DECLARE_METHOD(dragEnterMethod, CDragSourceContextPeerClass, "dragEnter", "(IIII)V");
(*env)->CallVoidMethod(env, fDragSourceContextPeer, dragEnterMethod, targetActions, (jint) fModifiers, (jint) point.x, (jint) point.y); // AWT_THREADING Safe (event)
(*env)->CallVoidMethod(env, fDragSourceContextPeer, dragEnterMethod, targetActions, (jint) fModifiers, (jint) point.x, (jint) point.y);
CHECK_EXCEPTION();
}

@@ -730,7 +730,7 @@ - (void) postDragExit {
DLog3(@" -> posting dragExit, point %f, %f", point.x, point.y);
GET_DSCP_CLASS();
DECLARE_METHOD(dragExitMethod, CDragSourceContextPeerClass, "dragExit", "(II)V");
(*env)->CallVoidMethod(env, fDragSourceContextPeer, dragExitMethod, (jint) point.x, (jint) point.y); // AWT_THREADING Safe (event)
(*env)->CallVoidMethod(env, fDragSourceContextPeer, dragExitMethod, (jint) point.x, (jint) point.y);
CHECK_EXCEPTION();

}
@@ -146,7 +146,7 @@ - (BOOL) askFilenameFilter:(NSString *)filename {

DECLARE_CLASS_RETURN(jc_CFileDialog, "sun/lwawt/macosx/CFileDialog", NO);
DECLARE_METHOD_RETURN(jm_queryFF, jc_CFileDialog, "queryFilenameFilter", "(Ljava/lang/String;)Z", NO);
BOOL returnValue = (*env)->CallBooleanMethod(env, fFileDialog, jm_queryFF, jString); // AWT_THREADING Safe (AWTRunLoopMode)
BOOL returnValue = (*env)->CallBooleanMethod(env, fFileDialog, jm_queryFF, jString);
CHECK_EXCEPTION();
(*env)->DeleteLocalRef(env, jString);

@@ -608,6 +608,7 @@ render using the right font (see bug 7183516) when attribString is not
// Get string to draw and the length
const jchar *unichars = (*env)->GetStringChars(env, str, NULL);
if (unichars == NULL) {
JNU_ThrowOutOfMemoryError(env, "Could not get string chars");
return;
Copy link
Member

@mrserb mrserb Feb 1, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do not we need to throw an exception here? Otherwise, GetStringChars error will be ignored?

Copy link
Contributor Author

@prrace prrace Feb 2, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Look a few lines further up at my reply 3 days ago Gerard about this.

Copy link
Member

@mrserb mrserb Feb 2, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I read it and not sure that it is fine to ignore this error, why not throw an exception and signal the CTextPipe_doDrawString that an error occurred like InvalidPipeException or something(Sometimes we wrap other exception like OOM into the InvalidPipeException and this seems similar case)?

Copy link
Contributor Author

@prrace prrace Feb 2, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The changes look good to me, but please see my comment from my review about documenting NormalizedPathNSStringFromJavaString() API.

I see it. I will copy what you wrote in there.

Copy link
Contributor Author

@prrace prrace Feb 2, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I read it and not sure that it is fine to ignore this error, why not throw an exception and signal the CTextPipe_doDrawString that an error occurred like InvalidPipeException or something(Sometimes we wrap other exception like OOM into the InvalidPipeException and this seems similar case)?

OK. I will do something like throw OOME or InternalError. Since we already checked for NULL as an arg any failure here implies a deep VM problem rather than anytjhing like a 2D invalid pipe

}

@@ -84,7 +84,7 @@ - (NSString *)getDescription
fCompLocal );
CHECK_EXCEPTION();
if (jstr != NULL) {
str = JavaStringToNSString(env, jstr); // AWT_THREADING Safe (AWTRunLoopMode)
str = JavaStringToNSString(env, jstr);
(*env)->DeleteLocalRef(env, jstr);
}
(*env)->DeleteLocalRef(env, fCompLocal);
@@ -100,7 +100,7 @@ - (void)perform
"(Ljavax/accessibility/AccessibleAction;ILjava/awt/Component;)V");

(*env)->CallStaticVoidMethod(env, sjc_CAccessibility, jm_doAccessibleAction,
fAccessibleAction, fIndex, fComponent); // AWT_THREADING Safe (AWTRunLoopMode)
fAccessibleAction, fIndex, fComponent);
CHECK_EXCEPTION();
}