Skip to content

Commit 969f927

Browse files
committed
Fix for reflection warnings for strongly encapsulated Desktop methods in Java > 9
1 parent 7393e2c commit 969f927

File tree

1 file changed

+14
-4
lines changed

1 file changed

+14
-4
lines changed

java/com/tigervnc/vncviewer/VncViewer.java

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -88,14 +88,24 @@ public class VncViewer implements Runnable {
8888
public static void setLookAndFeel() {
8989
try {
9090
if (os.startsWith("mac os x")) {
91-
Class appClass = Class.forName("com.apple.eawt.Application");
91+
String appClassName = new String("com.apple.eawt.Application");
92+
String appMethodName = new String("getApplication");
93+
String setIconMethodName = new String("setDockIconImage");
94+
// JEP-272. Platform-specific Desktop Features are strongly encapsulated
95+
// in JRE 9 & above, but the API features needed aren't in JRE 8.
96+
if (Float.parseFloat(System.getProperty("java.specification.version")) > 1.8) {
97+
appClassName = new String("java.awt.Taskbar");
98+
appMethodName = new String("getTaskbar");
99+
setIconMethodName = new String("setIconImage");
100+
}
101+
Class appClass = Class.forName(appClassName);
92102
Method getApplication =
93-
appClass.getMethod("getApplication", (Class[])null);
103+
appClass.getMethod(appMethodName, (Class[])null);
94104
Object app = getApplication.invoke(appClass);
95105
Class paramTypes[] = new Class[1];
96106
paramTypes[0] = Image.class;
97-
Method setDockIconImage =
98-
appClass.getMethod("setDockIconImage", paramTypes);
107+
Method setDockIconImage =
108+
appClass.getMethod(setIconMethodName, paramTypes);
99109
setDockIconImage.invoke(app, VncViewer.logoImage);
100110
}
101111
// Use Nimbus LookAndFeel if it's available, otherwise fallback

0 commit comments

Comments
 (0)