Janino
  1. Janino
  2. JANINO-147

JaninoRuntimeException: Cannot "set()" Offset more than once

    Details

    • Type: Bug Bug
    • Status: Resolved Resolved
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: 2.6.0-RC3
    • Fix Version/s: 2.6.2
    • Labels:
      None
    • Environment:
      redhat x86_64, jdk 1.5.0_19-b02
    • Testcase included:
      yes
    • Number of attachments :
      0

      Description

      Compiling code that has a method with a switch statement, inside an initializer of a data member of an anonymous inner class, janino throws the following exception:

      JaninoRuntimeException: Cannot "set()" Offset more than once

      I reproduced the problem in the debugger, and put a break point in CodeContext.Offset.set. The break point was hit twice, once with initializeInstanceVariablesAndInvokeInstanceInitializers() on the stack, and once not. I'm guessing that initializing the instance variables is re-doing some work that it shouldn't.

      Here's the test case (I think it's minimal) and the stack trace.

      [jhyde@plank intellij]$ cat /tmp/Foo.java
      public class Foo
      {
      public static void main(String[] args) {
      Object foo = new Object() {
      Object bar = new Object() {
      public Object getObject(int i8) {
      switch (i8)

      { case 0: return "sss"; }

      return null;
      }
      };
      };
      }
      }
      [jhyde@plank intellij]$ java -cp ../../thirdparty/janino/janino.jar org.codehaus.janino.SimpleCompiler /tmp/Foo.java Foo
      Exception in thread "main" org.codehaus.janino.JaninoRuntimeException: Cannot "set()" Offset more than once
      at org.codehaus.janino.CodeContext$Offset.set(CodeContext.java:1178)
      at org.codehaus.janino.UnitCompiler.compile2(UnitCompiler.java:1142)
      at org.codehaus.janino.UnitCompiler.access$1300(UnitCompiler.java:103)
      at org.codehaus.janino.UnitCompiler$4.visitSwitchStatement(UnitCompiler.java:787)
      at org.codehaus.janino.Java$SwitchStatement.accept(Java.java:1680)
      at org.codehaus.janino.UnitCompiler.compile(UnitCompiler.java:802)
      at org.codehaus.janino.UnitCompiler.compileStatements(UnitCompiler.java:828)
      at org.codehaus.janino.UnitCompiler.compile(UnitCompiler.java:1913)
      at org.codehaus.janino.UnitCompiler.compileDeclaredMethods(UnitCompiler.java:765)
      at org.codehaus.janino.UnitCompiler.compileDeclaredMethods(UnitCompiler.java:746)
      at org.codehaus.janino.UnitCompiler.compile2(UnitCompiler.java:461)
      at org.codehaus.janino.UnitCompiler.compile2(UnitCompiler.java:605)
      at org.codehaus.janino.UnitCompiler.compile2(UnitCompiler.java:566)
      at org.codehaus.janino.UnitCompiler$3.visitAnonymousClassDeclaration(UnitCompiler.java:307)
      at org.codehaus.janino.Java$AnonymousClassDeclaration.accept(Java.java:553)
      at org.codehaus.janino.UnitCompiler.compile(UnitCompiler.java:316)
      at org.codehaus.janino.UnitCompiler.compileGet2(UnitCompiler.java:3670)
      at org.codehaus.janino.UnitCompiler.access$6600(UnitCompiler.java:103)
      at org.codehaus.janino.UnitCompiler$10.visitNewAnonymousClassInstance(UnitCompiler.java:2781)
      at org.codehaus.janino.Java$NewAnonymousClassInstance.accept(Java.java:2948)
      at org.codehaus.janino.UnitCompiler.compileGet(UnitCompiler.java:2799)
      at org.codehaus.janino.UnitCompiler.compileGetValue(UnitCompiler.java:3806)
      at org.codehaus.janino.UnitCompiler.compile2(UnitCompiler.java:1283)
      at org.codehaus.janino.UnitCompiler.access$500(UnitCompiler.java:103)
      at org.codehaus.janino.UnitCompiler$4.visitFieldDeclaration(UnitCompiler.java:779)
      at org.codehaus.janino.Java$FieldDeclaration.accept(Java.java:1242)
      at org.codehaus.janino.UnitCompiler.compile(UnitCompiler.java:802)
      at org.codehaus.janino.UnitCompiler.initializeInstanceVariablesAndInvokeInstanceInitializers(UnitCompiler.java:5148)
      at org.codehaus.janino.UnitCompiler.compile(UnitCompiler.java:1869)
      at org.codehaus.janino.UnitCompiler.compile2(UnitCompiler.java:472)
      at org.codehaus.janino.UnitCompiler.compile2(UnitCompiler.java:605)
      at org.codehaus.janino.UnitCompiler.compile2(UnitCompiler.java:566)
      at org.codehaus.janino.UnitCompiler$3.visitAnonymousClassDeclaration(UnitCompiler.java:307)
      at org.codehaus.janino.Java$AnonymousClassDeclaration.accept(Java.java:553)
      at org.codehaus.janino.UnitCompiler.compile(UnitCompiler.java:316)
      at org.codehaus.janino.UnitCompiler.compileGet2(UnitCompiler.java:3670)
      at org.codehaus.janino.UnitCompiler.access$6600(UnitCompiler.java:103)
      at org.codehaus.janino.UnitCompiler$10.visitNewAnonymousClassInstance(UnitCompiler.java:2781)
      at org.codehaus.janino.Java$NewAnonymousClassInstance.accept(Java.java:2948)
      at org.codehaus.janino.UnitCompiler.compileGet(UnitCompiler.java:2799)
      at org.codehaus.janino.UnitCompiler.compileGetValue(UnitCompiler.java:3806)
      at org.codehaus.janino.UnitCompiler.compile2(UnitCompiler.java:1485)
      at org.codehaus.janino.UnitCompiler.access$1600(UnitCompiler.java:103)
      at org.codehaus.janino.UnitCompiler$4.visitLocalVariableDeclarationStatement(UnitCompiler.java:790)
      at org.codehaus.janino.Java$LocalVariableDeclarationStatement.accept(Java.java:1770)
      at org.codehaus.janino.UnitCompiler.compile(UnitCompiler.java:802)
      at org.codehaus.janino.UnitCompiler.compileStatements(UnitCompiler.java:828)
      at org.codehaus.janino.UnitCompiler.compile(UnitCompiler.java:1913)
      at org.codehaus.janino.UnitCompiler.compileDeclaredMethods(UnitCompiler.java:765)
      at org.codehaus.janino.UnitCompiler.compileDeclaredMethods(UnitCompiler.java:746)
      at org.codehaus.janino.UnitCompiler.compile2(UnitCompiler.java:461)
      at org.codehaus.janino.UnitCompiler.compile2(UnitCompiler.java:354)
      at org.codehaus.janino.UnitCompiler$3.visitPackageMemberClassDeclaration(UnitCompiler.java:309)
      at org.codehaus.janino.Java$PackageMemberClassDeclaration.accept(Java.java:769)
      at org.codehaus.janino.UnitCompiler.compile(UnitCompiler.java:316)
      at org.codehaus.janino.UnitCompiler.compileUnit(UnitCompiler.java:285)
      at org.codehaus.janino.SimpleCompiler.compileToClassLoader(SimpleCompiler.java:394)
      at org.codehaus.janino.SimpleCompiler.cook(SimpleCompiler.java:195)
      at org.codehaus.janino.SimpleCompiler.cook(SimpleCompiler.java:185)
      at org.codehaus.commons.compiler.Cookable.cook(Cookable.java:65)
      at org.codehaus.commons.compiler.Cookable.cook(Cookable.java:50)
      at org.codehaus.janino.SimpleCompiler.<init>(SimpleCompiler.java:120)
      at org.codehaus.janino.SimpleCompiler.main(SimpleCompiler.java:83)

        Activity

        Hide
        Arno Unkrig added a comment -

        Problem could be reproduced. In fact the test case appears to be minimal.

        Show
        Arno Unkrig added a comment - Problem could be reproduced. In fact the test case appears to be minimal.
        Hide
        Arno Unkrig added a comment -

        Please test.

        Show
        Arno Unkrig added a comment - Please test.

          People

          • Assignee:
            Arno Unkrig
            Reporter:
            Julian Hyde
          • Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved: