Skip to content

Bad class file due to value with constant type that overrides a specialized trait method #9486

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
scabug opened this issue Sep 24, 2015 · 3 comments

Comments

@scabug
Copy link

scabug commented Sep 24, 2015

trait A[@specialized(Int) T] {
  def f: T = ???
}

object B extends A[Int] {
  override final val f = 0
}

will cause the following error when B is loaded:

Exception in thread "main" java.lang.ClassFormatError: Duplicate method name&signature in class file test/B$
	at java.lang.ClassLoader.defineClass1(Native Method)
	at java.lang.ClassLoader.defineClass(ClassLoader.java:760)
	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:331)
	at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
	at java.lang.Class.getDeclaredMethods0(Native Method)
	at java.lang.Class.privateGetDeclaredMethods(Class.java:2701)
	at java.lang.Class.privateGetMethodRecursive(Class.java:3048)
	at java.lang.Class.getMethod0(Class.java:3018)
	at java.lang.Class.getMethod(Class.java:1784)
	at com.intellij.rt.execution.application.AppMain.main(AppMain.java:125)

Interestingly, if we removed the "final" marker in object B, the code will run properly.

@scabug
Copy link
Author

scabug commented Sep 24, 2015

Imported From: https://issues.scala-lang.org/browse/SI-9486?orig=1
Reporter: Tongfei Chen (ctongfei)
Affected Versions: 2.11.7, 2.12.0-M2

@scabug
Copy link
Author

scabug commented Sep 25, 2015

@soc said (edited on Sep 25, 2015 5:04:25 PM UTC):
My first guess¹ would be that this is caused by the compiler's behavior of treating definitions of values with literals as constant types: some check in an earlier phase doesn't take this into account and then in the backend the constant type is again erased to the same signature as the other method from the parent.

¹ adding a type ascription also "fixes" the crash

@SethTisue SethTisue added this to the Backlog milestone Mar 3, 2018
@som-snytt
Copy link

duplicated by #12301

@SethTisue SethTisue removed this from the Backlog milestone Apr 30, 2025
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

3 participants