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

Class.forName behaviour is case-sensitive under Windows

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Open
    • Priority: P4
    • Resolution: Unresolved
    • Affects Version/s: 8u51, 9
    • Fix Version/s: tbd
    • Component/s: core-libs
    • Labels:
    • Subcomponent:
    • CPU:
      x86_64
    • OS:
      windows_7

      Description

      FULL PRODUCT VERSION :
      java version "1.8.0_51"
      Java(TM) SE Runtime Environment (build 1.8.0_51-b16)
      Java HotSpot(TM) 64-Bit Server VM (build 25.51-b03, mixed mode)

      ADDITIONAL OS VERSION INFORMATION :
      Windows 7 64-bit

      A DESCRIPTION OF THE PROBLEM :
      The documentation for method "forName" from java.lang.Class states the method will throw ClassNotFoundException if the class cannot be located.
      However, under Windows with a case-insensitive filesystem, the method may also throw the undocumented NoClassDefFoundError, in case the supplied classname differs only by case from an existing class.
      This is annoying, as NoClassDefFoundError is an Error and therefore unlikely to be caught by anyone using Class.forName as documented.

      See the attached TestCase!

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      Execute the attached testclass.



      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      A ClassNotFoundException should be thrown.
      ACTUAL -
      A NoClassDefFoundError is being thrown.

      ERROR MESSAGES/STACK TRACES THAT OCCUR :
      Exception in thread "main" java.lang.NoClassDefFoundError: mcnepp/testclassloading (wrong
              at java.lang.ClassLoader.defineClass1(Native Method)
              at java.lang.ClassLoader.defineClass(ClassLoader.java:760)
              at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
              at java.net.URLClassLoader.defineClass(URLClassLoader.java:467)
              at java.net.URLClassLoader.access$100(URLClassLoader.java:73)
              at java.net.URLClassLoader$1.run(URLClassLoader.java:368)
              at java.net.URLClassLoader$1.run(URLClassLoader.java:362)
              at java.security.AccessController.doPrivileged(Native Method)
              at java.net.URLClassLoader.findClass(URLClassLoader.java:361)
              at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
              at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331)
              at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
              at java.lang.Class.forName0(Native Method)
              at java.lang.Class.forName(Class.java:264)
              at mcnepp.TestClassLoading.main(TestClassLoading.java:6)

      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------
      public class TestClassLoading {

      public static void main(String[] args) throws Exception {
      Class.forName(TestClassLoading.class.getName().toLowerCase());
      }
      }

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

        Attachments

          Activity

            People

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

              Dates

              Created:
              Updated: