- About Scala
- Documentation
- Code Examples
- Software
- Scala Developers
Re: VerifyError with exceptions occurring inside of lazy vals (even if they are caught)
Mon, 2011-03-21, 15:26
Here's a more accurate piece of code:
object ReflectiveAccess {
val loader = getClass.getClassLoader
def getClassFor[T](fqn: String, classloader: ClassLoader = loader): 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(classOf[Actor].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
}
}
On Mon, Mar 21, 2011 at 3:16 PM, √iktor Klang <viktor.klang@gmail.com> wrote:
--
Viktor Klang,
Code Connoisseur
Work: Scalable Solutions
Code: github.com/viktorklang
Follow: twitter.com/viktorklang
Read: klangism.tumblr.com
object ReflectiveAccess {
val loader = getClass.getClassLoader
def getClassFor[T](fqn: String, classloader: ClassLoader = loader): 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(classOf[Actor].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
}
}
On Mon, Mar 21, 2011 at 3:16 PM, √iktor Klang <viktor.klang@gmail.com> wrote:
Oh, sorry about that, the classloader parameter used a default value but I chopped a bit too hard when composing the email.
On Mar 21, 2011 3:06 PM, "Johannes Rudolph" <johannes.rudolph@googlemail.com> wrote:
On Mon, Mar 21, 2011 at 2:52 PM, √iktor Klang <viktor.klang@gmail.com> wrote:
> def getClassFor[T](f...> scala> ReflectiveAccess.getClassFor("foo")
This looks like stale class files, your code expects two parameters
> java.lang.VerifyError: (class: akka/util/ReflectiveAc...
but you are giving it only one, or am I missing something?
--
Johannes
-----------------------------------------------
Johannes Rudolph
http://virtual-void.net
--
Viktor Klang,
Code Connoisseur
Work: Scalable Solutions
Code: github.com/viktorklang
Follow: twitter.com/viktorklang
Read: klangism.tumblr.com
Mon, 2011-03-21, 16:17
#2
Re: VerifyError with exceptions occurring inside of lazy vals (
On Mon, Mar 21, 2011 at 4:05 PM, Johannes Rudolph <johannes.rudolph@googlemail.com> wrote:
Here's a shorter one:
object LazyTryCatch {
def printer(str: String): Int = { println(str); 0 }
def test: Int = {
lazy val a = try { 0 } catch { case c: ClassNotFoundException => 0 }
a
}
}
What's "printer" for?
Seems to be this one:
http://lampsvn.epfl.ch/trac/scala/ticket/4000
Yeah, I had a look at all tickets that matched the profile, but was unsure whether 4000 was same-same or same-but-different or just plain different.
and is fixed in 2.9.0.
On Mon, Mar 21, 2011 at 3:26 PM, √iktor Klang <viktor.klang@gmail.com> wrote:
> Here's a more accurate piece of code:
>
> object ReflectiveAccess {
>
> val loader = getClass.getClassLoader
>
> def getClassFor[T](fqn: String, classloader: ClassLoader = loader):
> 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(classOf[Actor].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
> }
> }
>
> On Mon, Mar 21, 2011 at 3:16 PM, √iktor Klang <viktor.klang@gmail.com>
> wrote:
>>
>> Oh, sorry about that, the classloader parameter used a default value but I
>> chopped a bit too hard when composing the email.
>>
>> On Mar 21, 2011 3:06 PM, "Johannes Rudolph"
>> <johannes.rudolph@googlemail.com> wrote:
>>
>> On Mon, Mar 21, 2011 at 2:52 PM, √iktor Klang <viktor.klang@gmail.com>
>> wrote:
>> > def getClassFor[T](f...
>>
>> > scala> ReflectiveAccess.getClassFor("foo")
>> > java.lang.VerifyError: (class: akka/util/ReflectiveAc...
>>
>> This looks like stale class files, your code expects two parameters
>> but you are giving it only one, or am I missing something?
>>
>> --
>> Johannes
>>
>> -----------------------------------------------
>> Johannes Rudolph
>> http://virtual-void.net
>
>
>
> --
> Viktor Klang,
> Code Connoisseur
> Work: Scalable Solutions
> Code: github.com/viktorklang
> Follow: twitter.com/viktorklang
> Read: klangism.tumblr.com
>
>
--
Johannes
-----------------------------------------------
Johannes Rudolph
http://virtual-void.net
--
Viktor Klang,
Code Connoisseur
Work: Scalable Solutions
Code: github.com/viktorklang
Follow: twitter.com/viktorklang
Read: klangism.tumblr.com
Mon, 2011-03-21, 16:27
#3
Re: VerifyError with exceptions occurring inside of lazy vals (
On Mon, Mar 21, 2011 at 4:11 PM, √iktor Klang wrote:
> What's "printer" for?
Oh, sorry, scrap that. I (wrongly) thought there was some double code
generation going on and I used the `printer` method to check that.
Just the `test`-method is enough.
>> Seems to be this one:
>> http://lampsvn.epfl.ch/trac/scala/ticket/4000
>>
>
> Yeah, I had a look at all tickets that matched the profile, but was unsure
> whether 4000 was same-same or same-but-different or just plain different.
>
>>
>> and is fixed in 2.9.0.
>>
>> On Mon, Mar 21, 2011 at 3:26 PM, √iktor Klang
>> wrote:
>> > Here's a more accurate piece of code:
>> >
>> > object ReflectiveAccess {
>> >
>> > val loader = getClass.getClassLoader
>> >
>> > def getClassFor[T](fqn: String, classloader: ClassLoader = loader):
>> > 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(classOf[Actor].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
>> > }
>> > }
>> >
>> > On Mon, Mar 21, 2011 at 3:16 PM, √iktor Klang
>> > wrote:
>> >>
>> >> Oh, sorry about that, the classloader parameter used a default value
>> >> but I
>> >> chopped a bit too hard when composing the email.
>> >>
>> >> On Mar 21, 2011 3:06 PM, "Johannes Rudolph"
>> >> wrote:
>> >>
>> >> On Mon, Mar 21, 2011 at 2:52 PM, √iktor Klang
>> >> wrote:
>> >> > def getClassFor[T](f...
>> >>
>> >> > scala> ReflectiveAccess.getClassFor("foo")
>> >> > java.lang.VerifyError: (class: akka/util/ReflectiveAc...
>> >>
>> >> This looks like stale class files, your code expects two parameters
>> >> but you are giving it only one, or am I missing something?
>> >>
>> >> --
>> >> Johannes
>> >>
>> >> -----------------------------------------------
>> >> Johannes Rudolph
>> >> http://virtual-void.net
>> >
>> >
>> >
>> > --
>> > Viktor Klang,
>> > Code Connoisseur
>> > Work: Scalable Solutions
>> > Code: github.com/viktorklang
>> > Follow: twitter.com/viktorklang
>> > Read: klangism.tumblr.com
>> >
>> >
>>
>>
>>
>> --
>> Johannes
>>
>> -----------------------------------------------
>> Johannes Rudolph
>> http://virtual-void.net
>
>
>
> --
> Viktor Klang,
> Code Connoisseur
> Work: Scalable Solutions
> Code: github.com/viktorklang
> Follow: twitter.com/viktorklang
> Read: klangism.tumblr.com
>
>
Here's a shorter one:
object LazyTryCatch {
def printer(str: String): Int = { println(str); 0 }
def test: Int = {
lazy val a = try { 0 } catch { case c: ClassNotFoundException => 0 }
a
}
}
Seems to be this one:
http://lampsvn.epfl.ch/trac/scala/ticket/4000
and is fixed in 2.9.0.
On Mon, Mar 21, 2011 at 3:26 PM, √iktor Klang wrote:
> Here's a more accurate piece of code:
>
> object ReflectiveAccess {
>
> val loader = getClass.getClassLoader
>
> def getClassFor[T](fqn: String, classloader: ClassLoader = loader):
> 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(classOf[Actor].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
> }
> }
>
> On Mon, Mar 21, 2011 at 3:16 PM, √iktor Klang
> wrote:
>>
>> Oh, sorry about that, the classloader parameter used a default value but I
>> chopped a bit too hard when composing the email.
>>
>> On Mar 21, 2011 3:06 PM, "Johannes Rudolph"
>> wrote:
>>
>> On Mon, Mar 21, 2011 at 2:52 PM, √iktor Klang
>> wrote:
>> > def getClassFor[T](f...
>>
>> > scala> ReflectiveAccess.getClassFor("foo")
>> > java.lang.VerifyError: (class: akka/util/ReflectiveAc...
>>
>> This looks like stale class files, your code expects two parameters
>> but you are giving it only one, or am I missing something?
>>
>> --
>> Johannes
>>
>> -----------------------------------------------
>> Johannes Rudolph
>> http://virtual-void.net
>
>
>
> --
> Viktor Klang,
> Code Connoisseur
> Work: Scalable Solutions
> Code: github.com/viktorklang
> Follow: twitter.com/viktorklang
> Read: klangism.tumblr.com
>
>