2 Replies Latest reply on Sep 10, 2003 2:45 AM by jeanlazarou

    IllegalAccessError

    jeanlazarou

      I tried to instrument javax.swing.JPopupMenu and when I create an JPopupMenu instance, next Exception is thrown:
      > java.lang.IllegalAccessError: tried to access method > javax.swing.SwingUtilities.appContextGet
      > (Ljava/lang/Object;)Ljava/lang/Object;
      > from class javax.swing.JPopupMenu
      >
      > at javax.swing.JPopupMenu.
      > getDefaultLightWeightPopupEnabled
      > (JPopupMenu.java:140)
      >
      > at javax.swing.JPopupMenu.
      > (JPopupMenu.java:165)

      The code that modified the class (in a custom class loader) looks like:

      > CtClass cc = pool.get(name);
      > CtMethod m = cc.getDeclaredMethod(...);
      > m.insertBefore(...);
      > byte[] b = cc.toBytecode();
      > Class c = defineClass(name, b, 0, b.length);
      > return c;

      Can some help?

      Thanks,
      Jean

        • 1. Re: IllegalAccessError
          chiba

          Can you try an unmodified JPopupMenu?

          > CtClass cc = pool.get(name);
          > byte[] b = cc.toBytecode();
          > Class c = defineClass(name, b, 0, b.length);
          > return c;

          This simply loads JPopupMenu as is. If an exception
          is still thrown, the problem is because JPopupMenu
          is loaded by a class loader different from one loading
          javax.swing.SwingUtilities.appContextGet. This
          prohibits JPopupMenu from accessing package
          methods in SwingUtilities.

          Please read Section 4 of the tutorial.

          Chiba

          • 2. Re: IllegalAccessError
            jeanlazarou

            As is stated in javassist.Loader:

            /* The swing components must be loaded by a system
            * class loader.
            * javax.swing.UIManager loads a (concrete) subclass
            * of LookAndFeel by a system class loader and cast
            * an instance of the class to LookAndFeel for
            * (maybe) a security reason. To avoid failure of
            * type conversion, LookAndFeel must not be loaded
            * by this class loader.
            */

            I cannot do what I want...

            The only think I could do is instrument the compiled
            class and then use : java -Xbootclasspath

            Jean