JDK-4463896 : Class literals are compiled into code which conflicts with CLDC exceptions
  • Type: Bug
  • Component: tools
  • Sub-Component: launcher
  • Affected Version: 1.3.0
  • Priority: P3
  • Status: Closed
  • Resolution: Duplicate
  • OS: solaris_2.5.1
  • CPU: sparc
  • Submitted: 2001-05-29
  • Updated: 2001-05-29
  • Resolved: 2001-05-29
Related Reports
Duplicate :  
Description

Name: hk112284			Date: 05/29/2001


When compiling a java source file that uses the "class literal"
syntax (e.g. className.class), the javac compiler (both the jdk1.2.2
and the jdk1.3 versions) inserts some <clinit> code that includes a
reference to the java.lang.NoClassDefFoundError class.

This causes a problem when I set the bootclasspath to refer to the
j2me_cldc classes which do not include the java.lang.NoClassDefFoundError class.

Is there a compiler switch or other mechanism to direct the javac compiler to a
different error/exception that exists in the j2me_cldc classes
(e.g. another -target type such as -target cldc)?

The following code demonstrates the problem

public class MyTestClass {

  static final String MYTESTCLASS_PREFIX = MyTestClass.class.getName();

  public static void main( String[] args ) {
    System.out.println( "My test classes prefix is : " + MYTESTCLASS_PREFIX );
  }

}


----------------

The above class is compiled as listed below (except each compiler option is
placed indented on a separate line for clarity).
\jdk1.2.2\bin\javac
   -target 1.1
   -bootclasspath c:\j2me_cldc\bin\api\classes
   -extdirs ""
   -classpath . MyTestClass.java
MyTestClass.java:5: Class java.lang.NoClassDefFoundError not found in java.lang.Class
class$(java.lang.String).
public class MyTestClass {
             ^
1 error

---------------

When using the jdk1.3 compiler the problem also occurs, but it results in a compiler
crash as shown below

\jdk1.3\bin\javac
   -target 1.1
   -bootclasspath c:\j2me_cldc\bin\api\classes
   -extdirs ""
   -classpath . MyTestClass.java
An exception has occurred in the compiler (1.3.0). Please file a bug at the Java Developer
Connection
(http://java.sun.com/cgi-bin/bugreport.cgi).  Include your program and the following diagnostic
in your report.  Thank
you.
com.sun.tools.javac.v8.code.Symbol$CompletionFailure: file java\lang\NoClassDefFoundError.class
not found
        at com.sun.tools.javac.v8.code.ClassReader.fillIn(ClassReader.java:997)
        at com.sun.tools.javac.v8.code.ClassReader.complete(ClassReader.java:952)
        at com.sun.tools.javac.v8.code.Symbol.complete(Symbol.java:366)
        at com.sun.tools.javac.v8.code.Symbol$ClassSymbol.flags(Symbol.java:578)
        at com.sun.tools.javac.v8.comp.Resolve.findMethod(Resolve.java:367)
        at com.sun.tools.javac.v8.comp.Resolve.resolveQualifiedMethod(Resolve.java:808)
        at com.sun.tools.javac.v8.comp.Resolve.resolveConstructor(Resolve.java:827)
        at com.sun.tools.javac.v8.comp.TransInner.makeNewClass(TransInner.java:239)
        at com.sun.tools.javac.v8.comp.TransInner.classDollarSym(TransInner.java:1198)
        at com.sun.tools.javac.v8.comp.TransInner.classOf(TransInner.java:1291)
        at com.sun.tools.javac.v8.comp.TransInner._case(TransInner.java:1554)
        at com.sun.tools.javac.v8.tree.Tree$Select.visit(Tree.java:963)
        at com.sun.tools.javac.v8.tree.TreeTranslator.translate(TreeTranslator.java:35)
        at com.sun.tools.javac.v8.comp.TransInner._case(TransInner.java:1552)
        at com.sun.tools.javac.v8.tree.Tree$Select.visit(Tree.java:963)
        at com.sun.tools.javac.v8.tree.TreeTranslator.translate(TreeTranslator.java:35)
        at com.sun.tools.javac.v8.comp.TransInner._case(TransInner.java:1485)
        at com.sun.tools.javac.v8.tree.Tree$Apply.visit(Tree.java:785)
        at com.sun.tools.javac.v8.tree.TreeTranslator.translate(TreeTranslator.java:35)
        at com.sun.tools.javac.v8.tree.TreeTranslator._case(TreeTranslator.java:106)
        at com.sun.tools.javac.v8.tree.Tree$VarDef.visit(Tree.java:470)
        at com.sun.tools.javac.v8.tree.TreeTranslator.translate(TreeTranslator.java:35)
        at com.sun.tools.javac.v8.comp.TransInner._case(TransInner.java:1355)
        at com.sun.tools.javac.v8.tree.Tree$ClassDef.visit(Tree.java:402)
        at com.sun.tools.javac.v8.tree.TreeTranslator.translate(TreeTranslator.java:35)
        at com.sun.tools.javac.v8.comp.TransInner.translate(TransInner.java:1317)
        at com.sun.tools.javac.v8.comp.TransInner.translateTopLevelClass(TransInner.java:1583)
        at com.sun.tools.javac.v8.JavaCompiler.compile(JavaCompiler.java:397)
        at com.sun.tools.javac.v8.Main.compile(Main.java:247)
        at com.sun.tools.javac.Main.main(Main.java:16)
(Review ID: 120686) 
======================================================================