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

HotSpot ClassLoader does not throw appropriate exception with circular classes

XMLWordPrintable

    • generic
    • generic

      ADDITIONAL SYSTEM INFORMATION :
      Darwin 21.4.0 Darwin Kernel Version 21.4.0: Fri Mar 18 00:45:05 PDT 2022; root:xnu-8020.101.4~15/RELEASE_X86_64 x86_64
      javac 17.0.3
      java version "17.0.3" 2022-04-19 LTS
      Java(TM) SE Runtime Environment (build 17.0.3+8-LTS-111)
      Java HotSpot(TM) 64-Bit Server VM (build 17.0.3+8-LTS-111, mixed mode, sharing)


      A DESCRIPTION OF THE PROBLEM :
      According to https://openjdk.java.net/groups/hotspot/docs/RuntimeOverview.html

      "... If the class hierarchy has a problem such that this class is its own superclass or superinterface (recursively), then the VM will throw a ClassCircularityError."

      A test case of three classes with a circular inheritance shows that this does not work as documented.

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      javac circular/*.java
      java -cp circular Me
      java -cp circular Myself
      java -cp circular I

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      According to the documentation I was expecting a throw of java.lang.ClassCircularityError
      ACTUAL -
      $ javac circular/*.java
      $ java -cp circular I
      Error: Could not find or load main class I
      Caused by: java.lang.NoClassDefFoundError: circular/I (wrong name: I)

      $ java -cp circular Me
      Error: Could not find or load main class Me
      Caused by: java.lang.NoClassDefFoundError: circular/Me (wrong name: Me)

      $ java -cp circular Myself
      Error: Could not find or load main class Myself
      Caused by: java.lang.NoClassDefFoundError: circular/Myself (wrong name: Myself)

      ---------- BEGIN SOURCE ----------
      package circular;
      public class Me extends Myself {
      }

      package circular;
      public class Myself extends I {
      }

      package circular;
      public class I extends Me {
      }

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

      CUSTOMER SUBMITTED WORKAROUND :
      None identified

      FREQUENCY : always


            sswsharm swati sharma (Inactive)
            webbuggrp Webbug Group
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: