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

Illegal field modifiers in class: 0x11 when referencing value from surrounding scope from inner trait/class of a trait. #7970

Closed
scabug opened this issue Nov 14, 2013 · 5 comments

Comments

@scabug
Copy link

scabug commented Nov 14, 2013

This only happens if Outer is a trait. If it is a class it runs fine. Also session has to be a value of a block of lambda function for it to happen.

Reproduce code:

object IllegalFieldModifiers extends App {
  {
    val session = null
    trait Outer{
      trait Inner{
        session
      }          
    }
    new Outer{}
  }
}

Expected result:
(Compiles and runs fine) or fails statically.

Actual result:
Compiles fine, but leads to runtime exception:

java.lang.ClassFormatError: Illegal field modifiers in class IllegalFieldModifiers$Outer$1: 0x11
	at java.lang.ClassLoader.defineClass1(Native Method)
	at java.lang.ClassLoader.defineClassCond(ClassLoader.java:637)
	at java.lang.ClassLoader.defineClass(ClassLoader.java:621)
	at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:141)
	at java.net.URLClassLoader.defineClass(URLClassLoader.java:283)
	at java.net.URLClassLoader.access$000(URLClassLoader.java:58)
	at java.net.URLClassLoader$1.run(URLClassLoader.java:197)
	at java.security.AccessController.doPrivileged(Native Method)
	at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
	at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
	at java.lang.ClassLoader.loadClass(ClassLoader.java:247)
	at java.lang.ClassLoader.defineClass1(Native Method)
	at java.lang.ClassLoader.defineClassCond(ClassLoader.java:637)
	at java.lang.ClassLoader.defineClass(ClassLoader.java:621)
	at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:141)
	at java.net.URLClassLoader.defineClass(URLClassLoader.java:283)
	at java.net.URLClassLoader.access$000(URLClassLoader.java:58)
	at java.net.URLClassLoader$1.run(URLClassLoader.java:197)
	at java.security.AccessController.doPrivileged(Native Method)
	at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
	at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
	at java.lang.ClassLoader.loadClass(ClassLoader.java:247)
	at IllegalFieldModifiers$.<init>(NyScala2013.scala:9)
	at IllegalFieldModifiers$.<clinit>(NyScala2013.scala)
	at IllegalFieldModifiers.main(NyScala2013.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)
@scabug
Copy link
Author

scabug commented Nov 14, 2013

Imported From: https://issues.scala-lang.org/browse/SI-7970?orig=1
Reporter: @cvogt
Affected Versions: 2.9.3, 2.10.3, 2.11.0-M6
See #6231

@scabug
Copy link
Author

scabug commented Nov 6, 2014

@retronym said:
Related to #6231. We end up generating a JVM field for session in an the interface for Outer!

@scabug
Copy link
Author

scabug commented Nov 6, 2014

@retronym said:
Here's a way to look at what goes wrong here:

https://gist.github.com/retronym/808f230eaa79ab03c6c7

I compare the progression of the AST for test cases that vary in whether Outer is a class or a trait.

@som-snytt
Copy link

Verified broken on 2.11, works on 2.12. But did not look at why. 2.12 has the lambda change?

@joroKr21
Copy link
Member

2.12 had trait encoding changes for Java 8

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

No branches or pull requests

5 participants