#2481 Nesting try / finally blocks

SlimerDude Sat 3 Oct 2015

When I nest try / finally blocks like this:

class Example {
    Void main() {
        try {
            null?.toStr
        } finally {
            try     null?.toStr
            finally null?.toStr
        }
    }
}

And run it, I get the error Multiple returns to single jsr:

java.lang.VerifyError: (class: fan/dude_0/Example, method: main signature: ()V) Multiple returns to single jsr
    at java.lang.Class.getDeclaredFields0(Native Method)
    at java.lang.Class.privateGetDeclaredFields(Class.java:2300)
    at java.lang.Class.getDeclaredFields(Class.java:1745)
    at fan.sys.ClassType.finishSlots(ClassType.java:591)
    at fan.sys.ClassType.finish(ClassType.java:553)
    at fan.sys.Method$MethodFunc.isStatic(Method.java:475)
    at fan.sys.Method$MethodFunc.callList(Method.java:191)
    at fan.sys.Type.make(Type.java:246)
    at fan.sys.ClassType.make(ClassType.java:110)
    at fan.sys.Type.make(Type.java:236)
    at fanx.tools.Fan.callMain(Fan.java:182)
    at fanx.tools.Fan.executeFile(Fan.java:105)
    at fanx.tools.Fan.execute(Fan.java:37)
    at fanx.tools.Fan.run(Fan.java:305)
    at fanx.tools.Fan.main(Fan.java:343)
sys::Err: Method not mapped to java.lang.reflect correctly dude_0::Example.make
  fan.sys.Method$MethodFunc.isStatic (Method.java:482)
  fan.sys.Method$MethodFunc.callList (Method.java:191)
  fan.sys.Type.make (Type.java:246)
  fan.sys.ClassType.make (ClassType.java:110)
  fan.sys.Type.make (Type.java:236)
  fanx.tools.Fan.callMain (Fan.java:182)
  fanx.tools.Fan.executeFile (Fan.java:105)
  fanx.tools.Fan.execute (Fan.java:37)
  fanx.tools.Fan.run (Fan.java:305)
  fanx.tools.Fan.main (Fan.java:343)

Current workaround is to move the 2nd try / finally block to its own method:

class Example {
    Void main() {
        try {
            null?.toStr
        } finally {
            mainFinally()
        }
    }
    
    Void mainFinally() {
        try     null?.toStr
        finally null?.toStr
    }
}

brian Sat 3 Oct 2015

Ticket promoted to #2481 and assigned to brian

Ok thanks for reporting, that might be hairy one to fix

Login or Signup to reply.