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

compiler crashed when trying to use fancy static initializer, ..TryStatement.cop

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Duplicate
    • Icon: P4 P4
    • None
    • 1.1
    • tools
    • None
    • sparc
    • solaris_2.5.1



      Name: sgC58550 Date: 05/15/97


      Ok, I tried to compile the following piece of code:

      package alpha.server;
      public final
      class Server {
        {
          try {
          } catch(Exception e) {
            e.printStackTrace(System.err);
            throw new RuntimeException("Static initializer failed!");
          }
        }
        public static void main(String[] args) {
          System.out.println("test!");
        }
      }

      The idea was to use a static initializer to initialize a static final
      field with a few statements that might have thrown a checked exception.
      Since static initializer cannot throw checked exceptions I tried to use
      the code above to catch and print the checked exception and then to throw
      a RuntimeException which the static initializers are allowed to throw.
      However the compiler crashed with the following trace dump:

      sun.tools.java.CompilerError: copyInline
              at sun.tools.tree.TryStatement.copyInline(TryStatement.java)
              at sun.tools.tree.CompoundStatement.copyInline(CompoundStatement.java)
              at sun.tools.tree.InlineMethodExpression.copyInline(InlineMethodExpression.java)
              at sun.tools.tree.MethodExpression.makeVarInits(MethodExpression.java)
              at sun.tools.tree.MethodExpression.checkValue(MethodExpression.java)
              at sun.tools.tree.MethodExpression.check(MethodExpression.java)
              at sun.tools.tree.ExpressionStatement.check(ExpressionStatement.java)
              at sun.tools.tree.CompoundStatement.check(CompoundStatement.java)
              at sun.tools.tree.Statement.checkMethod(Statement.java)
              at sun.tools.javac.SourceField.check(SourceField.java)
              at sun.tools.javac.SourceClass.checkFields(SourceClass.java)
              at sun.tools.javac.SourceClass.checkInternal(SourceClass.java)
              at sun.tools.javac.SourceClass.check(SourceClass.java)
              at sun.tools.javac.Main.compile(Main.java)
              at sun.tools.javac.Main.main(Main.java)
      error: An error has occurred in the compiler; please file a bug report
      (###@###.###).
      1 error

      I tried then to use the following static initializer:

      {
        try {
        } catch(Exception e) {
        }
      }

      And it crashed again. I think that means using try-catch inside
      static initializers always crashes the compiler...

      ======================================================================

            dstoutamsunw David Stoutamire (Inactive)
            sgoodsunw Sheri Good (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: