darklaf icon indicating copy to clipboard operation
darklaf copied to clipboard

[Bug] Exception when running on Windows Java 17

Open SiboVG opened this issue 1 year ago • 7 comments

Describe the bug When running my Java Swing application with Darkula on Windows on Java 17, I get an exception:

java.lang.IllegalAccessError: class com.github.weisj.darklaf.compatibility.SwingUtil (in unnamed module @0x562aec8) cannot access class sun.awt.SunToolkit (in module java.desktop) because module java.desktop does not export sun.awt to unnamed module @0x562aec8 at com.github.weisj.darklaf.compatibility.SwingUtil.grab(SwingUtil.java:109) at 
com.github.weisj.darklaf.ui.popupmenu.MouseGrabber.grabWindow(MouseGrabber.java:74) at 
com.github.weisj.darklaf.ui.popupmenu.MouseGrabber.stateChanged(MouseGrabber.java:112) at 
java.desktop/javax.swing.MenuSelectionManager.fireStateChanged(MenuSelectionManager.java:211) at 
java.desktop/javax.swing.MenuSelectionManager.setSelectedPath(MenuSelectionManager.java:138) at 
java.desktop/javax.swing.plaf.basic.BasicMenuUI$Handler.mousePressed(BasicMenuUI.java:519) at 
com.github.weisj.darklaf.delegate.MouseInputDelegate.mousePressed(MouseInputDelegate.java:81) at 
com.github.weisj.darklaf.ui.menu.DarkMenuUI$1.mousePressed(DarkMenuUI.java:83) at 
java.desktop/java.awt.Component.processMouseEvent(Component.java:6623) at 
java.desktop/javax.swing.JComponent.processMouseEvent(JComponent.java:3389) at 
java.desktop/java.awt.Component.processEvent(Component.java:6391) at 
java.desktop/java.awt.Container.processEvent(Container.java:2266) at 
java.desktop/java.awt.Component.dispatchEventImpl(Component.java:5001) at 
java.desktop/java.awt.Container.dispatchEventImpl(Container.java:2324) at 
java.desktop/java.awt.Component.dispatchEvent(Component.java:4833) at 
java.desktop/java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4948) at 
java.desktop/java.awt.LightweightDispatcher.processMouseEvent(Container.java:4572) at 
java.desktop/java.awt.LightweightDispatcher.dispatchEvent(Container.java:4516) at 
java.desktop/java.awt.Container.dispatchEventImpl(Container.java:2310) at 
java.desktop/java.awt.Window.dispatchEventImpl(Window.java:2780) at 
java.desktop/java.awt.Component.dispatchEvent(Component.java:4833) at 
java.desktop/java.awt.EventQueue.dispatchEventImpl(EventQueue.java:773) at 
java.desktop/java.awt.EventQueue$4.run(EventQueue.java:722) at java.desktop/java.awt.EventQueue$4.run(EventQueue.java:716) 
at java.base/java.security.AccessController.doPrivileged(AccessController.java:399) at 
java.base/java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:86) at 
java.base/java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:97) at 
java.desktop/java.awt.EventQueue$5.run(EventQueue.java:746) at java.desktop/java.awt.EventQueue$5.run(EventQueue.java:744) 
at java.base/java.security.AccessController.doPrivileged(AccessController.java:399) at 
java.base/java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:86) at 
java.desktop/java.awt.EventQueue.dispatchEvent(EventQueue.java:743) at 
java.desktop/java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:203) at 
java.desktop/java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:124) at 
java.desktop/java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:113) at 
java.desktop/java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:109) at 
java.desktop/java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:101) at 
java.desktop/java.awt.EventDispatchThread.run(EventDispatchThread.java:90)

To Reproduce Sorry, hard to say, the code is really embedded in my application... But I just installed the LAF with LafManager.install(new DarculaTheme());.

Screenshots

Additional Information:

  • OS: Windows
  • OS Version: 11 Pro Insider Preview (23430.1000)
  • Darklaf Version: 3.0.2
    • Note: If you are using the latest.integration version please try to replicate the issue with the latest stable release.

Additional context Works fine on my macOS machine (also Java 17). Running Windows on Parallels Desktop on my MacBook Pro M1.

SiboVG avatar Jul 02 '23 19:07 SiboVG

@weisJ if you want I can help out on this issue, but it would be nice to have some initial directions. Is this just a matter of bumping the codebase to be compatible with Java 17?

SiboVG avatar Jul 19 '23 14:07 SiboVG

Looks like the jdk.swing.interop.SwingInterOpUtils class isn’t found (though it should exists) https://github.com/weisJ/darklaf/blob/master/compatibility/src/main/java/com/github/weisj/darklaf/compatibility/SwingUtil.java

In theory the library is fully compatible with the module system (and Java 17 in particular)

weisJ avatar Jul 19 '23 14:07 weisJ

Running java --list-modules does show that my JRE has [email protected] (which should include jdk.swing.interop.SwingInterOpUtils). Trying to runClass.forName("jdk.swing.interop.SwingInterOpUtils") throws SwingInterOpUtils not available: java.lang.ClassNotFoundException: jdk.swing.interop.SwingInterOpUtils.

So I really don't know what the issue is... Any ideas?

SiboVG avatar Jul 22 '23 01:07 SiboVG

@weisJ if possible, it would probably be best to avoid sun.awt.Toolkit and jdk.swing.interop.SwingInterOpUtils entirely. Seems like it's gonna keep giving you headaches, especially if you'd like to support newer JDK's, where those internal APIs may eventually be removed completely... I may be wrong, but that's just my thoughts.

SiboVG avatar Jul 28 '23 21:07 SiboVG

Sadly it isn't possible to not use either. jdk.swing.interop.SwingInterOpUtils should be available from Java 11 and onwards. On versions before that sun.awt.SunToolkit has to be used instead. The classes are used to overwrite the default behaviour of menus being closed when interacted with the mouse in any way (including scrolling), which makes it impossible to provide scroll support for them. (There are some internal properties which would enable it but sadly they are checked by reference equality and the object for the property is internal too, so there is no way to obtain it).

Although Swing was designed to have a pluggable look and feel sadly only the "look" part is actually customisable with the "feel" being locked down to internal implementations.

weisJ avatar Nov 14 '23 14:11 weisJ

I have decided to drop support of Java 8 with the next version. The new minimum versions requirement will be Java 17. I don't find as much time as I used to for working on this project and keeping support for a large amount of versions was coming with lots of complications. This will hopefully resolve the issue and make the code easier to read 😅

weisJ avatar Nov 15 '23 15:11 weisJ

I have decided to drop support of Java 8 with the next version. The new minimum versions requirement will be Java 17. I don't find as much time as I used to for working on this project and keeping support for a large amount of versions was coming with lots of complications. This will hopefully resolve the issue and make the code easier to read 😅

IMO that's a very wise choice! Especially since macOS is really trying to bug everyone that uses old Java versions...

SiboVG avatar Nov 15 '23 15:11 SiboVG