Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8210087

Classes in jdk.unsupported not accessible from jconsole plugin

    Details

    • Subcomponent:
    • Introduced In Version:
      9
    • Resolved In Build:
      b10
    • OS:
      generic

      Description

      ADDITIONAL SYSTEM INFORMATION :
      Observed on Windows and Mac OSX. Should occur on other platforms too.

      A DESCRIPTION OF THE PROBLEM :
      The plugin access to Unsafe and got java.lang.NoClassDefFoundError: sun/misc/Unsafe
      When run with jdk 11 outside jconsole launcher, the class is resolved.
      Even java -cp TestJConsoleJDK11.jar sun.tools.jconsole.JConsole works fine.

      REGRESSION : Last worked in version 10.0.2

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      Simplest plugin to access to unsafe in getTabs.


      ---------- BEGIN SOURCE ----------
      import com.sun.tools.jconsole.JConsolePlugin;
      import java.awt.BorderLayout;
      import java.lang.reflect.Field;
      import java.util.HashMap;
      import java.util.Map;
      import java.util.logging.Level;
      import java.util.logging.Logger;
      import javax.swing.JPanel;
      import javax.swing.SwingWorker;
      import sun.misc.Unsafe;

      /**
       *
       * @author jdenise@redhat.com
       */
      public class TestJConsoleJDK11 extends JConsolePlugin {

          /**
           * @param args the command line arguments
           */
          public static void main(String[] args) throws Exception {
              // TODO code application logic here
              System.out.println(getUnsafe().addressSize());
          }

          @Override
          public Map<String, JPanel> getTabs() {
              int size = -1;
              try {
                  size = getUnsafe().addressSize();
              } catch (IllegalArgumentException | IllegalAccessException | NoSuchFieldException ex) {
                  Logger.getLogger(TestJConsoleJDK11.class.getName()).log(Level.SEVERE, null, ex);
              }
              Map<String, JPanel> panelMap = new HashMap<String, JPanel>();
              JPanel jconsolePanel = new JPanel(new BorderLayout());
              panelMap.put("Test" + size, jconsolePanel);
              return panelMap;
          }

          @Override
          public SwingWorker<?, ?> newSwingWorker() {
              return null;
          }

          private static Unsafe getUnsafe() throws IllegalArgumentException, IllegalAccessException, NoSuchFieldException {
              Field f = Unsafe.class.getDeclaredField("theUnsafe");
              f.setAccessible(true);
              Unsafe unsafe = (Unsafe) f.get(null);
              return unsafe;
          }

      }

      ---------- END SOURCE ----------

      CUSTOMER SUBMITTED WORKAROUND :
      Add --add-modules=jdk.unsupported when launching jconsole.

      FREQUENCY : always


        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                alanb Alan Bateman
                Reporter:
                webbuggrp Webbug Group
              • Votes:
                0 Vote for this issue
                Watchers:
                3 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved: