PreviousNextTracker indexSee it online !

(218/240) 3971 - Exception trying to set X11 WM_CLASS in JDK9 on Linux

JDK9 includes modules since jdk-9-ea+111. There is an exception when trying to set X11 WM_CLASS (aka x11.wmclass) to "jedit" on Linux via reflection. Luckily, jEdit still starts. The culprit is the call to [setAccessible](https://sourceforge.net/p/jedit/svn/HEAD/tree/jEdit/trunk/org/gjt/sp/jedit/jEdit.java#l161). As a consequence, X11 window class names will be different with JDK9, as seen by calling `xprop | grep WM_CLASS`:

JDK8: WM_CLASS(STRING) = "sun-awt-X11-XFramePeer", "jedit"
JDK9: WM_CLASS(STRING) = "org-gjt-sp-jedit-jEdit", "org-gjt-sp-jedit-jEdit"

Setting that value in the first place was requested [here](https://sourceforge.net/p/jedit/feature-requests/290/). There does not seem to be any other way to set it. Throwing an exception on startup should be avoided.

Submitted will69 - 2016-03-29 12:25:21.793000 Assigned
Priority 5 Labels JDK9
Status open Group minor bug
Resolution None

Comments

2016-03-29 12:36:18.049000
will69

Since this is an expected behavior on JDK9, the startup exception should be eliminated by inserting

~~~~
if(!"java.lang.reflect.InaccessibleObjectException".equals(e.getClass().getName()))
~~~~

before the call to [Log.log](https://sourceforge.net/p/jedit/svn/HEAD/tree/jEdit/trunk/org/gjt/sp/jedit/jEdit.java#l166) or at least the log message should be clarified ("Cannot set X11 WM_CLASS to \"jedit\"").

2016-04-08 08:13:32.170000
will69

The exception can be eliminated by adding the following command line option on JDK9:
~~~~
-XaddExports:java.desktop/sun.awt.X11=ALL-UNNAMED
~~~~
This breaks the access-control boundaries defined by the module system. See also [JDK-8061972](https://bugs.openjdk.java.net/browse/JDK-8061972).

<tt>xprop | grep WM_CLASS</tt> then yields:

WM_CLASS(STRING) = "jedit", "jedit"

Thus, the above command line option should be added when running on JDK9.

2016-12-29 14:09:24.483000
will69

The syntax has been changed twice. First to
~~~
--add-exports=java.desktop/sun.awt.X11=ALL-UNNAMED
~~~
and now (around Java 9-ea+149) to
~~~
--add-opens=java.desktop/sun.awt.X11=ALL-UNNAMED
~~~