Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

IncompatibleClassChangeError: SomeClass and SomeClass$$$$anon$$1 disagree on InnerClasses attribute #1167

Closed
scabug opened this issue Aug 3, 2008 · 15 comments
Assignees

Comments

@scabug
Copy link

scabug commented Aug 3, 2008

Compiling and running the attached Scala source (short) yields to this runtime exception,

java.lang.IncompatibleClassChangeError: SimpleName and SimpleName$$$$anon$$1 disagree on InnerClasses attribute
at java.lang.Class.getDeclaringClass(Native Method)
at java.lang.Class.getEnclosingClass(Class.java:1081)
at java.lang.Class.getSimpleBinaryName(Class.java:1216)
at java.lang.Class.getSimpleName(Class.java:1108)
at Foo.toString(SimpleName.scala:3)
at java.lang.String.valueOf(String.java:2615)
at java.io.PrintStream.print(PrintStream.java:616)
at java.io.PrintStream.println(PrintStream.java:753)
at scala.Console$$.println(Console.scala:162)
at scala.Predef$$.println(Predef.scala:156)
at SimpleName$$.(SimpleName.scala:13)
at SimpleName$$.(SimpleName.scala)
at SimpleName.main(SimpleName.scala)

@scabug
Copy link
Author

scabug commented Aug 3, 2008

Imported From: https://issues.scala-lang.org/browse/SI-1167?orig=1
Reporter: @aboisvert
Attachments:

@scabug
Copy link
Author

scabug commented Aug 3, 2008

@aboisvert said:
SimpleName.scala

@scabug
Copy link
Author

scabug commented Aug 3, 2008

Geoffrey Alan Washburn (washburn) said:
I can reproduce this with

class Foo {
  override def toString = getClass.getSimpleName
}

object SimpleName extends Application {
  val foo = new Foo {}
  println(foo)
}

Changing the one line to

  override def toString = classOf[Foo].getSimpleName

Makes the problem go away.

@scabug
Copy link
Author

scabug commented Oct 14, 2009

@jrudolph said:
This was supposedly fixed by r15927. But since the commented code was resurrected in r16328 this bug is reappearing.

Here's a simple example:

trait Test {
 def testFunc(i:Int) = ((i:Int) => i + 5)(i)
}

And here the console session:

Welcome to Scala version 2.7.4.final (OpenJDK 64-Bit Server VM, Java 1.6.0_0).
Type in expressions to have them evaluated.
Type :help for more information.

scala> Class.forName("Test$$$$anonfun$$testFunc$$1")
res0: java.lang.Class[_] = class Test$$$$anonfun$$testFunc$$1

scala> res0.getSimpleName
java.lang.IncompatibleClassChangeError: Test and
Test$$$$anonfun$$testFunc$$1 disagree on InnerClasses attribute
       at java.lang.Class.getDeclaringClass(Native Method)
       at java.lang.Class.getEnclosingClass(Class.java:1102)
       at java.lang.Class.getSimpleBinaryName(Class.java:1237)
       at java.lang.Class.getSimpleName(Class.java:1129)
       at .<init>(<console>:6)
       at .<clinit>(<console>)
       at RequestR...

@scabug
Copy link
Author

scabug commented Oct 14, 2009

@paulp said:
Replying to [comment:4 jrudolph]:

This was supposedly fixed by r15927. But since the commented code was resurrected in r16328 this bug is reappearing.

See also #2083, which to my frustration was closed wontfix. (It also arose in the course of what I think should be safe reflection calls.)

@scabug
Copy link
Author

scabug commented Oct 16, 2009

@jrudolph said:
Replying to [comment:5 extempore]:

See also #2083, which to my frustration was closed wontfix. (It also arose in the course of what I think should be safe reflection calls.)
IMO the general restriction to forbid any types with '$$' in the Scala syntax is reasonable (although, failing with only an assertion isn't). What you experienced here, can only happen to you, because you - as a developer of the interpreter - are the only one who has access to the mighty "eval". And it's only then, that implementation details of the compiler output can feed back into the compiler, isn't it?

@scabug
Copy link
Author

scabug commented Nov 2, 2009

Matt Hellige (hellige) said:
Same problem:

java.lang.IncompatibleClassChangeError: scala.collection.Map and scala.collection.Map$$$$anon$$5 disagree on InnerClasses attribute
	at java.lang.Class.getDeclaringClass(Native Method)
	at java.lang.Class.getEnclosingClass(Class.java:1085)
        [...]

I'm using Google's gson JSON library. AFAICS it's just doing very basic reflection... I might be able to find a workaround, but this problem is pretty serious.

@scabug
Copy link
Author

scabug commented Nov 23, 2009

luxspes said:
I am getting this error if I use a code like this (concatente the contents of a list in a comma separated string) inside a method in my class:

val classNames = Conversions.convertList(names).reduceLeft[String] { (acc, n) =>
        acc + ", " + n
        }	

Apparently this makes the compiler generate an incompatible inner class:

java.lang.IncompatibleClassChangeError: com.googlecode.solder.dwr.WeldContainer and com.googlecode.solder.dwr.WeldContainer$$$$anonfun$$getClasses$$1 disagree on InnerClasses attribute
	at java.lang.Class.getDeclaringClass(Native Method)
	at java.lang.Class.getEnclosingClass(Class.java:1085)
	at java.lang.Class.getSimpleBinaryName(Class.java:1220)
	at java.lang.Class.getSimpleName(Class.java:1112)
	at org.jboss.weld.util.Names.typeToString(Names.java:251)
	at org.jboss.weld.util.Names.classToString(Names.java:263)
	at org.jboss.weld.introspector.jlr.WeldClassImpl.<init>(WeldClassImpl.java:151)
	at org.jboss.weld.introspector.jlr.WeldClassImpl.of(WeldClassImpl.java:133)
	at org.jboss.weld.resources.ClassTransformer$$2.call(ClassTransformer.java:72)
	at org.jboss.weld.resources.ClassTransformer$$2.call(ClassTransformer.java:68)
	at java.util.concurrent.FutureTask$$Sync.innerRun(FutureTask.java:303)
	at java.util.concurrent.FutureTask.run(FutureTask.java:138)
	at org.jboss.weld.util.collections.ConcurrentCache.putIfAbsent(ConcurrentCache.java:125)
	at org.jboss.weld.resources.ClassTransformer.loadClass(ClassTransformer.java:67)
	at org.jboss.weld.bootstrap.BeanDeployer.addClass(BeanDeployer.java:59)
	at org.jboss.weld.bootstrap.BeanDeployer.addClasses(BeanDeployer.java:86)
	at org.jboss.weld.bootstrap.BeanDeployment.deployBeans(BeanDeployment.java:134)
	at org.jboss.weld.bootstrap.WeldBootstrap.deployBeans(WeldBootstrap.java:367)
	at org.jboss.weld.environment.servlet.Listener.contextInitialized(Listener.java:158)
	at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:3843)
	at org.apache.catalina.core.StandardContext.start(StandardContext.java:4342)
	at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1045)
	at org.apache.catalina.core.StandardHost.start(StandardHost.java:719)
	at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1045)
	at org.apache.catalina.core.StandardEngine.start(StandardEngine.java:443)
	at org.apache.catalina.core.StandardService.start(StandardService.java:516)
	at org.apache.catalina.core.StandardServer.start(StandardServer.java:710)
	at org.apache.catalina.startup.Catalina.start(Catalina.java:578)
	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 org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:288)
	at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:413)

I guess this means Weld (JSR-299) and Scala are not compatible. Please fix this!

@scabug
Copy link
Author

scabug commented Nov 24, 2009

Seto (seto) said:
No planning about fixing it?
I'm using it with Weld too. I met this error as well.

@scabug
Copy link
Author

scabug commented Nov 24, 2009

@scabug
Copy link
Author

scabug commented Nov 26, 2009

@dragos said:
Hm, can someone please post a reproducible, self-contain test case? I could not reproduce it with any of the examples in the comments, nor the initial program. It's ok if I need some 3rd party library, but please post a program that compiles (nobody here ever used Weld, so I can't come up with something 'basic' any time soon).

@scabug
Copy link
Author

scabug commented Nov 26, 2009

