Skip to content

Illegal field modifiers in class Matchers: 0x9 #5924

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

Closed
liufengyun opened this issue Feb 14, 2019 · 1 comment · Fixed by #5932
Closed

Illegal field modifiers in class Matchers: 0x9 #5924

liufengyun opened this issue Feb 14, 2019 · 1 comment · Fixed by #5932

Comments

@liufengyun
Copy link
Contributor

liufengyun commented Feb 14, 2019

The following code produces a load-time exception:

Exception in thread "main" java.lang.ClassFormatError: Illegal field modifiers in class Matchers: 0x9
	at java.lang.ClassLoader.defineClass1(Native Method)
trait Matchers {
  object Helper
}

object Matchers extends Matchers

object Test {
  def main(args: Array[String]): Unit = Matchers
}
show full log
Exception in thread "main" java.lang.ClassFormatError: Illegal field modifiers in class Matchers: 0x9
	at java.lang.ClassLoader.defineClass1(Native Method)
	at java.lang.ClassLoader.defineClass(ClassLoader.java:763)
	at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
	at java.net.URLClassLoader.defineClass(URLClassLoader.java:467)
	at java.net.URLClassLoader.access$100(URLClassLoader.java:73)
	at java.net.URLClassLoader$1.run(URLClassLoader.java:368)
	at java.net.URLClassLoader$1.run(URLClassLoader.java:362)
	at java.security.AccessController.doPrivileged(Native Method)
	at java.net.URLClassLoader.findClass(URLClassLoader.java:361)
	at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
	at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:335)
	at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
	at java.lang.ClassLoader.defineClass1(Native Method)
	at java.lang.ClassLoader.defineClass(ClassLoader.java:763)
	at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
	at java.net.URLClassLoader.defineClass(URLClassLoader.java:467)
	at java.net.URLClassLoader.access$100(URLClassLoader.java:73)
	at java.net.URLClassLoader$1.run(URLClassLoader.java:368)
	at java.net.URLClassLoader$1.run(URLClassLoader.java:362)
	at java.security.AccessController.doPrivileged(Native Method)
	at java.net.URLClassLoader.findClass(URLClassLoader.java:361)
	at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
	at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:335)
	at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
	at Test$.main(inner.scala:10)
	at Test.main(inner.scala)

This bug is found when working with @cheeseng on ScalaTest macros. Big thanks to @cheeseng for minimizing the problem.

@odersky
Copy link
Contributor

odersky commented Feb 15, 2019

It looks like the culprit is the following field definition in trait Matchers:

@scala.annotation.static() @scala.annotation.static() val OFFSET$_m_0: Long
       = 
    dotty.runtime.LazyVals.getOffset(
      classOf[Object with Matchers with Serializable{...}]
    , "bitmap$0")

The Java spec allows only final static fields in interfaces, but this field is not final.

I am not sure, unfortunately, how to fix this. /cc @DarkDimius

liufengyun added a commit to dotty-staging/dotty that referenced this issue Feb 15, 2019
@liufengyun liufengyun self-assigned this Feb 15, 2019
liufengyun added a commit to dotty-staging/dotty that referenced this issue Feb 15, 2019
liufengyun added a commit to dotty-staging/dotty that referenced this issue Feb 19, 2019
liufengyun added a commit that referenced this issue Feb 19, 2019
Fix #5924: don't move static to interfaces
@liufengyun liufengyun mentioned this issue Mar 19, 2019
66 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants