Menu

#3971 Exception trying to set X11 WM_CLASS in JDK9 on Linux

minor bug
closed-fixed
JDK9 (2)
5
2017-10-05
2016-03-29
will69
No

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. 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. There does not seem to be any other way to set it. Throwing an exception on startup should be avoided.

Discussion

  • will69

    will69 - 2016-03-29

    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 (sourceforge.net) or at least the log message should be clarified ("Cannot set X11 WM_CLASS to \"jedit\"").

     
  • will69

    will69 - 2016-04-08

    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.

    xprop | grep WM_CLASS then yields:

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

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

     
  • will69

    will69 - 2016-12-29

    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
    
     
  • Dale Anson

    Dale Anson - 2017-10-03

    Now that Java 9 is out, is your last comment still valid? Has anything else changed?

     
  • Dale Anson

    Dale Anson - 2017-10-05

    I've looked into this some more, I get this message when starting jEdit with Java 9 (OpenJDK build 9+181):

    WARNING: An illegal reflective access operation has occurred
    WARNING: Illegal reflective access by org.gjt.sp.jedit.jEdit (file:/home/danson/apps/jedit/current/jedit.jar) to field sun.awt.X11.XToolkit.awtAppClassName
    WARNING: Please consider reporting this to the maintainers of org.gjt.sp.jedit.jEdit
    WARNING: Use --illegal-access=warn to enable warnings of further illegal reflective access operations
    WARNING: All illegal access operations will be denied in a future release

    The OpenJDK mailing list suggests adding

    Add-Opens: java.desktop/sun.awt

    to the jar manifest. Doing so, and adjusting the jEdit code to not call the illegal access eliminates the message above, but then there is this:

    WARNING: An illegal reflective access operation has occurred
    WARNING: Illegal reflective access by org.gjt.sp.jedit.gui.BufferSwitcher (file:/home/danson/apps/jedit/current/jedit.jar) to field javax.swing.plaf.basic.BasicComboBoxUI.listBox
    WARNING: Please consider reporting this to the maintainers of org.gjt.sp.jedit.gui.BufferSwitcher
    WARNING: Use --illegal-access=warn to enable warnings of further illegal reflective access operations
    WARNING: All illegal access operations will be denied in a future release

    I'll continue to look into this.

     
  • Dale Anson

    Dale Anson - 2017-10-05
    • assigned_to: Dale Anson
     
  • Dale Anson

    Dale Anson - 2017-10-05
    • status: open --> closed-fixed
     
  • Dale Anson

    Dale Anson - 2017-10-05

    Fixed in revision 24747. The fix checks the java version and does not execute the code that sets the WM_CLASS if Java 9 and adds the "Add-Opens" line to the manifest file. Tested with both Java 8 and 9. I'll open another ticket for the second warning since it's really a separate issue.

     

Log in to post a comment.