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

Implicit class load failed when explicit class load succeeded

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Resolved
    • Priority: P3
    • Resolution: Not an Issue
    • Affects Version/s: 8u11
    • Fix Version/s: 9
    • Component/s: hotspot
    • Subcomponent:
    • CPU:
      x86
    • OS:
      windows_7

      Description

      FULL PRODUCT VERSION :


      A DESCRIPTION OF THE PROBLEM :
      If first implicit class load failed, the next implicit class loads will continue to fail,even when explicit class load can succeed.

      The problem is in JDK6/JDK7/JDK8, but not in JDK5.

      THE PROBLEM WAS REPRODUCIBLE WITH -Xint FLAG: Yes

      THE PROBLEM WAS REPRODUCIBLE WITH -server FLAG: Yes

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      Run test case.

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      +++++++++++++++++++ Expected and in JDK5 +++++++++++++++++++
      ==============testImplicitClassLoad=====================
      implicit class load failed. java.lang.NoClassDefFoundError: test/A
      ==============testImplicitClassLoad=====================
      B
      ==============testImplicitClassLoad=====================
      B
      ==============testExplicitClassLoad=====================
      test.B loaded...class test.B
      test.A loaded...class test.A

      ++++++++++++++++++++++++++++++++++++++++++++++++++

      +++++++++++++++++++++ In JDK7 +++++++++++++++++++++++

      ==============testImplicitClassLoad=====================
      implicit class load failed. java.lang.NoClassDefFoundError: test/A
      ==============testImplicitClassLoad=====================
      implicit class load failed. java.lang.NoClassDefFoundError: test/B
      ==============testImplicitClassLoad=====================
      implicit class load failed. java.lang.NoClassDefFoundError: test/B
      ==============testExplicitClassLoad=====================
      test.B loaded...class test.B
      test.A loaded...class test.A

      ++++++++++++++++++++++++++++++++++++++++++++++++++

      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------
      package test;

      public class A {
      public void print() {
      System.out.println("A");
      }
      }
      ========================================
      package test;

      public class B extends A{
      @Override
      public void print() {
      System.out.println("B");
      }
      }
      ========================================
      package test;

      public class C {
      public void print() {
      new B().print();
      }
      }
      =========================================
      package test;

      import java.lang.reflect.Method;
      import java.net.URL;
      import java.net.URLClassLoader;
      import java.util.concurrent.atomic.AtomicInteger;

      public class Test {

      public static void main(String[] args) throws Exception {

      MyClassLoader myClassLoader = new MyClassLoader();

      Class cClass = myClassLoader.loadClass("test.C");
      Object cObject = cClass.newInstance();
      Method printMethod = cClass.getMethod("print");

      testImplicitClassLoad(cObject, printMethod);

      testExplicitClassLoad(myClassLoader);
      }

      private static void testImplicitClassLoad(Object cObject, Method printMethod) {
      for (int i = 0; i < 3; i++) {
      System.out.println("==============testImplicitClassLoad=====================");
      try {
      printMethod.invoke(cObject);
      } catch (Exception e) {
      System.out.println("implicit class load failed. " + e.getCause());
      }
      }
      }

      private static void testExplicitClassLoad(ClassLoader classLoader) throws ClassNotFoundException {
      System.out.println("==============testExplicitClassLoad=====================");
      System.out.println("test.B loaded..." + classLoader.loadClass("test.B"));
      System.out.println("test.A loaded..." + classLoader.loadClass("test.A"));
      }
      }

      class MyClassLoader extends URLClassLoader {

      private AtomicInteger count = new AtomicInteger(0);

      public MyClassLoader() {
      super(getMyURLs(), null);
      }

      private static URL[] getMyURLs() {
      URL[] urls = {Thread.currentThread().getContextClassLoader().getResource("")};
      return urls;
      }

      @Override
      protected Class<?> loadClass(String name, boolean resolve)
      throws ClassNotFoundException {
      //System.out.println(name);

      if (name.contains("A") && count.getAndIncrement() == 0)
      {
      throw new ClassNotFoundException("A");
      }

      return super.loadClass(name, resolve);
      }
      }


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

        Attachments

          Activity

            People

            Assignee:
            Unassigned Unassigned
            Reporter:
            webbuggrp Webbug Group
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Dates

              Created:
              Updated:
              Resolved: