- About Scala
- Documentation
- Code Examples
- Software
- Scala Developers
Incompatible Class Change Error on Set Difference
Fri, 2011-10-07, 17:52
Hi All,
It's been some time ago, but I have encountered a new problem that I
didn't find a solution for.
I have 2 Set[String] instances and try to take the difference with
&~. The code compiles fine
(with 2.9.1). When I run it, I get:
java.lang.IncompatibleClassChangeError: Class
scala.collection.immutable.Set$Set3 does not implement the requested
interface scala.collection.GenSetLike
The sets have been created by calling toSet on some List.
So I tried to use immutable HashSets instead, but when adding the
contents of my lists to
empty HashSets I get this exception:
java.lang.NoSuchMethodError: scala.collection.immutable.HashSet
$.apply(Lscala/collection/Seq;)Lscala/collection/GenTraversable;
Again, the code compiled fine.
Guess I ran into a 2.9.1 bug. Is there a workaround? I haven't found
it yet :-(
Job Honig
Fri, 2011-10-07, 18:47
#2
Re: Incompatible Class Change Error on Set Difference
Sounds like you're executing against old libraries on the classpath. The following breaks with something like this:
java -classpath ".;O:/scala-2.8.1/lib/scala-library.jar;O:/scala-2.9.1.final/lib/scala-library.jar" Sets
WFM on 2.9.1, with 3 elements;
object Sets {
def main(args: Array[String]) {
val one = List(1,2,3)
val two = List(2,3,4)
val result = one.toSet &~ two.toSet
println(result.toString)
val three = List("one","two","three")
val four = List("two","three","four")
val another = three.toSet &~ four.toSet
println(another.toString)
}
}
On Fri, Oct 7, 2011 at 9:52 AM, jhonig <joho@xs4all.nl> wrote:
java -classpath ".;O:/scala-2.8.1/lib/scala-library.jar;O:/scala-2.9.1.final/lib/scala-library.jar" Sets
WFM on 2.9.1, with 3 elements;
object Sets {
def main(args: Array[String]) {
val one = List(1,2,3)
val two = List(2,3,4)
val result = one.toSet &~ two.toSet
println(result.toString)
val three = List("one","two","three")
val four = List("two","three","four")
val another = three.toSet &~ four.toSet
println(another.toString)
}
}
On Fri, Oct 7, 2011 at 9:52 AM, jhonig <joho@xs4all.nl> wrote:
Hi All,
It's been some time ago, but I have encountered a new problem that I
didn't find a solution for.
I have 2 Set[String] instances and try to take the difference with
&~. The code compiles fine
(with 2.9.1). When I run it, I get:
java.lang.IncompatibleClassChangeError: Class
scala.collection.immutable.Set$Set3 does not implement the requested
interface scala.collection.GenSetLike
The sets have been created by calling toSet on some List.
So I tried to use immutable HashSets instead, but when adding the
contents of my lists to
empty HashSets I get this exception:
java.lang.NoSuchMethodError: scala.collection.immutable.HashSet
$.apply(Lscala/collection/Seq;)Lscala/collection/GenTraversable;
Again, the code compiled fine.
Guess I ran into a 2.9.1 bug. Is there a workaround? I haven't found
it yet :-(
Job Honig
Fri, 2011-10-07, 18:47
#3
Re: Incompatible Class Change Error on Set Difference
> Sounds like you're executing against old libraries on the classpath. The
> following breaks with something like this:
> java -classpath
> ".;O:/scala-2.8.1/lib/scala-library.jar;O:/scala-2.9.1.final/lib/scala-libr
> ary.jar" Sets
>
I have heard this before. I'm compiling from Maven and ALL my version
numbers in the POM point to 2.9.1, I'm 100% sure of that.
Job
Fri, 2011-10-07, 18:57
#4
Re: Incompatible Class Change Error on Set Difference
Hi Simon,
> I tried List("a", "b").toSet &~ List("b", "c").toSet but couldn't verify
> your problem on 2.10.0.r25789-b20111005020219.
>
> Could you assemble a small code example?
I will try later tonight.
Job Honig
Fri, 2011-10-07, 19:57
#5
Re: Incompatible Class Change Error on Set Difference
Hi All,
> I tried List("a", "b").toSet &~ List("b", "c").toSet but couldn't verify
> your problem on 2.10.0.r25789-b20111005020219.
>
> Could you assemble a small code example?
I now have this:
package org.jhonig.psdevs.lang.parser;
object Test
{
private def test ()
{
val theRelationVars : Set[String] = List ("a", "b", "c").toSet;
val theVariableVars : Set[String] = List ("a", "b", "c").toSet;
System.err.println ("Vars 1 = " + theRelationVars.mkString (", "));
System.err.println ("Vars 2 = " + theVariableVars.mkString (", "));
val theExcessRelationVars : Set[String]
= theRelationVars &~ theVariableVars;
System.err.println ("Difference 1 = " + theExcessRelationVars.mkString
(", "));
val theExcessVariableVars : Set[String]
= theVariableVars &~ theRelationVars;
System.err.println ("Difference 2 = " + theExcessVariableVars.mkString
(", "));
System.err.println ("Finished test");
}
def main (args : Array[String])
{
test ();
}
}
Running it gives:
Vars 1 = a, b, c
Vars 2 = a, b, c
java.lang.IncompatibleClassChangeError: Class
scala.collection.immutable.Set$Set3 does not implement the requested interface
scala.collection.GenSetLike
at org.jhonig.psdevs.lang.parser.Test$.test(Test.scala:19)
at org.jhonig.psdevs.lang.parser.Test$.main(Test.scala:29)
at org.jhonig.psdevs.lang.parser.Test.main(Test.scala)
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.util.ScalaClassLoader$$anonfun$run$1.apply(ScalaClassLoader.scala:81)
at
scala.tools.nsc.util.ScalaClassLoader$class.asContext(ScalaClassLoader.scala:24)
at
scala.tools.nsc.util.ScalaClassLoader$URLClassLoader.asContext(ScalaClassLoader.scala:86)
at
scala.tools.nsc.util.ScalaClassLoader$class.run(ScalaClassLoader.scala:81)
at
scala.tools.nsc.util.ScalaClassLoader$URLClassLoader.run(ScalaClassLoader.scala:86)
at scala.tools.nsc.MainGenericRunner$.main(MainGenericRunner.scala:83)
at scala.tools.nsc.MainGenericRunner.main(MainGenericRunner.scala)
I run with:
scala -cp "target/classes:/home/joho/.m2/repository/org/scala-lang/scala-
library/2.9.1/scala-library-2.9.1.jar" org.jhonig.psdevs.lang.parser.Test
So there's a problem with the library-2.9.1.jar???
Job H.
Fri, 2011-10-07, 20:17
#6
Re: Incompatible Class Change Error on Set Difference
Hi All,
Sorry to follow up on my own post. I compiled the same code with
scalac and it runs okay.
When compiled with mvn scala:compile I get the error... I removed ALL
NON-2.9.1 jars
from my local .m2/repository before trying that....
Job
Fri, 2011-10-07, 22:57
#7
Re: Re: Incompatible Class Change Error on Set Difference
Hi Job,
Would you mind dumping your code that does this into a github project? That way we can check it out, build with scalac vs maven and see if we get the same errors.
Thanks,
Matthew
On 7 October 2011 20:01, jhonig <joho@xs4all.nl> wrote:
--
Dr Matthew PocockIntegrative Bioinformatics Group, School of Computing Science, Newcastle Universitymailto: turingatemyhamster@gmail.com gchat: turingatemyhamster@gmail.commsn: matthew_pocock@yahoo.co.uk irc.freenode.net: drdozertel: (0191) 2566550mob: +447535664143
Would you mind dumping your code that does this into a github project? That way we can check it out, build with scalac vs maven and see if we get the same errors.
Thanks,
Matthew
On 7 October 2011 20:01, jhonig <joho@xs4all.nl> wrote:
Hi All,
Sorry to follow up on my own post. I compiled the same code with
scalac and it runs okay.
When compiled with mvn scala:compile I get the error... I removed ALL
NON-2.9.1 jars
from my local .m2/repository before trying that....
Job
--
Dr Matthew PocockIntegrative Bioinformatics Group, School of Computing Science, Newcastle Universitymailto: turingatemyhamster@gmail.com gchat: turingatemyhamster@gmail.commsn: matthew_pocock@yahoo.co.uk irc.freenode.net: drdozertel: (0191) 2566550mob: +447535664143
Sat, 2011-10-08, 15:07
#8
Re: Incompatible Class Change Error on Set Difference
Hi Matthew,
Thanks to Paul Phillips, I found out that there was indeed another
version of
Scala on my system. So when compiling with Maven, I got another
version
than when running the compiled program. That solved the problem.
Thanks all for responding!
Job Honig
On Oct 7, 11:51 pm, Matthew Pocock
wrote:
> Hi Job,
>
> Would you mind dumping your code that does this into a github project? That
> way we can check it out, build with scalac vs maven and see if we get the
> same errors.
>
> Thanks,
>
> Matthew
>
> On 7 October 2011 20:01, jhonig wrote:
>
> > Hi All,
>
> > Sorry to follow up on my own post. I compiled the same code with
> > scalac and it runs okay.
> > When compiled with mvn scala:compile I get the error... I removed ALL
> > NON-2.9.1 jars
> > from my local .m2/repository before trying that....
>
> > Job
>
> --
> Dr Matthew Pocock
> Integrative Bioinformatics Group, School of Computing Science, Newcastle
> University
> mailto: turingatemyhams...@gmail.com
> gchat: turingatemyhams...@gmail.com
> msn: matthew_poc...@yahoo.co.uk
> irc.freenode.net: drdozer
> tel: (0191) 2566550
> mob: +447535664143
I tried List("a", "b").toSet &~ List("b", "c").toSet but couldn't verify your problem on 2.10.0.r25789-b20111005020219.
Could you assemble a small code example?
Thanks,
Simon