java.lang.IllegalAccessException: Class FxSelectionModelIssue can not access a member of class javafx.scene.control.MultipleSelectionModelBase with modifiers "public"

JDK Bug System | Webbug Group | 2 months ago
  1. 0

    FULL PRODUCT VERSION : java version "1.8.0_101" Java(TM) SE Runtime Environment (build 1.8.0_101-b13) Java HotSpot(TM) 64-Bit Server VM (build 25.101-b13, mixed mode) ADDITIONAL OS VERSION INFORMATION : Microsoft Windows [Version 6.1.7601] EXTRA RELEVANT SYSTEM CONFIGURATION : I've tried it on Linux also with the same results. A DESCRIPTION OF THE PROBLEM : In trying to auto select a javafx.scene.control.SelectionModel index, direct manipulation calling the select function directly works fine. However, if trying to access the select function via reflection, an exception is thrown. STEPS TO FOLLOW TO REPRODUCE THE PROBLEM : Save the code below in a file called FxSelectionModelIssue.java. Compile it: javac FxSelectionModelIssue.java Run it: java FxSelectionModelIssue 1 // works Run it: java FxSelectionModelIssue 2 // fails EXPECTED VERSUS ACTUAL BEHAVIOR : EXPECTED - Running the enclosed program will bring up a ListView window with a button at the bottom. Initially, the first item is highlighted/selected. Pressing the "next" button at the bottom of the ListView will increment the selected ListView Item. This works fine when providing the command line option 1. When providing command line option 2, the expected behavior should be the same as using option 1. ACTUAL - When using command line option 2, The application starts with an exception being thrown. ERROR MESSAGES/STACK TRACES THAT OCCUR : java.lang.IllegalAccessException: Class FxSelectionModelIssue can not access a member of class javafx.scene.control.MultipleSelectionModelBase with modifiers "public" at sun.reflect.Reflection.ensureMemberAccess(Reflection.java:102) at java.lang.reflect.AccessibleObject.slowCheckMemberAccess(AccessibleObject.java:296) at java.lang.reflect.AccessibleObject.checkAccess(AccessibleObject.java:288) at java.lang.reflect.Method.invoke(Method.java:491) at FxSelectionModelIssue.selectIndirect(FxSelectionModelIssue.java:84) at FxSelectionModelIssue.start(FxSelectionModelIssue.java:60) at com.sun.javafx.application.LauncherImpl.lambda$launchApplication1$162(LauncherImpl.java:863) at com.sun.javafx.application.PlatformImpl.lambda$runAndWait$175(PlatformImpl.java:326) at com.sun.javafx.application.PlatformImpl.lambda$null$173(PlatformImpl.java:295) at java.security.AccessController.doPrivileged(Native Method) at com.sun.javafx.application.PlatformImpl.lambda$runLater$174(PlatformImpl.java:294) at com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java:95) at com.sun.glass.ui.win.WinApplication._runLoop(Native Method) at com.sun.glass.ui.win.WinApplication.lambda$null$148(WinApplication.java:191) at java.lang.Thread.run(Thread.java:745) REPRODUCIBILITY : This bug can be reproduced always. ---------- BEGIN SOURCE ---------- /* compile: javac FxSelectionModelIssue.java usage: java FxSelectionModelIssue 1 // calls select directly usage: java FxSelectionModelIssue 2 // calls select indirectly via reflection */ public class FxSelectionModelIssue extends javafx.application.Application { public void start(javafx.stage.Stage stage) { String usage = "java FxSelectViaIntrospection 1|2"; java.util.List<String> listParm = getParameters().getRaw(); if (listParm.size() != 1) { System.err.println(usage); System.exit(1); } String call = listParm.get(0).intern(); if (call != "1" && call != "2") { System.err.println(usage); System.exit(1); } javafx.scene.control.ListView ListView = new javafx.scene.control.ListView(); javafx.scene.control.MultipleSelectionModel msm = ListView.getSelectionModel(); msm.setSelectionMode(javafx.scene.control.SelectionMode.SINGLE); javafx.scene.control.Button Button = new javafx.scene.control.Button(); Button.setText("next"); Button.setUserData(ListView); Button.setOnAction( event -> { javafx.scene.control.Button b = (javafx.scene.control.Button)event.getSource(); javafx.scene.control.ListView lv = (javafx.scene.control.ListView)b.getUserData(); javafx.scene.control.SelectionModel sm = lv.getSelectionModel(); int i = sm.getSelectedIndex(); int size = lv.getItems().size(); i = (i < size - 1) ? i + 1 : 0; if (call == "1") { selectDirect(sm, i); // works } else if (call == "2") { selectIndirect(sm, i); // fails } System.err.println(sm.getSelectedIndex()+" => "+sm.getSelectedItem()); } ); ListView.getItems().add("a"); ListView.getItems().add("b"); ListView.getItems().add("c"); ListView.getItems().add("d"); ListView.getItems().add("e"); if (call == "1") { selectDirect(msm, 0); // works } else if (call == "2") { selectIndirect(msm, 0); // fails } javafx.scene.layout.VBox vbox = new javafx.scene.layout.VBox(); vbox.getChildren().add(ListView); vbox.getChildren().add(Button); javafx.scene.Scene scene = new javafx.scene.Scene(vbox); stage.setScene(scene); stage.show(); } // works private void selectDirect(javafx.scene.control.SelectionModel sm, int i) { sm.select(i); } // The following exception is thrown upon invoke call: // java.lang.IllegalAccessException: Class FxSelectViaIntrospection can not access a member of class javafx.scene.control.MultipleSelectionModelBase with modifiers "public" // fails private void selectIndirect(javafx.scene.control.SelectionModel sm, int i) { try { java.lang.reflect.Method m = sm.getClass().getMethod("select", int.class); m.invoke(sm, i); } catch (Exception e) { e.printStackTrace(); } } } ---------- END SOURCE ----------

    JDK Bug System | 2 months ago | Webbug Group
    java.lang.IllegalAccessException: Class FxSelectionModelIssue can not access a member of class javafx.scene.control.MultipleSelectionModelBase with modifiers "public"
  2. 0

    FULL PRODUCT VERSION : java version "1.8.0_74" Java(TM) SE Runtime Environment (build 1.8.0_74-b02) Java HotSpot(TM) 64-Bit Server VM (build 25.74-b02, mixed mode) ADDITIONAL OS VERSION INFORMATION : Microsoft Windows [Version 6.1.7601] A DESCRIPTION OF THE PROBLEM : The goal is to perform the functionality in iterator0() using introspection, found in iterator1(). iterator0() loads a HashMap and iterates through it's content. Using introspection, attempted in iterator1(), an java.lang.IllegalAccessException is thrown when trying to access the iterator via HashMap's keySet(). iterator2() shows the work-a-round implying HashMap and related classes and Interfaces requires rearchitecting allowing the iterator to be reflected/introspected. All this is moot if the intended design was to prevent iterator reflection, however there's nothing in the documentation. STEPS TO FOLLOW TO REPRODUCE THE PROBLEM : Save the code below in a file called: ReflectBug.java compile: javac ReflectBug.java run: java ReflectBug EXPECTED VERSUS ACTUAL BEHAVIOR : EXPECTED - Three methods are executed. Each do the same thing but get there three different ways. The desired method is iterator1() which failes. iterator0() shows what would like to be done. iterator2() is the work-a-round. Expected output from the program: # iterator0 # iterator0 # iterator0 map={A=B, B=C} A=B B=C # iterator1 # iterator1 # iterator1 map={A=B, B=C} A=B B=C # iterator2 # iterator2 # iterator2 map={A=B, B=C} A=B B=C ACTUAL - # iterator0 # iterator0 # iterator0 map={A=B, B=C} A=B B=C # iterator1 # iterator1 # iterator1 map={A=B, B=C} java.lang.IllegalAccessException: Class ReflectBug can not access a member of class java.util.HashMap$KeySet with modifiers "public final" at sun.reflect.Reflection.ensureMemberAccess(Reflection.java:102) at java.lang.reflect.AccessibleObject.slowCheckMemberAccess(AccessibleObject.java:296) at java.lang.reflect.AccessibleObject.checkAccess(AccessibleObject.java:288) at java.lang.reflect.Method.invoke(Method.java:491) at ReflectBug.iterator1(ReflectBug.java:74) at ReflectBug.main(ReflectBug.java:28) # iterator2 # iterator2 # iterator2 map={A=B, B=C} A=B B=C ERROR MESSAGES/STACK TRACES THAT OCCUR : java.lang.IllegalAccessException: Class ReflectBug can not access a member of class java.util.HashMap$KeySet with modifiers "public final" at sun.reflect.Reflection.ensureMemberAccess(Reflection.java:102) at java.lang.reflect.AccessibleObject.slowCheckMemberAccess(AccessibleObject.java:296) at java.lang.reflect.AccessibleObject.checkAccess(AccessibleObject.java:288) at java.lang.reflect.Method.invoke(Method.java:491) at ReflectBug.iterator1(ReflectBug.java:74) at ReflectBug.main(ReflectBug.java:28) REPRODUCIBILITY : This bug can be reproduced always. ---------- BEGIN SOURCE ---------- public class ReflectBug { public static void main(String[] args) throws Exception { java.util.Map<String,String> map = new java.util.HashMap<>(); map.put("A", "B"); map.put("B", "C"); try { iterator0(map); } catch (Exception e) { e.printStackTrace(); } try { iterator1(map); } catch (Exception e) { e.printStackTrace(); } try { iterator2(map); } catch (Exception e) { e.printStackTrace(); } } // iterator0() implements functionality desired via introspection public static void iterator0(java.util.Map map) { System.err.println(); System.err.println("# iterator0"); System.err.println("# iterator0"); System.err.println("# iterator0"); System.err.println("map="+map); java.util.Set s = map.keySet(); java.util.Iterator i = s.iterator(); Object key; Object value; while (i.hasNext()) { key = i.next(); value = map.get(key); System.err.println(key+"="+value); } } // iterator1() is an attempt at iterator0() functionality via introspection. // The code below is commented where an IllegalAccessException is thrown. public static void iterator1(java.util.Map map) throws Exception { System.err.println(); System.err.println("# iterator1"); System.err.println("# iterator1"); System.err.println("# iterator1"); System.err.println("map="+map); Class<?> mapClass = map.getClass(); java.lang.reflect.Method keySetMethod = mapClass.getMethod("keySet"); java.util.Set keySet = (java.util.Set)keySetMethod.invoke(map); Class<?> keySetClass = keySet.getClass(); java.lang.reflect.Method iteratorMethod = keySetClass.getMethod("iterator"); /* The following code fails with: java.lang.IllegalAccessException: Class IterateBug can not access a member of class java.util.HashMap$KeySet with modifiers "public final" */ java.util.Iterator iterator = (java.util.Iterator)iteratorMethod.invoke(keySet); Class<?> iteratorClass = iterator.getClass(); java.lang.reflect.Method hasNextMethod = iteratorClass.getMethod("hasNext"); java.lang.reflect.Method nextMethod = iteratorClass.getMethod("next"); boolean hasNext = (boolean)hasNextMethod.invoke(iterator); java.lang.reflect.Method getMethod = mapClass.getMethod("get", Object.class); Object key; Object value; while (hasNext) { key = nextMethod.invoke(iterator); value = getMethod.invoke(map, key); System.err.println(key+"="+value); } } // iterator2() is a work around. public static void iterator2(java.util.Map map) throws Exception { System.err.println(); System.err.println("# iterator2"); System.err.println("# iterator2"); System.err.println("# iterator2"); System.err.println("map="+map); Class<?> mapClass = map.getClass(); java.lang.reflect.Method getMethod = mapClass.getMethod("get", Object.class); java.lang.reflect.Method keySetMethod = mapClass.getMethod("keySet"); java.util.Set set = (java.util.Set)keySetMethod.invoke(map); Class<?> setClass = set.getClass(); java.lang.reflect.Method toArrayMethod = setClass.getMethod("toArray"); Object[] array = (Object[])toArrayMethod.invoke(set); ReflectBugIterator rbi = new ReflectBugIterator(); Class<?> ReflectBugIteratorClass = rbi.getClass(); java.lang.reflect.Method setArrayMethod = ReflectBugIteratorClass.getMethod("setArray", Object[].class); setArrayMethod.invoke(rbi, new Object[]{array}); java.lang.reflect.Method hasNextMethod = ReflectBugIteratorClass.getMethod("hasNext"); java.lang.reflect.Method nextMethod = ReflectBugIteratorClass.getMethod("next"); Object key; Object value; while ((boolean)hasNextMethod.invoke(rbi)) { // key = i.next(); key = nextMethod.invoke(rbi); // value = map.get(key); value = getMethod.invoke(map, key); System.err.println(key+"="+value); } } } class ReflectBugIterator { private int index; private Object[] array; public void setArray(Object[] o) { array = o; } public void reset() { index = 0; } public boolean hasNext() { return index < array.length; } public Object next() { return array[index++]; } } ---------- END SOURCE ---------- CUSTOMER SUBMITTED WORKAROUND : iterator2() is the work-a-round for this issue.

    JDK Bug System | 8 months ago | Webbug Group
    java.lang.IllegalAccessException: Class ReflectBug can not access a member of class java.util.HashMap$KeySet with modifiers "public final"
  3. 0

    FULL PRODUCT VERSION : java version "1.8.0_101" Java(TM) SE Runtime Environment (build 1.8.0_101-b13) Java HotSpot(TM) 64-Bit Server VM (build 25.101-b13, mixed mode) ADDITIONAL OS VERSION INFORMATION : Microsoft Windows [Version 6.1.7601] A DESCRIPTION OF THE PROBLEM : Trying to reflect on the iterator.hasNext(), a java.lang.IllegalAccessException is thrown the Inner Class. See Related Review ID: JI-9044075 for a similar example. REGRESSION. Last worked in version 8u101 STEPS TO FOLLOW TO REPRODUCE THE PROBLEM : Save the Source Code in a file called: InnerClassIssue.java Compile it: javac InnerClassIssue.java Run it: java InnerClassIssue EXPECTED VERSUS ACTUAL BEHAVIOR : EXPECTED - The program should print the letters a-e on separate lines several times. Each time a different way of printing the letters is used. In total, the letters a-e should be printed 6 times prefixed by "way x" where x is 1, 2 or 3, referencing the print and access method used. ACTUAL - The program prints the letters a - e on separate lines using different ways. The List and Set interfaces are used as examples. The List is created. a-e is loaded into the list and then the list is printed using the list.iterator() hasNext() and next() methods directly (works as expected). Then the iterator is gotten via introspection and printed using the list.iterator() hasNext() and next() methods directly (works as expected). Then the iterator is gotten and printed using reflection on the iterator's hasNext() and next() methods (fails with exception). I would expect this last attempt to behave just like the first two. The Set is used as a second example and results in similar behavior. ERROR MESSAGES/STACK TRACES THAT OCCUR : way 1: a b c d e way 2: a b c d e java.lang.IllegalAccessException: Class InnerClassIssue can not access a member of class java.util.ArrayList$Itr with modifiers "public" at sun.reflect.Reflection.ensureMemberAccess(Reflection.java:102) at java.lang.reflect.AccessibleObject.slowCheckMemberAccess(AccessibleObject.java:296) at java.lang.reflect.AccessibleObject.checkAccess(AccessibleObject.java:288) at java.lang.reflect.Method.invoke(Method.java:491) at InnerClassIssue.toStringI11n(InnerClassIssue.java:123) at InnerClassIssue.toString3(InnerClassIssue.java:72) at InnerClassIssue.main(InnerClassIssue.java:30) way 1: a b c d e way 2: a b c d e java.lang.IllegalAccessException: Class InnerClassIssue can not access a member of class java.util.TreeMap$PrivateEntryIterator with modifiers "public final" at sun.reflect.Reflection.ensureMemberAccess(Reflection.java:102) at java.lang.reflect.AccessibleObject.slowCheckMemberAccess(AccessibleObject.java:296) at java.lang.reflect.AccessibleObject.checkAccess(AccessibleObject.java:288) at java.lang.reflect.Method.invoke(Method.java:491) at InnerClassIssue.toStringI11n(InnerClassIssue.java:123) at InnerClassIssue.toString3(InnerClassIssue.java:95) at InnerClassIssue.main(InnerClassIssue.java:44) REPRODUCIBILITY : This bug can be reproduced always. ---------- BEGIN SOURCE ---------- public class InnerClassIssue { public static void main(String[] args) throws Exception { try { java.util.List<String> list = new java.util.ArrayList<>(); list.add("a"); list.add("b"); list.add("c"); list.add("d"); list.add("e"); System.err.println("way 1:\n"+toString1(list)); System.err.println("way 2:\n"+toString2(list)); System.err.println("way 3:\n"+toString3(list)); } catch (Exception e) { e.printStackTrace(); } try { java.util.Set<String> set = new java.util.TreeSet<>(); set.add("a"); set.add("b"); set.add("c"); set.add("d"); set.add("e"); System.err.println("way 1:\n"+toString1(set)); System.err.println("way 2:\n"+toString2(set)); System.err.println("way 3:\n"+toString3(set)); } catch (Exception e) { e.printStackTrace(); } } // Introspection: I11n // // toString: list // // toString1: NoI11n used private static String toString1(java.util.List<String> list) { return toStringNoI11n(list.iterator()); } // toString2: Use I11n on set.iterator() private static String toString2(java.util.List<String> list) throws Exception { java.lang.reflect.Method m = list.getClass() .getMethod("iterator"); return toStringNoI11n((java.util.Iterator)m.invoke(list)); } // toString3: Use I11n on iterator.hasNext() and iterator.next() private static String toString3(java.util.List<String> list) throws Exception { return toStringI11n(list.iterator()); } // // toString: set // // toString1: NoI11n used private static String toString1(java.util.Set<String> set) { return toStringNoI11n(set.iterator()); } // toString2: Use I11n on set.iterator() private static String toString2(java.util.Set<String> set) throws Exception { java.lang.reflect.Method m = set.getClass() .getMethod("iterator"); return toStringNoI11n((java.util.Iterator)m.invoke(set)); } // toString3: Use I11n on iterator.hasNext() and iterator.next() private static String toString3(java.util.Set<String> set) throws Exception { return toStringI11n(set.iterator()); } // // toString: itarator // // toStringNoI11n: NoI11n used private static String toStringNoI11n(java.util.Iterator<String> i) { StringBuilder sb = new StringBuilder(); if (i.hasNext()) { sb.append(i.next()); while (i.hasNext()) { sb.append("\n"); sb.append(i.next()); } } return sb.toString(); } // toStringI11n: Use I11n on iterator.hasNext() and iterator.next() private static String toStringI11n(java.util.Iterator<String> i) throws Exception { StringBuilder sb = new StringBuilder(); java.lang.reflect.Method mhn = i.getClass().getMethod("hasNext"); java.lang.reflect.Method mn = i.getClass().getMethod("next"); // fails on first invoke // java.lang.IllegalAccessException: Class InnerClassIssue can not access a member of class java.util.TreeMap$PrivateEntryIterator with modifiers "public final" if ((boolean)mhn.invoke(i)) { sb.append(mn.invoke(i)); while ((boolean)mhn.invoke(i)) { sb.append("\n"); sb.append(mn.invoke(i)); } } return sb.toString(); } } ---------- END SOURCE ---------- CUSTOMER SUBMITTED WORKAROUND : The toArray() method can be used in both the List and Set case but this defeats the purpose of having an iterator in the first place. Without seeing the code, it seems that Inner classes need to be removed from any class their contained in. Since Java is suppose to be object oriented and reusable, hiding a class within a class inherently defeats this feature. As can be seen in this example, an Iterator is a fundamental construct yet can not be reflected upon which it clearly should be. If inner classes aren't used, the code should collapse since the inner class will now be reusable (and this bug should go away). Just because you can do something doesn't mean you should do it. That something in this case is embed a class in a class. It introduces more problems than it solves, this bug for example. By allowing the end user to cut corners and create inner classes, they too are introducing this same bug and nonreusability. In short, this feature needs to be redesigned and inner classes removed.

    JDK Bug System | 2 months ago | Webbug Group
    java.lang.IllegalAccessException: Class InnerClassIssue can not access a member of class java.util.ArrayList$Itr with modifiers "public"
  4. Speed up your debug routine!

    Automated exception search integrated into your IDE

  5. 0

    cannot decorate inner class

    GitHub | 2 months ago | maciejmikosik
    java.lang.IllegalAccessException: Class org.logbuddy.decorator.LoggingDecorator$DecorateHandler can not access a member of class Bug$2 with modifiers "public"
  6. 0

    IllegalAccessException on multiple invocations

    GitHub | 2 years ago | jimbru
    java.lang.IllegalAccessException: Class org.flatland.drip.Main can not access a member of class HelloWorld with modifiers "public static"

    7 unregistered visitors
    Not finding the right solution?
    Take a tour to get the most out of Samebug.

    Tired of useless tips?

    Automated exception search integrated into your IDE

    Root Cause Analysis

    1. java.lang.IllegalAccessException

      Class FxSelectionModelIssue can not access a member of class javafx.scene.control.MultipleSelectionModelBase with modifiers "public"

      at sun.reflect.Reflection.ensureMemberAccess()
    2. Java RT
      Method.invoke
      1. sun.reflect.Reflection.ensureMemberAccess(Reflection.java:102)
      2. java.lang.reflect.AccessibleObject.slowCheckMemberAccess(AccessibleObject.java:296)
      3. java.lang.reflect.AccessibleObject.checkAccess(AccessibleObject.java:288)
      4. java.lang.reflect.Method.invoke(Method.java:491)
      4 frames
    3. Unknown
      FxSelectionModelIssue.start
      1. FxSelectionModelIssue.selectIndirect(FxSelectionModelIssue.java:84)
      2. FxSelectionModelIssue.start(FxSelectionModelIssue.java:60)
      2 frames
    4. com.sun.javafx
      PlatformImpl.lambda$null$173
      1. com.sun.javafx.application.LauncherImpl.lambda$launchApplication1$162(LauncherImpl.java:863)
      2. com.sun.javafx.application.PlatformImpl.lambda$runAndWait$175(PlatformImpl.java:326)
      3. com.sun.javafx.application.PlatformImpl.lambda$null$173(PlatformImpl.java:295)
      3 frames
    5. Java RT
      AccessController.doPrivileged
      1. java.security.AccessController.doPrivileged(Native Method)
      1 frame
    6. com.sun.javafx
      PlatformImpl.lambda$runLater$174
      1. com.sun.javafx.application.PlatformImpl.lambda$runLater$174(PlatformImpl.java:294)
      1 frame
    7. com.sun.glass
      WinApplication.lambda$null$148
      1. com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java:95)
      2. com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
      3. com.sun.glass.ui.win.WinApplication.lambda$null$148(WinApplication.java:191)
      3 frames
    8. Java RT
      Thread.run
      1. java.lang.Thread.run(Thread.java:745)
      1 frame