@jrudolph said:
I posted some pretty full disclosure about my findings in comment:4. The problem was fixed the first time in r15927, when two lines were commented out. In r16328 the lines were resurrected. Perhaps you can remember why you've done that?

You may want to look into the [http://old.nabble.com/Re%3A-Scala-Interpreter-Oddity----General-Class-Name-Curio-p25869373.html mailing-list post] which contains more information.

And here, again my example:

Put that into test.scala:

trait Test {
 def testFunc(i:Int) = ((i:Int) => i + 5)(i)
}

Then, do:

% ~/downloads/sources/scala-2.8.0.r19722-b20091119020248/bin/scalac test.scala
% ~/downloads/sources/scala-2.8.0.r19722-b20091119020248/bin/scala -e 'Class.forName("Test$$$$anonfun$$testFunc$$1").getSimpleName'
java.lang.IncompatibleClassChangeError: Test and Test$$$$anonfun$$testFunc$$1 disagree on InnerClasses attribute
	at java.lang.Class.getDeclaringClass(Native Method)
	at java.lang.Class.getEnclosingClass(Class.java:1102)
	at java.lang.Class.getSimpleBinaryName(Class.java:1237)
	at java.lang.Class.getSimpleName(Class.java:1129)
	at Main$$$$anon$$1.<init>((virtual file):6)
	at Main$$.main((virtual file):5)
	at Main.main((virtual file))
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:616)
	at scala.tools.nsc.util.ScalaClassLoader$$$$anonfun$$run$$1.apply(ScalaClassLoader.scala:55)
	at scala.tools.nsc.util.ScalaClassLoader$$class.asContext(ScalaClassLoader.scala:22)
	at scala.tools.nsc.util.ScalaClassLoader$$URLClassLoader.asContext(ScalaClassLoader.scala:61)
	at scala.tools.nsc.util.ScalaClassLoader$$class.run(ScalaClassLoader.scala:55)
	at scala.tools.nsc.util.ScalaClassLoader$$URLClassLoader.run(ScalaClassLoader.scala:61)
	at scala.tools.nsc.ScriptRunner$$.scala$$tools$$nsc$$ScriptRunner$$$$runCompiled(ScriptRunner.scala:326)
	at scala.tools.nsc.ScriptRunner$$$$anonfun$$runCommand$$1.apply(ScriptRunner.scala:371)
	at scala.tools.nsc.ScriptRunner$$$$anonfun$$runCommand$$1.apply(ScriptRunner.scala:371)
	at scala.tools.nsc.ScriptRunner$$$$anonfun$$withCompiledScript$$1.apply(ScriptRunner.scala:298)
	at scala.tools.nsc.ScriptRunner$$$$anonfun$$withCompiledScript$$1.apply(ScriptRunner.scala:298)
	at scala.Option.map(Option.scala:74)
	at scala.tools.nsc.ScriptRunner$$.withCompiledScript(ScriptRunner.scala:298)
	at scala.tools.nsc.ScriptRunner$$.runCommand(ScriptRunner.scala:371)
	at scala.tools.nsc.MainGenericRunner$$.main(MainGenericRunner.scala:140)
	at scala.tools.nsc.MainGenericRunner.main(MainGenericRunner.scala)

@scabug
Copy link
Author

scabug commented Nov 26, 2009

@dragos said:
(In r19895) Fixed #1167.

@scabug
Copy link
Author

scabug commented Nov 26, 2009

@dragos said:
Sorry, I didn't follow the whole interpreter session, I stopped at forName. Anyway, that one is fixed, let's hope it's the same bug the Weld guys are hitting.

@scabug scabug closed this as completed May 18, 2011
@scabug
Copy link
Author

scabug commented Aug 15, 2011

@jsuereth said:
Note, you can reproduce this bug in JAVA by changing source and target versions.

Using the following JDK:

java version "1.6.0_22"
OpenJDK Runtime Environment (IcedTea6 1.10.2) (6b22-1.10.2-0ubuntu1~11.04.1)
OpenJDK 64-Bit Server VM (build 20.0-b11, mixed mode)

I was able to induce this error with a simple static final Nested class with both -source and -target set to 1.5. Looks like we're not alone in the insanity.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants