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

Reflection fail (NoClassDefFoundError) when class name has international char.

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Duplicate
    • Icon: P4 P4
    • None
    • 1.4.0
    • core-libs



      Name: bsC130419 Date: 06/01/2001


      java version "1.4.0-beta"
      Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.0-beta-b65)
      Java HotSpot(TM) Client VM (build 1.4.0-beta-b65, mixed mode)

      When a class name contains international character (e.g. "Cl?",
      written "Cl\u00E9" below for portability), the compiler finds it but some
      reflection methods fail. Please compile and test the following program. The
      interface "Cl?" doesn't need to be in a separated file.



      import java.lang.reflect.Field;

      public class Test
      {
          public static void main(final String[] args) throws Exception
          {
              final Class classe = Cl\u00E9.class; // Success
              final Field field = classe.getField("ID"); // Success
              final int ID = field.getInt(null); // Fail
              System.out.println(ID);
          }
      }

      class Cl\u00E9
      {
          public static final int ID=12;
      }



      This program work as expected if we use plain class name (e.g. "Cle" instead
      of "Cl?"). With "Cl?", I get the following exception:


      Exception in thread "main" java.lang.NoClassDefFoundError: Cl? (wrong name: Cl?)
              at java.lang.ClassLoader.defineClass0(Native Method)
              at java.lang.ClassLoader.defineClass(ClassLoader.java:495)
              at java.security.SecureClassLoader.defineClass
      (SecureClassLoader.java:110)
              at java.net.URLClassLoader.defineClass(URLClassLoader.java:249)
              at java.net.URLClassLoader.access$100(URLClassLoader.java:57)
              at java.net.URLClassLoader$1.run(URLClassLoader.java:196)
              at java.security.AccessController.doPrivileged(Native Method)
              at java.net.URLClassLoader.findClass(URLClassLoader.java:189)
              at java.lang.ClassLoader.loadClass(ClassLoader.java:304)
              at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:287)
              at java.lang.ClassLoader.loadClass(ClassLoader.java:297)
              at java.lang.ClassLoader.loadClass(ClassLoader.java:260)
              at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:320)
              at sun.reflect.GeneratedFieldAccessor1.getInt(Unknown Source)
              at java.lang.reflect.Field.getInt(Field.java:312)
              at Test.main(Test.java:9)


      Looking in the exception message, we see that the lower-case "e" acute ("?")
      has been replaced by an upper-case "e" acute ("?") for no apparent raison.
      (Review ID: 125239)
      ======================================================================

            iris Iris Clark
            bstrathesunw Bill Strathearn (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: