-
Notifications
You must be signed in to change notification settings - Fork 5.9k
8358452: JNI exception pending in Java_sun_awt_screencast_ScreencastHelper_remoteDesktopKeyImpl of screencast_pipewire.c:1214 (ID: 51119) #25605
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
base: master
Are you sure you want to change the base?
Conversation
…elper_remoteDesktopKeyImpl of screencast_pipewire.c:1214 (ID: 51119)
👋 Welcome back azvegint! A progress list of the required criteria for merging this PR into |
@azvegint This change now passes all automated pre-integration checks. ℹ️ This project also has non-automated pre-integration requirements. Please see the file CONTRIBUTING.md for details. After integration, the commit message for the final commit will be:
You can use pull request commands such as /summary, /contributor and /issue to adjust it as needed. At the time when this comment was updated there had been 73 new commits pushed to the
As there are no conflicts, your changes will automatically be rebased on top of these commits when integrating. If you prefer to avoid this automatic rebasing, please check the documentation for the /integrate command for further details. ➡️ To integrate this PR with the above commit message to the |
Webrevs
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
@@ -1206,7 +1206,7 @@ JNIEXPORT jint JNICALL Java_sun_awt_screencast_ScreencastHelper_remoteDesktopKey | |||
int key = awt_getX11KeySym(jkey); | |||
AWT_UNLOCK(); | |||
|
|||
if (key == NoSymbol) { | |||
if (key == NoSymbol || (*env)->ExceptionCheck(env)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess we normally call ExceptionCheck after we call some JNI methods like (*env)->NewString or (*env)->CallObjectMethod. Here before this check we are not calling any JNI method so I think we should do it after we call (*env)->GetStringUTFChars ie. after l1214
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we are not calling any JNI method
We have the AWT_LOCK()
/ AWT_UNLOCK();
macro expansions with JNI methods being called.
jdk/src/java.desktop/unix/native/common/awt/awt.h
Lines 97 to 110 in 78a392a
#define AWT_NOFLUSH_UNLOCK_IMPL() \ | |
do { \ | |
jthrowable pendingException; \ | |
if ((pendingException = (*env)->ExceptionOccurred(env)) != NULL) { \ | |
(*env)->ExceptionClear(env); \ | |
} \ | |
(*env)->CallStaticVoidMethod(env, tkClass, awtUnlockMID); \ | |
if ((*env)->ExceptionCheck(env)) { \ | |
(*env)->ExceptionClear(env); \ | |
} \ | |
if (pendingException) { \ | |
(*env)->Throw(env, pendingException); \ | |
} \ | |
} while (0) |
This is exactly what static code analysis tool complains about.
JNI exception pending in Java_sun_awt_screencast_ScreencastHelper_remoteDesktopKeyImpl of screencast_pipewire.c:1214
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But we are calling ExceptionCheck in that macro in l104 so why do we again need to call?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please note the line 108 of the awt.h
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But then it should show JNI exception pending for all places where we call AWT_UNLOCK, why only this place?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We call AWT_UNLOCK in awt_Robot.c, gtk3_interface.c, awt_GraphicsEnv.c where there's no ExceptionCheck after the call.
For example, here ExceptionCheck is called not after AWT_UNLOCK but after the next JNI call (*env)->NewObject
jdk/src/java.desktop/unix/native/libawt_xawt/awt/awt_GraphicsEnv.c
Lines 1281 to 1290 in ebd8528
AWT_LOCK (); | |
XGetWindowAttributes(awt_display, RootWindow(awt_display, screen), | |
&xwa); | |
AWT_UNLOCK (); | |
bounds = (*env)->NewObject(env, clazz, mid, 0, 0, | |
xwa.width, xwa.height); | |
} | |
if ((*env)->ExceptionCheck(env)) { |
Normally we do ExceptionCheck after GetStringUTFChars
jdk/src/java.desktop/windows/native/libawt/windows/ShellFolder2.cpp
Lines 1192 to 1193 in ebd8528
const char *pLibName = env->GetStringUTFChars(libName, NULL); | |
JNU_CHECK_EXCEPTION_RETURN(env, 0); |
Did you verify the warning goes off only by this PR change? If not, I will also recommend doing CHECK_EXCEPTION after GetStringUTFChars too..
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We call AWT_UNLOCK in awt_Robot.c, gtk3_interface.c, awt_GraphicsEnv.c where there's no ExceptionCheck after the call.
Neither awt_Robot.c nor gtk3_interface.c calls any JNI functions afterwards.
the awt_GraphicsEnv.c case doesn't call JNI functions between AWT_LOCK
/ AWT_UNLOCK
(see explanation below about false positive).
Normally we do ExceptionCheck after GetStringUTFChars
I added it just in case, but the GetStringUTFChars documentation doesn't mention any exceptions being thrown.
Did you verify the warning goes off only by this PR change?
it is the only reported line by the tool:
JNI exception pending in Java_sun_awt_screencast_ScreencastHelper_remoteDesktopKeyImpl of screencast_pipewire.c:1214
so it should resolve the issue.
But now I think it might be a false positive:
AWT_LOCK()
clears all exceptions:
jdk/src/java.desktop/unix/native/common/awt/awt.h
Lines 86 to 95 in 78a392a
#define AWT_LOCK_IMPL() \ do { \ if ((*env)->ExceptionCheck(env)) { \ (*env)->ExceptionClear(env); \ } \ (*env)->CallStaticVoidMethod(env, tkClass, awtLockMID); \ if ((*env)->ExceptionCheck(env)) { \ (*env)->ExceptionClear(env); \ } \ } while(0) awt_getX11KeySym
doesn't call JNI methods at allAWT_UNLOCK()
also clears an exception, and rethrows a previously pending exception, if any.
jdk/src/java.desktop/unix/native/common/awt/awt.h
Lines 97 to 110 in 78a392a
#define AWT_NOFLUSH_UNLOCK_IMPL() \ do { \ jthrowable pendingException; \ if ((pendingException = (*env)->ExceptionOccurred(env)) != NULL) { \ (*env)->ExceptionClear(env); \ } \ (*env)->CallStaticVoidMethod(env, tkClass, awtUnlockMID); \ if ((*env)->ExceptionCheck(env)) { \ (*env)->ExceptionClear(env); \ } \ if (pendingException) { \ (*env)->Throw(env, pendingException); \ } \ } while (0)
Since neither 1. nor 2. produces an exception, no exception will be thrown.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
3 rethrows the exception, maybe tool is complaining about that..maybe we should find out what that exception is and who is throwing?
Should we call EXCEPTION_CHECK_DESCRIBE instead to find out what exception it is complaining about by running the tool?
Also, dont we need to do ExceptionClear too in addition to ExcepionCheck to clear out the exception else it will keep it pending?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think so. Let Java catch it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok..but checkReturnValue in ScreenCastHelper.java doesnt handle the exception for RESULT_ERROR case so it will be left to application to handle and am not sure if they will expect this internal exception..
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me..
It is still unclear why an exception is reported just in this line and others like mention below, can we narrow down what exact line in the code/macro caused that? |
It is It seems to be a false positive because neither |
After calling
AWT_UNLOCK()
,GetStringUTFChars
may be called with a pending exception.Progress
Issue
Reviewers
Reviewing
Using
git
Checkout this PR locally:
$ git fetch https://git.openjdk.org/jdk.git pull/25605/head:pull/25605
$ git checkout pull/25605
Update a local copy of the PR:
$ git checkout pull/25605
$ git pull https://git.openjdk.org/jdk.git pull/25605/head
Using Skara CLI tools
Checkout this PR locally:
$ git pr checkout 25605
View PR using the GUI difftool:
$ git pr show -t 25605
Using diff file
Download this PR as a diff file:
https://git.openjdk.org/jdk/pull/25605.diff
Using Webrev
Link to Webrev Comment