[OpenJDK 2D-Dev] [14] Review Request: 8229810 NullPointerException getting bounds of GraphicsConfiguration

Sergey Bylokhov Sergey.Bylokhov at oracle.com
Mon Aug 19 19:03:15 UTC 2019


Hello.
Please review the fix for JDK 14.

Bug: https://bugs.openjdk.java.net/browse/JDK-8229810
Fix: http://cr.openjdk.java.net/~serb/8229810/webrev.00

The root cause is a lack of synchronization in CGraphicsEnvironment,
we create the GraphicsDevice under a special lock which is used to
access the list of devices:
http://hg.openjdk.java.net/jdk/client/file/39f133168348/src/java.desktop/macosx/classes/sun/awt/CGraphicsEnvironment.java#l184

but initialize the device w/o this lock.
http://hg.openjdk.java.net/jdk/client/file/39f133168348/src/java.desktop/macosx/classes/sun/awt/CGraphicsEnvironment.java#l187

So it is possible that we create the device, add it to the list of devices,
and before we initialize it the user could access the not fully initialized object.

The bug exists from the jdk7, but it was hidden because all fields in CGraphicsDevice
were primitives, so the app just used invalid data. In JDK-8211992 the object field "bounds"
was added and now we can get NPE if this field was not initialized.

As a fix, I suggest to always initialize the graphics device in the constructor.

Note that we cannot move "displayChanged" which will notify devices and all listeners
in awt/swing in the CGraphicsEnvironment under the lock, it will cause various
deadlocks in the a different listeners.

-- 
Best regards, Sergey.


More information about the 2d-dev mailing list