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

(1.1.7) Compilation errors when compiling with -O on javac

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Duplicate
    • Icon: P2 P2
    • None
    • 1.1.7
    • tools
    • None
    • x86
    • windows_nt

      A customer is running into several compiler errors when compiling the following code with javac with the -O flag that do not occur when I run either without it or with -g.


      public class CrashJavac {
      public CrashJavac() {
      }
      public void crash() {
      final CrashJavac crash = this;
      Object obj = new Object() {
      public String toString() {
      return crash.toString();
      }
      };
      }
      }

      Running javac -O CrashJavac.java causes the following error message:

      sun.tools.java.CompilerError: addReference CrashJavac crash
              at java.lang.Throwable.<init>(Compiled Code)
              at java.lang.Error.<init>(Compiled Code)
              at sun.tools.java.CompilerError.<init>(Compiled Code)
              at sun.tools.java.ClassDefinition.addReference(Compiled Code)
              at sun.tools.java.ClassDefinition.getReference(Compiled Code)
              at sun.tools.tree.Context.noteReference(Compiled Code)
              at sun.tools.tree.Context.makeReference(Compiled Code)
              at sun.tools.tree.UplevelReference.codeArguments(Compiled Code)
              at sun.tools.tree.NewInstanceExpression.codeCommon(Compiled Code)
              at sun.tools.tree.NewInstanceExpression.code(Compiled Code)
              at sun.tools.tree.ExpressionStatement.code(Compiled Code)
              at sun.tools.tree.DeclarationStatement.code(Compiled Code)
              at sun.tools.javac.SourceField.code(Compiled Code)
              at sun.tools.javac.SourceField.code(Compiled Code)
              at sun.tools.javac.SourceClass.compileClass(Compiled Code)
              at sun.tools.javac.SourceClass.compile(Compiled Code)
              at sun.tools.javac.Main.compile(Compiled Code)
              at sun.tools.javac.Main.main(Compiled Code)
      CrashJavac.java:0: class CrashJavac:void crash()@sun.tools.java.CompilerError: addReference CrashJavac crash
      public class CrashJavac {
      ^
      1 error

            tturnidgsunw Todd Turnidge (Inactive)
            duke J. Duke
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: