Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

java.lang.VerifyError when using nested try/catch and ControlThrowable #7807

Closed
scabug opened this issue Sep 3, 2013 · 3 comments
Closed
Assignees
Milestone

Comments

@scabug
Copy link

scabug commented Sep 3, 2013

There may be an issue with nested try/catch blocks and ControlThrowable.

import scala.util.control.ControlThrowable

object Bar {
  def main(args: Array[String]) {
    try {
      println("...")
    }
    finally {
      try {
        println("...")
      }
      finally {
        try {
          println("...")
        }
        catch {
          case ct: ControlThrowable => throw(ct)
          case t: Throwable => t.printStackTrace()
        }
      }
    }
  }
}

compiles, but when run leads to a VerifyError:

[info] Running Bar 
[error] java.lang.VerifyError: (class: Bar$, method: main signature: ([Ljava/lang/String;)V) Accessing value from uninitialized register 9
[error] 	at Bar.main(Bar.scala)
[error] 	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
[error] 	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
[error] 	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
[error] 	at java.lang.reflect.Method.invoke(Method.java:606)
[error] 	at scala.tools.nsc.util.ScalaClassLoader$$anonfun$run$1.apply(ScalaClassLoader.scala:71)
[error] 	at scala.tools.nsc.util.ScalaClassLoader$class.asContext(ScalaClassLoader.scala:31)
[error] 	at scala.tools.nsc.util.ScalaClassLoader$URLClassLoader.asContext(ScalaClassLoader.scala:139)
[error] 	at scala.tools.nsc.util.ScalaClassLoader$class.run(ScalaClassLoader.scala:71)
[error] 	at scala.tools.nsc.util.ScalaClassLoader$URLClassLoader.run(ScalaClassLoader.scala:139)
[error] 	at scala.tools.nsc.CommonRunner$class.run(ObjectRunner.scala:28)
[error] 	at scala.tools.nsc.ObjectRunner$.run(ObjectRunner.scala:45)
[error] 	at scala.tools.nsc.CommonRunner$class.runAndCatch(ObjectRunner.scala:35)
[error] 	at scala.tools.nsc.ObjectRunner$.runAndCatch(ObjectRunner.scala:45)
[error] 	at scala.tools.nsc.MainGenericRunner.runTarget$1(MainGenericRunner.scala:74)
[error] 	at scala.tools.nsc.MainGenericRunner.process(MainGenericRunner.scala:96)
[error] 	at scala.tools.nsc.MainGenericRunner$.main(MainGenericRunner.scala:105)
[error] 	at scala.tools.nsc.MainGenericRunner.main(MainGenericRunner.scala)
@scabug
Copy link
Author

scabug commented Sep 3, 2013

Imported From: https://issues.scala-lang.org/browse/SI-7807?orig=1
Reporter: Patrick Tschorn (ptschorn)
Affected Versions: 2.10.2

@scabug
Copy link
Author

scabug commented Sep 3, 2013

@magarciaEPFL said:
Easy cake for GenBCode, whether optimization is on or not.

Not sure whether this bug shares a root cause with #7407 . The problem there last time I checked was a per-design best-effort shuffling of ICode CFG blocks aiming to comply with bytecode verification.

In contrast, the bytecode emitted by GenBCode reflects the lexical nesting of try-catch-finally, thus it always passes bytecode verification.

To better see the ordering of side-effects:

import scala.util.control.ControlThrowable

object Test {
  def main(args: Array[String]) {
    try { println(1) }
    finally {
      try { println(2) }
      finally {
        try   { println(3) }
        catch {
          case ct: ControlThrowable => throw(ct)
          case t:  Throwable        => t.printStackTrace()
        }
      }
    }
  }
}

@scabug
Copy link
Author

scabug commented Feb 3, 2016

@lrytz said (edited on Feb 3, 2016 3:28:27 PM UTC):
fixed in 2.12 backend, test case added in scala/scala#4920

@scabug scabug closed this as completed Feb 3, 2016
@scabug scabug added this to the 2.12.0-M4 milestone Apr 7, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants