Muki-SkyWalker / specs

Automatically exported from code.google.com/p/specs
Other
0 stars 0 forks source link

java.lang.String.isEmpty()Z on mustEqual List() #140

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1. I am trying to make sure two List() are equal and I do: (simplified)

List("1","2","3") mustEqual List("7ce2233d-qww0fb-4594-", "q")

and on the console it tells me:

java.lang.NoSuchMethodError: java.lang.String.isEmpty()Z
        at org.specs.runner.ClassRunner.fullClassName(ClassRunner.scala:83)
...

(WIll paste the complete stack trace below.)

Strange thing is, running 

List("1","2","3") mustEqual List("7ce2233d-qww0fb-4594", "q")

goes just fine (well, it fails but it is expected :) )

The only difference is that the second test, the first element on the List is 
one character 
less.

This is the complete test.scala file you can use to reproduce it:

diego:trunk wizard$ cp src/com/mysql/merlin/robot/JsonToScala.scala 
src/com/mysql/merlin/
package com.fmpwizard.robot

import org.specs._
import org.specs.runner._

class ParseServerListTest extends Specification {

  "GetServerList" should {
    "this will fail" in {
      List("1","2","3") mustEqual List("7ce2233d-qww0fb-4594-", "q")
    }
  }
}

and run:

$ scala -cp ../lib/specs-1.6.2.1.jar run com.fmpwizard.ParseServerListTest

More info:

$ scala -version
Scala code runner version 2.7.7.final -- Copyright 2002-2009, LAMP/EPFL

What is the expected output? What do you see instead?
I expect the test to fail telling me those two list do not match, but I get:

java.lang.NoSuchMethodError: java.lang.String.isEmpty()Z
        at org.specs.runner.ClassRunner.fullClassName(ClassRunner.scala:83)
        at org.specs.runner.ClassRunner.createSpecification(ClassRunner.scala:80)
        at 
org.specs.runner.ClassRunner$$anonfun$3$$anonfun$apply$1.apply(ClassRunner.scala
:
76)
        at 
org.specs.runner.ClassRunner$$anonfun$3$$anonfun$apply$1.apply(ClassRunner.scala
:
75)
        at scala.List.map(List.scala:812)
        at org.specs.runner.ClassRunner$$anonfun$3.apply(ClassRunner.scala:75)
        at org.specs.runner.ClassRunner$$anonfun$3.apply(ClassRunner.scala:74)
        at scala.List.flatMap(List.scala:1132)
        at org.specs.runner.ClassRunner.getSpecifications(ClassRunner.scala:74)
        at org.specs.runner.ClassRunner.specs(ClassRunner.scala:44)
        at org.specs.runner.ClassRunner.main(ClassRunner.scala:51)
        at run.main(run.scala)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at 
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
        at 
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.jav
a:2
5)
        at java.lang.reflect.Method.invoke(Method.java:592)
        at scala.tools.nsc.ObjectRunner$$anonfun$run$1.apply(ObjectRunner.scala:75)
        at scala.tools.nsc.ObjectRunner$.withContextClassLoader(ObjectRunner.scala:49)
        at scala.tools.nsc.ObjectRunner$.run(ObjectRunner.scala:74)
        at scala.tools.nsc.MainGenericRunner$.main(MainGenericRunner.scala:154)
        at scala.tools.nsc.MainGenericRunner.main(MainGenericRunner.scala)

What version of the product are you using? On what operating system?

Mac OS X 10.5
Scala code runner version 2.7.7.final -- Copyright 2002-2009, LAMP/EPFL
specs-1.6.2.1.jar

Please provide any additional information below.

Original issue reported on code.google.com by fmpwiz...@gmail.com on 6 May 2010 at 3:56

GoogleCodeExporter commented 9 years ago
You should use Java 6. String.isEmpty doesn't exist on Java5.

Original comment by etorrebo...@gmail.com on 6 May 2010 at 4:06

GoogleCodeExporter commented 9 years ago
This has been a bit fuzzy in the past but I actually think that I'm going to 
deliver 
specs on Java 6 by default from now on (especially since Java 5 has been 
end-of-lifed) 
and I will push a Java 5 compatible release on demand. Do you need one?

Original comment by etorrebo...@gmail.com on 6 May 2010 at 4:41

GoogleCodeExporter commented 9 years ago
on mac 10.5, you can select either 1.5 or 1.6, I made the change to 1.6 and now 
nothing prints to stdout. And if I 
run it under ant  and junit (changing the extend part), I still get the same 
error.

Original comment by fmpwiz...@gmail.com on 6 May 2010 at 12:26

GoogleCodeExporter commented 9 years ago
I think that you've touched the limit of 20 characters after which the detailed 
differences algorithm kicks in to try to show the differences between 2 objects.

I think that this issue should be reproducible just by adding this example:

"this throws an error" in {
  "".isEmpty
}

But I also think that this is a Java 5 vs Java 6 issue (it works ok for me). 
I'm 
pretty sure you're still somehow running Java 5 when you see the same error.

Can you please do more investigation and see if you can reproduce with the 
other 
example I gave you?

Thanks.

Original comment by etorrebo...@gmail.com on 6 May 2010 at 12:59

GoogleCodeExporter commented 9 years ago
Thanks for looking into this. See this sequence:

$ cat bug.scala 
package com.fmpwizard.robot

import org.specs._
import org.specs.runner._

class ParseServerListTest extends Specification {
  "this throws an error" in {
    "".isEmpty
  }

}

$ java -version
java version "1.6.0_17"
Java(TM) SE Runtime Environment (build 1.6.0_17-b04-248-9M3125)
Java HotSpot(TM) 64-Bit Server VM (build 14.3-b01-101, mixed mode)

$ java -cp lib/specs-1.6.2.1.jar:/opt/local/share/scala/lib/scala-library.jar 
run 
com.fmpwizard.robot.ParseServerList
$

As you see, I get no output, but see this:

$ cat bug.scala 
package com.fmpwizard.robot

import org.specs._
import org.specs.runner._

class ParseServerListTest extends Specification {
  "this throws an error" in {
    "".isEmpty
  }

}

$ java -version
java version "1.5.0_22"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0_22-b03-333-9M3125)
Java HotSpot(TM) 64-Bit Server VM (build 1.5.0_22-147, mixed mode)

$ java -cp lib/specs-1.6.2.1.jar:/opt/local/share/scala/lib/scala-library.jar 
run 
com.fmpwizard.robot.ParseServerList
Exception in thread "main" java.lang.NoSuchMethodError: 
java.lang.String.isEmpty()Z
        at org.specs.runner.ClassRunner.fullClassName(ClassRunner.scala:83)
        at org.specs.runner.ClassRunner.createSpecification(ClassRunner.scala:80)
        at org.specs.runner.ClassRunner$$anonfun$3$$anonfun$apply$1.apply(ClassRunner.scala:76)
        at org.specs.runner.ClassRunner$$anonfun$3$$anonfun$apply$1.apply(ClassRunner.scala:75)
        at scala.List.map(List.scala:812)
        at org.specs.runner.ClassRunner$$anonfun$3.apply(ClassRunner.scala:75)
        at org.specs.runner.ClassRunner$$anonfun$3.apply(ClassRunner.scala:74)
        at scala.List.flatMap(List.scala:1132)
        at org.specs.runner.ClassRunner.getSpecifications(ClassRunner.scala:74)
        at org.specs.runner.ClassRunner.specs(ClassRunner.scala:44)
        at org.specs.runner.ClassRunner.main(ClassRunner.scala:51)
        at run.main(run.scala)
$ 

So, using java5 I get the error, using java6 I do not see anything (not even a 
"test pass/fail"

And thanks for explaining why increasing the text length causes an error / no 
error

Original comment by fmpwiz...@gmail.com on 6 May 2010 at 2:33

GoogleCodeExporter commented 9 years ago
So the issue is really now the question of understanding why you get no output. 
Can you 
please re-run your spec like this:

$ java -cp lib/specs-1.6.2.1.jar:/opt/local/share/scala/lib/scala-library.jar -
DdebugCreateObject=true run 
com.fmpwizard.robot.ParseServerList -v

That may print more information.

Original comment by etorrebo...@gmail.com on 6 May 2010 at 8:49

GoogleCodeExporter commented 9 years ago
Thanks for all your help, It turns out I got no output because I forgot to run 
scalac first.
After I did that, using java6 worked fine and java5 gives the error I reported.

Is there a way to use something different that isEmpty, maybe checking the 
.length instead ?

And even though I set java to be 1.6 as the default, ant was still using java5, 
I ended up setting $JAVA_HOME 
to an invalid path to get ant to use the correct one :P

Thanks

Original comment by fmpwiz...@gmail.com on 7 May 2010 at 1:27

GoogleCodeExporter commented 9 years ago
> Is there a way to use something different that isEmpty, maybe checking the 
.length 
instead ?

It is possible but it gives me bad vibes,... Actually the issue really is in 
the 
implementation of isEmpty in the Scala library itself (it is not implemented in 
the 
regular distribution but provided as a RichString method in the Java 5 
distribution). 

You can get more information on that debate from that thread: http://scala-
programming-language.1934581.n4.nabble.com/Targetting-different-JVMs-was-scala-
internals-First-candidate-for-2-8-0-beta-td2006918.html

Original comment by etorrebo...@gmail.com on 7 May 2010 at 4:15

GoogleCodeExporter commented 9 years ago
Just got bit by this bug. Use case: The applications that I am a developer for 
have to target WebSphere Application Server 6.1 at the earliest. WebSphere 
Application Server 6.1 uses IBM's 1.5 JVM.

Are there plans to continue a 2.7.7 line of code with bug fixes which will run 
properly on a 1.5 JVM?

Original comment by nairb...@gmail.com on 6 Aug 2010 at 4:23

GoogleCodeExporter commented 9 years ago
As a side note: I would be happier with a 2.8.0 line of code that works with 
1.5. I am also willing to go through the specs source and make the patches to 
make this a reality.

Original comment by nairb...@gmail.com on 6 Aug 2010 at 4:37

GoogleCodeExporter commented 9 years ago
Hi, I've had some troubles with the jdk on my machine. I'll try to redeploy 
1.5.0 versions for both releases during the week-end if I can fix that.

Original comment by etorrebo...@gmail.com on 7 Aug 2010 at 8:53

GoogleCodeExporter commented 9 years ago
Let me know if there is anything I can do to help. Brian.

Original comment by nairb...@gmail.com on 7 Aug 2010 at 4:44

GoogleCodeExporter commented 9 years ago
Thanks for your help. I've just uploaded a 1.5.0 release for 2.7.7:

http://scala-tools.org/repo-releases/org/scala-tools/testing/specs/1.6.2.2_1.5.0
/

I'll try to do another one for 2.8.0 today.

Original comment by etorrebo...@gmail.com on 7 Aug 2010 at 11:19

GoogleCodeExporter commented 9 years ago
There is now a java 1.5.0 compiled version here: 
http://www.scala-tools.org/repo-snapshots/org/scala-tools/testing/specs_2.8.0/1.
6.6_1.5.0-SNAPSHOT/

Please try it out.

Original comment by etorrebo...@gmail.com on 8 Aug 2010 at 11:17