- About Scala
- Documentation
- Code Examples
- Software
- Scala Developers
VerifyError with exceptions occurring inside of lazy vals (even if they are caught)
Mon, 2011-03-21, 14:52
Hey guys,
This is on Scala 2.8.1 on OS X Snow Leopard,
Given the following code:
object ReflectiveAccess {
def getClassFor[T](fqn: String, classloader: ClassLoader): Option[Class[T]] = {
assert(fqn ne null)
lazy val a =
try { Option(classloader.loadClass(fqn).asInstanceOf[Class[T]]) } catch { case c: ClassNotFoundException => None }
lazy val b =
try { Option(Thread.currentThread.getContextClassLoader.loadClass(fqn).asInstanceOf[Class[T]]) } catch { case c: ClassNotFoundException => None }
lazy val c =
try { Option(this.getClass.getClassLoader.loadClass(fqn).asInstanceOf[Class[T]]) } catch { case c: ClassNotFoundException => None }
lazy val d =
try { Option(Class.forName(fqn).asInstanceOf[Class[T]]) } catch { case c: ClassNotFoundException => None }
if(a.isDefined) a
else if (b.isDefined) b
else if (c.isDefined) c
else if (d.isDefined) d
else None
}
}
When running the code:
Welcome to Scala version 2.8.1.final (Java HotSpot(TM) 64-Bit Server VM, Java 1.6.0_22).
Type in expressions to have them evaluated.
Type :help for more information.
scala> import akka.util.ReflectiveAccess
import akka.util.ReflectiveAccess
scala> ReflectiveAccess.getClassFor("foo")
java.lang.VerifyError: (class: akka/util/ReflectiveAccess$, method: a$1 signature: (Ljava/lang/String;Ljava/lang/ClassLoader;Lscala/runtime/ObjectRef;Lscala/runtime/VolatileIntRef;)Lscala/Option;) Inconsistent stack height 0 != 1
at .<init>(<console>:7)
at .<clinit>(<console>)
at RequestResult$.<init>(<console>:9)
at RequestResult$.<clinit>(<console>)
at RequestResult$scala_repl_result(<console>)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at scala.tools.nsc.Interpreter$Request$$anonfun$loadAndRun$1$$anonfun$apply$17.apply(Interpreter.scala...
scala>
Should I open a ticket?
Cheers,
--
Viktor Klang,
Code Connoisseur
Work: Scalable Solutions
Code: github.com/viktorklang
Follow: twitter.com/viktorklang
Read: klangism.tumblr.com
This is on Scala 2.8.1 on OS X Snow Leopard,
Given the following code:
object ReflectiveAccess {
def getClassFor[T](fqn: String, classloader: ClassLoader): Option[Class[T]] = {
assert(fqn ne null)
lazy val a =
try { Option(classloader.loadClass(fqn).asInstanceOf[Class[T]]) } catch { case c: ClassNotFoundException => None }
lazy val b =
try { Option(Thread.currentThread.getContextClassLoader.loadClass(fqn).asInstanceOf[Class[T]]) } catch { case c: ClassNotFoundException => None }
lazy val c =
try { Option(this.getClass.getClassLoader.loadClass(fqn).asInstanceOf[Class[T]]) } catch { case c: ClassNotFoundException => None }
lazy val d =
try { Option(Class.forName(fqn).asInstanceOf[Class[T]]) } catch { case c: ClassNotFoundException => None }
if(a.isDefined) a
else if (b.isDefined) b
else if (c.isDefined) c
else if (d.isDefined) d
else None
}
}
When running the code:
Welcome to Scala version 2.8.1.final (Java HotSpot(TM) 64-Bit Server VM, Java 1.6.0_22).
Type in expressions to have them evaluated.
Type :help for more information.
scala> import akka.util.ReflectiveAccess
import akka.util.ReflectiveAccess
scala> ReflectiveAccess.getClassFor("foo")
java.lang.VerifyError: (class: akka/util/ReflectiveAccess$, method: a$1 signature: (Ljava/lang/String;Ljava/lang/ClassLoader;Lscala/runtime/ObjectRef;Lscala/runtime/VolatileIntRef;)Lscala/Option;) Inconsistent stack height 0 != 1
at .<init>(<console>:7)
at .<clinit>(<console>)
at RequestResult$.<init>(<console>:9)
at RequestResult$.<clinit>(<console>)
at RequestResult$scala_repl_result(<console>)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at scala.tools.nsc.Interpreter$Request$$anonfun$loadAndRun$1$$anonfun$apply$17.apply(Interpreter.scala...
scala>
Should I open a ticket?
Cheers,
--
Viktor Klang,
Code Connoisseur
Work: Scalable Solutions
Code: github.com/viktorklang
Follow: twitter.com/viktorklang
Read: klangism.tumblr.com
On Mon, Mar 21, 2011 at 2:52 PM, √iktor Klang wrote:
> def getClassFor[T](fqn: String, classloader: ClassLoader): Option[Class[T]]
> scala> ReflectiveAccess.getClassFor("foo")
> java.lang.VerifyError: (class: akka/util/ReflectiveAccess$, method: a$1
> signature:
This looks like stale class files, your code expects two parameters
but you are giving it only one, or am I missing something?