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

java.lang.VerifyError: overriding final method #1055

Closed
scabug opened this issue Jun 18, 2008 · 3 comments
Closed

java.lang.VerifyError: overriding final method #1055

scabug opened this issue Jun 18, 2008 · 3 comments

Comments

@scabug
Copy link

scabug commented Jun 18, 2008

All with 2.7.1.final.

The following code generates the below stack trace at run time:

object ArrayBuffer
{
  def empty[T](i : Int) = new scala.collection.mutable.ArrayBuffer[T] {
    override val initialSize = i
  }
}

object Test extends Application
{
  val ab = ArrayBuffer.empty(10)
}
java.lang.VerifyError: class ArrayBuffer$$$$anon$$1 overrides final method initialSize.()I
        at java.lang.ClassLoader.defineClass1(Native Method)
        at java.lang.ClassLoader.defineClass(ClassLoader.java:620)
        at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:124)
        at java.net.URLClassLoader.defineClass(URLClassLoader.java:260)
        at java.net.URLClassLoader.access$$000(URLClassLoader.java:56)
        at java.net.URLClassLoader$$1.run(URLClassLoader.java:195)
        at java.security.AccessController.doPrivileged(Native Method)
        at java.net.URLClassLoader.findClass(URLClassLoader.java:188)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:251)
        at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:319)
        at Test$$.<init>(t.scala:10)
        at Test$$.<clinit>(t.scala)
        at Test.main(t.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)
        at scala.tools.nsc.ObjectRunner$$$$anonfun$$run$$1.apply(ObjectRunner.scala:75)
        at scala.tools.nsc.ObjectRunner$$.withContextClassLoader(ObjectRunner.scala:49)
        at scala.tools.nsc.ObjectRunner$$.run(ObjectRunner.scala:74)
        at scala.tools.nsc.MainGenericRunner$$.main(MainGenericRunner.scala:161)
        at scala.tools.nsc.MainGenericRunner.main(MainGenericRunner.scala)

The compiler should not generate code that generates a java.lang.VerifyError.

I'm was surpised to see that initialSize is not declared final in the
Scala library source code anywhere but the Java class file has it as final:

$$ javap -classpath scala-library.jar scala.collection.mutable.ArrayBuffer | grep initial
    public final void initialSize_$$eq(int);
    public final int initialSize();

So I guess the two choices are, disallow overriding initialSize or make
the initialSize() method non-final, I would prefer the later, otherwise
I have no way of creating an ArrayBuffer that is sized to what will be
added into it. If I can't do this, then ArrayBuffer will reallocate
quite often for any decently sized inputs.

@scabug
Copy link
Author

scabug commented Jun 18, 2008

Imported From: https://issues.scala-lang.org/browse/SI-1055?orig=1
Reporter: @blair

@scabug
Copy link
Author

scabug commented Jun 18, 2008

Geoffrey Alan Washburn (washburn) said:
Duplicate of #1037. Please check for existing tickets before opening a new one.

@scabug
Copy link
Author

scabug commented Jun 18, 2008

@blair said:
Sorry about that, I'll check in the future.

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

1 participant