Using java.awt.Toolkit.getDefaultToolkit().getScreenSize() reflectively causes InaccessibleObjectException

Rony G. Flatscher Rony.Flatscher at wu.ac.at
Thu Jan 5 18:42:07 UTC 2017


Trying to run a program that gets the screen dimensions using
java.awt.Toolkit.getDefaultToolkit().getScreenSize() reflectively.

On a 64-bit Ubuntu the returned Toolkit is of type sun.awt.X11.XToolkit. Reflectively invoking its
method getScreenSize() causes the following exception to be thrown on 9-ea+134:

    java.lang.reflect.InaccessibleObjectException: unable to make member of class sun.awt.SunToolkit
    accessible: module java.desktop does not export sun.awt to unnamed module ...

A little bit baffled as this is from a script that has been working flawlessly throughout more than
a decade on various Java versions and which employs documented public methods only (the sun.awt
object is returned by java.awt.Toolkit). Is this a known "legacy"problem :) that I could circumvent
somehow or a bug that needs to be reported?

---rony



More information about the jdk9-dev mailing list