JDK-4986512 : (cl) NoClassDefFoundError thrown when loading classes with names containing '/'
  • Type: Bug
  • Component: core-libs
  • Sub-Component: java.lang:class_loading
  • Affected Version: 5.0
  • Priority: P3
  • Status: Closed
  • Resolution: Not an Issue
  • OS: linux,windows_2000
  • CPU: x86
  • Submitted: 2004-01-30
  • Updated: 2012-10-08
  • Resolved: 2004-02-05
Related Reports
Duplicate :  
Relates :  
###@###.### 2004-01-30

J2SE Version (please include all output from java -version flag):
 java version "1.5.0-beta"
 Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0-beta-b32)
 Java HotSpot(TM) Client VM (build 1.5.0-beta-b32, mixed mode)

Does this problem occur on J2SE 1.3, 1.4 or 1.4.1?  Yes / No (pick one)
 No, works fine with 1.4.2

Bug Description:
  Customer has some code that generates classes on the fly, and loads them 
  (its a compiler for a scripting language).

  It works fine in JDK 1.4.2, but in 1.5.0, when it tries to load the
  newly generated class, it throws errors like the following:

java.lang.NoClassDefFoundError: IllegalName: factor/compiler/write__143
        at java.lang.ClassLoader.preDefineClass(ClassLoader.java:459)
        at java.lang.ClassLoader.defineClass(ClassLoader.java:598)
        at java.lang.ClassLoader.defineClass(ClassLoader.java:448)
        at factor.FactorWordDefinition$SimpleClassLoader._defineClass(FactorWordDefinition.java:257)
        at factor.FactorWordDefinition.compile(FactorWordDefinition.java:194)
        at factor.FactorWord.compile(FactorWord.java:74)
        at sun.reflect.GeneratedMethodAccessor4.invoke(Unknown Source)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
        at java.lang.reflect.Method.invoke(Method.java:494)
        at factor.FactorJava.jinvoke(FactorJava.java:439)
        at factor.FactorPrimitive$P_jinvoke.eval(FactorPrimitive.java:365)
        at factor.FactorInterpreter.eval(FactorInterpreter.java:329)
        at factor.FactorInterpreter.run(FactorInterpreter.java:189)
        at factor.FactorInterpreter.runBootstrap(FactorInterpreter.java:150)
        at factor.FactorInterpreter.init(FactorInterpreter.java:118)
        at factor.FactorInterpreter.main(FactorInterpreter.java:76)

Step to Reproduce:
  Hard to get a narrow down test case. just attached a zip file which
  contains 143 automatically generated classes. They all work fine with
  1.4.2, but in 1.5 they all fail to load with an error; check the above
  stack traces.

###@###.### 2004-02-03

Test case attached - ASMTest.jar.

run java ASMTest and get the following error:

Exception in thread "main" java.lang.NoClassDefFoundError: IllegalName: foo/bar/baz/quux
        at java.lang.ClassLoader.preDefineClass(ClassLoader.java:459)
        at java.lang.ClassLoader.defineClass(ClassLoader.java:598)
        at java.lang.ClassLoader.defineClass(ClassLoader.java:448)
        at ASMTest$SimpleClassLoader._defineClass(ASMTest.java:46)
        at ASMTest.main(ASMTest.java:30)

but, works fine with 1.4.2.

EVALUATION This is the intended behaviour. Since ClassLoader.defineClass was introduced in jdk1.1, this has been the specification for the syntax of the expected class name: @param name The expected name of the class, or null if not known, using '.' and not '/' as the separator and without a trailing ".class" suffix. In jdk1.5 we modified the implemenation of ClassLoader and have improved parameter checking for this method. As the detail message of the exception indicates, the provided class name is illegal. The code which calls defineClass should be modified to use '.' as the separator for the class name. -- iag@sfbay 2004-02-04