This page is no longer maintained — Please continue to the home page at www.scala-lang.org

Bug with lazy vals in methods when combined with try/catch

5 replies
Chris Marshall
Joined: 2009-06-17,
User offline. Last seen 44 weeks 3 days ago.
I'm just confirming people think this is a bug with RC6 (also broken in 2.7.7 so not regression)
The following compiles JUST fine:
package oxbow
   class Test2() {
def foo : Unit = { lazy val event = { //IF I REMOVE THE LAZY IT RUNS try { "Hello"} catch { case _ => "World" }     }     println(event)   }
}
object VE {   def main(args: Array[String]) {     println(Class.forName("oxbow.Test2"))   } }
Trying to run VE I get the following:
Exception in thread "main" java.lang.VerifyError: (class: oxbow/Test2, method: event$1 signature: (Lscala/runtime/ObjectRef;Lscala/runtime/IntRef;)Ljava/lang/String;) Inconsistent stack height 0 != 1 at java.lang.Class.forName0(Native Method) at java.lang.Class.forName(Class.java:169) at oxbow.VE$.main(test.scala:22) at oxbow.VE.main(test.scala)
The above code compiles and runs if I remove the lazy keyword. If I change the Test2 class to look as follows:
class Test2() {
def foo : Unit = {     lazy val event = "Hello" //STILL LAZY BUT NO TRY/CATCH     println(event)   } }


Get a free e-mail account with Hotmail. Sign-up now.
extempore
Joined: 2008-12-17,
User offline. Last seen 35 weeks 3 days ago.
Re: Bug with lazy vals in methods when combined with try/catch

On Wed, Jun 30, 2010 at 03:09:12PM +0000, christopher marshall wrote:
> I'm just confirming people think this is a bug with RC6 (also broken
> in 2.7.7 so not regression)

You don't have to ask whether anyone thinks code which compiles and
throws a VerifyError at runtime is a bug. Wouldn't it be nice if our
standards were so low! I'm going to modify the specification in a few
places with something like "... and in addition to the preceding
possibilities, once in a while it will generate invalid bytecode."

Also, that email had to set some kind of record for creative formatting.
I crown you the pablo picasso of programming.

The bug is:

https://lampsvn.epfl.ch/trac/scala/ticket/2333
"lazy vals with try {} catch {} throw VerifyError on runtime"

Chris Marshall
Joined: 2009-06-17,
User offline. Last seen 44 weeks 3 days ago.
RE: Bug with lazy vals in methods when combined with try/catch
> From: paulp@improving.org
>
> You don't have to ask whether anyone thinks code which compiles and
> throws a VerifyError at runtime is a bug. 
No, indeed. I actually find it difficult to find stuff in trac (there is something wrong with my brain, I think) and was worried about raising a duplicate and wasting your time. Should have been more clear about that - thanks for raising a ticket
> Wouldn't it be nice if our standards were so low! 

Using 2.7.x: Source.fromInputStream(System.in).getLines
'Nuff said :-)


Get a free e-mail account with Hotmail. Sign-up now.
Alex Cruise
Joined: 2008-12-17,
User offline. Last seen 2 years 26 weeks ago.
Re: Bug with lazy vals in methods when combined with try/catch
On Thu, Jul 1, 2010 at 12:42 AM, christopher marshall <oxbow_lakes@hotmail.com> wrote:
No, indeed. I actually find it difficult to find stuff in trac (there is something wrong with my brain, I think)

No, we're all just spoiled by Google.  For some reason the PageRank of Scala's trac ticket pages isn't very high, but you can force the issue with "site:lampsvn.epfl.ch mySearchTerms"
-0xe1a
extempore
Joined: 2008-12-17,
User offline. Last seen 35 weeks 3 days ago.
Re: Bug with lazy vals in methods when combined with try/catch

On Thu, Jul 01, 2010 at 07:42:38AM +0000, christopher marshall wrote:
> No, indeed. I actually find it difficult to find stuff in trac (there
> is something wrong with my brain, I think)

Finding information in trac can be annoying. I spend a lot of time
struggling with it when I have something complicated to express. That
said, let's try something uncomplicated.

> //IF I REMOVE THE LAZY IT RUNS
> Exception in thread "main" java.lang.VerifyError:

Those points seem important, so what I did was go on over to trac and
search for:

lazy verifyerror

And it won't always be this smooth, but:

Results (1 of 1)

#2333: defect: lazy vals with try {} catch {} throw VerifyError on runtime (new)

I don't know if there's some learned helplessness going on from previous
trac failures or what, but this doesn't count as difficult to find by
any metric. A crack team of professional googlers couldn't get their
hands on it any faster.

> > Wouldn't it be nice if our standards were so low!
>
> Using 2.7.x: Source.fromInputStream(System.in).getLines
> 'Nuff said :-)

I will say that is not enough said since I don't know what you're
saying. But it is enough said if you're just pointing out some bug,
because that misses the point: the point is not that there are not bugs,
but that we don't say obviously broken behaviors are not bugs. (One can
quibble about what "obviously broken" means, but no amount of quibbling
will get you to VerifyError.)

Chris Marshall
Joined: 2009-06-17,
User offline. Last seen 44 weeks 3 days ago.
RE: Bug with lazy vals in methods when combined with try/catch
> Date: Thu, 1 Jul 2010 11:15:20 -0700
> From: paulp@improving.org
> To: oxbow_lakes@hotmail.com

> Finding information in trac can be annoying. I spend a lot of time
> struggling with it when I have something complicated to express. That
> said, let's try something uncomplicated.

> what I did was go on over to trac and search for:>
> lazy verifyerror

Good job you did not try "verifyerror inconsistent stack depth lazy try catch", "lazy val stack depth", "lazy try catch", "lazy try catch bad class file" etc etc. Having said that, I should have found it - apologies
> > Using 2.7.x: Source.fromInputStream(System.in).getLines
> > 'Nuff said :-)
>
> I will say that is not enough said since I don't know what you're
> saying. But it is enough said if you're just pointing out some bug,
> because that misses the point: the point is not that there are not bugs,
> but that we don't say obviously broken behaviors are not bugs. 

The only thing I can infer from that is that no one has ever tried or tested the Source.fromInputStream(stdin). Here is a nice program to run using scala 2.7.7:
  object Echo {    def main(args: Array[String]) {      Source.fromInputStream(System.in).getLines foreach ( l => println("Echo: " + line) )    }  }
Then type "Hello"+ENTER+"World"+ENTER. This is fixed in 2.8. 
I was joking, however: I very much appreciate all the effort you, EPFL and all the scala committers put in to the language.
Chris
Get a new e-mail account with Hotmail - Free. Sign-up now.

Copyright © 2012 École Polytechnique Fédérale de Lausanne (EPFL), Lausanne, Switzerland