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

Hotspot failed to throw UnsupportedClassVersionError on the abnormal version

    XMLWordPrintable

    Details

    • Subcomponent:
    • CPU:
      generic
    • OS:
      generic

      Description

      ADDITIONAL SYSTEM INFORMATION :
      windows:
      Microsoft Windows 10
      10.0.19042 N/A Build 19042
      Intel(R) Core(TM) i5-8265U CPU @ 1.60GHz 1.80 GHz
      Memory 8.00 GB

      openjdk version "1.8.0_302"
      OpenJDK Runtime Environment (Temurin)(build 1.8.0_302-b08)
      OpenJDK 64-Bit Server VM (Temurin)(build 25.302-b08, mixed mode)

      openjdk version "11.0.11" 2021-04-20
      OpenJDK Runtime Environment AdoptOpenJDK-11.0.11+9 (build 11.0.11+9)
      OpenJDK 64-Bit Server VM AdoptOpenJDK-11.0.11+9 (build 11.0.11+9, mixed mode)


      A DESCRIPTION OF THE PROBLEM :
      Hotspot(1.8.0_302 ,11.0.11) failed to throw UnsupportedClassVersionError on the abnormal version. The simplified test program can be found below.

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      Just run the given test program.

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      UnsupportedClassVersionError
      ACTUAL -
      Version: 45 ClassFormatError
      Version: 46 ClassFormatError
      Version: 47 ClassFormatError
      Version: 48 ClassFormatError
      Version: 49 Test Pass
      Version: 50 Test Pass
      Version: 51 Test Pass
      Version: 52 Test Pass
      Version: 65581 ClassFormatError
      Version: 65582 ClassFormatError
      Version: 65583 ClassFormatError
      Version: 65584 ClassFormatError
      Version: 65585 Test Pass
      Version: 65586 Test Pass
      Version: 65587 Test Pass
      Version: 131117 ClassFormatError
      Version: 131118 ClassFormatError
      Version: 131119 ClassFormatError
      Version: 131120 ClassFormatError
      Version: 131121 Test Pass
      Version: 131122 Test Pass
      Version: 131123 Test Pass
      Version: 196653 ClassFormatError
      Version: 196654 ClassFormatError
      Version: 196655 ClassFormatError
      Version: 196656 ClassFormatError
      Version: 196657 Test Pass
      Version: 196658 Test Pass
      Version: 196659 Test Pass

      ---------- BEGIN SOURCE ----------
      import jdk.internal.org.objectweb.asm.ClassWriter;

      public class Test {

          public static void main(String[] var1) throws Throwable {

              for (int i = 0; i < 200000; i++){

                  try {
                      String name = "UM:}<u";
                      ClassWriter classWriter = new ClassWriter(0);
                      classWriter.visit(i, 1, name, (String)null, "java/lang/Object", (String[])null);
                      makeClassBytesLoader(classWriter.toByteArray(), name).loadClass(name);

                      System.err.println("Version: " + i + " " + "Test Pass");
                  } catch (Error e){

                      if (e.toString().contains("UnsupportedClassVersionError")){
      // System.err.println("Version: " + i + " " + "UnsupportedClassVersionError");
                      } else if (e.toString().contains("ClassFormatError")){
                          System.err.println("Version: " + i + " " + "ClassFormatError");
                      }
                  }
              }
          }

          public static ClassLoader makeClassBytesLoader(final byte[] classBytes, final String className) {
              return new ClassLoader() {
                  @Override
                  protected Class<?> loadClass(String name, boolean resolve) throws ClassNotFoundException {

                      if (!name.equals(className))
                          return super.loadClass(name, resolve);
                      return defineClass(className, classBytes, 0, classBytes.length);
                  }
              };
          }
      }
      ---------- END SOURCE ----------

        Attachments

          Activity

            People

            Assignee:
            hseigel Harold Seigel
            Reporter:
            webbuggrp Webbug Group
            Votes:
            0 Vote for this issue
            Watchers:
            5 Start watching this issue

              Dates

              Created:
              Updated:
              Resolved: