-
Notifications
You must be signed in to change notification settings - Fork 61
Description
Hi,
I’ve encountered a platform-specific issue using SystemTray on Windows 11 with Java 21. The setEnabled() method works correctly on Linux, but not on Windows.
❗ Problem
On Windows, after calling SystemTray.setEnabled(false), the tray icon disappears as expected. However, calling setEnabled(true) does not bring it back. Instead, it results in a NullPointerException being thrown from inside NOTIFYICONDATA.setTooltip().
This issue does not occur on Linux(Manjaro KDE), where toggling enabled/disabled works fine.
🖥️ System Info
OS: Windows 11 (64-bit)
Java Version: Java 21
SystemTray Version: 4.4
🔁 Steps to Reproduce
Here’s the minimal code to reproduce the issue:
import com.dorkbox.systemTray.SystemTray;
import java.util.Timer;
import java.util.TimerTask;
public class TrayBugDemo {
public static void main(String[] args) {
testTray();
}
public static void testTray() {
SystemTray.DEBUG = true;
SystemTray tray = SystemTray.get();
System.err.println("System tray is working");
tray.setImage("C:/Users/Tackle/icon.png"); // Full absolute path
tray.setStatus("Tray Icon Test");
new Timer().schedule(new TimerTask() {
private boolean testEnable = true;
@Override
public void run() {
System.out.println("Trying Set enable to "+testEnable);
tray.setEnabled(testEnable);
System.out.println("Successfully Set enable to "+testEnable);
testEnable = !testEnable;
}
}, 5000, 1000);
System.out.println("Tray icon should now be visible.");
}
}
🧨 Debug Log & Exception Stack Trace
System tray is working
Tray icon should now be visible.
Trying Set enable to true
Successfully Set enable to true
Trying Set enable to false
Successfully Set enable to false
Trying Set enable to true
Exception in thread "Timer-0" java.lang.NullPointerException: Cannot invoke "String.toCharArray()" because "s" is null
at dorkbox.jna.windows.structs.NOTIFYICONDATA.setTooltip(NOTIFYICONDATA.java:70)
at dorkbox.systemTray.ui.swing._WindowsNativeTray.show(_WindowsNativeTray.java:278)
at dorkbox.systemTray.ui.swing._WindowsNativeTray.access$700(_WindowsNativeTray.java:61)
at dorkbox.systemTray.ui.swing._WindowsNativeTray$1.setEnabled(_WindowsNativeTray.java:138)
at dorkbox.systemTray.MenuItem.setEnabled(MenuItem.java:250)
at dorkbox.systemTray.SystemTray.setEnabled(SystemTray.java:940)
at com.apidech.averst.core.runtime.AverstMain$1.run(AverstMain.java:29)
at java.base/java.util.TimerThread.mainLoop(Timer.java:566)
at java.base/java.util.TimerThread.run(Timer.java:516)
✅ Expected Behavior
Calling tray.setEnabled(true) after setEnabled(false) should restore the tray icon without throwing an exception.
Please investigate whether this is a bug in how the tray icon is restored on Windows, or if some internal state is being cleared that shouldn’t be. Let me know if you'd like help testing a patch or workaround.
Thank you!