RFR: 8366149: JNI exception pending in Java_sun_awt_X11GraphicsDevice_pGetBounds of awt_GraphicsEnv.c:1484

Damon Nguyen dnguyen at openjdk.org
Fri Sep 5 21:49:10 UTC 2025


On Fri, 5 Sep 2025 04:35:07 GMT, Phil Race <prr at openjdk.org> wrote:

>> In the scenario where AWT's UNLOCK API encounters a pendingException, the env pointer throws the pendingException (as seen in `awt.h`). However, in `Java_sun_awt_X11GraphicsDevice_pGetBounds`, after `AWT_UNLOCK`, the bounds var is set. The exception check does not occur until after the bounds is set, so the bounds may be set to an undesired value. This fix adds another exception check to look for this pendingException after `AWT_UNLOCK`.
>
> src/java.desktop/unix/native/libawt_xawt/awt/awt_GraphicsEnv.c line 1289:
> 
>> 1287:             AWT_UNLOCK ();
>> 1288: 
>> 1289:             if ((*env)->ExceptionCheck(env)) {
> 
> Is the problem that we are here because bounds == null and one way this is possible is that the call at line 1265 failed? Meaning threw an unlikely exception.
> If so, maybe that is where we should just "return NULL".

My understanding of the issue is that there is a possible `pendingException` on line 1287. This is possible by `AWT_NOFLUSH_UNLOCK_IMPL()` in `awt.h` as you previously pointed me to. Seems like setting bounds by the code that was previously on lines 1289-1290 was unsafe due to the `AWT_UNLOCK` possibly throwing an exception right before it.

I don't think bounds can be null in this area because line 1279 checks for this. But if the `AWT_UNLOCK` here is throwing a `pendingException`, I think returning null is what should be done here since the same is done on line 1297, except this won't be reached in this case until after bounds is unsafely set.

I can just `return NULL` instead near line 1265 as you suggested, but from what I read, the exception would be at line 1287 (which is after).

-------------

PR Review Comment: https://git.openjdk.org/jdk/pull/27110#discussion_r2326105323


More information about the client-libs-dev mailing list