Skip to content

ClassFormatError using specialized annotation #7288

@scabug

Description

@scabug

It seems that the scala compiler is generating multiple equals methods with the same signature. First of all here is a toy code sample that reproduces the issue:

trait TestTrait[@specialized(Double) T] {
    var array: Array[T] = null
}

class MyClass extends TestTrait[Double] {
    array = new Array[Double](0)
}

val tst = new MyClass

This program compiles correctly using the scala compiler, however upon instantiation of MyClass at run time, the class loader throws the following exception:

java.lang.ClassFormatError: Duplicate method name&signature in class file Main$$anon$1$MyClass
	at java.lang.ClassLoader.defineClass1(Native Method)
	at java.lang.ClassLoader.defineClassCond(ClassLoader.java:631)
	at java.lang.ClassLoader.defineClass(ClassLoader.java:615)
	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)

Running javap shows the following duplicate method has been generated:

$ javap MyClass.class | sort | uniq -d
output: public void array_$eq(java.lang.Object);

Additionally using JAD to decompile the class shows the source of the two methods:

public void array_$eq(Object x$1)
{
    array = (double[])x$1;
}

public volatile void array_$eq(Object x$1)
{
    array_$eq((double[])x$1);
}

FYI: I don't think this is a blocker, it's my first time filing an issue, and I was unable to change the default priority.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions