Skip to content

Scala 2.10.7 and 2.11.12 regression: VerifyError when overriding a Java-defined default method #10609

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
sjrd opened this issue Nov 14, 2017 · 4 comments
Assignees

Comments

@sjrd
Copy link
Member

sjrd commented Nov 14, 2017

Reproduction:

import java.{util => ju}

class DefaultMethodsTest {
  def canOverrideDefaultMethod(): Unit = {
    var counter = 0

    class SpecialIntComparator extends ju.Comparator[Int] {
      def compare(o1: Int, o2: Int): Int =
        o1.compareTo(o2)

      override def reversed(): ju.Comparator[Int] = {
        counter += 1
        super.reversed()
      }
    }

    val c = new SpecialIntComparator
    assert(c.compare(5, 7) < 0)
    assert(0 == counter)

    val reversed = c.reversed()
    assert(1 == counter)
    assert(reversed.compare(5, 7) > 0)
  }
}

object Test {
  def main(args: Array[String]) {
    new DefaultMethodsTest().canOverrideDefaultMethod()
  }
}

In all cases, I build on Java 8 via sbt 0.13.16 (empty build except for scalaVersion := "...").

Using any version of Scala since 2.10.2 and until 2.12.4, except 2.10.7 and 2.11.12, the above .scala source compiles and runs without error.

When using 2.10.7 or 2.11.12, running causes the following VerifyError:

[info] Running Test
[error] (run-main-4) java.lang.VerifyError: Illegal type at constant pool entry 51 in class DefaultMethodsTest$SpecialIntComparator$1
[error] Exception Details:
[error]   Location:
[error]     DefaultMethodsTest$SpecialIntComparator$1.reversed()Ljava/util/Comparator; @17: invokespecial
[error]   Reason:
[error]     Constant pool index 51 is invalid
[error]   Bytecode:
[error]     0x0000000: 2ab4 002c 2ab4 002c b400 3104 60b5 0031
[error]     0x0000010: 2ab7 0033 b0
java.lang.VerifyError: Illegal type at constant pool entry 51 in class DefaultMethodsTest$SpecialIntComparator$1
Exception Details:
  Location:
    DefaultMethodsTest$SpecialIntComparator$1.reversed()Ljava/util/Comparator; @17: invokespecial
  Reason:
    Constant pool index 51 is invalid
  Bytecode:
    0x0000000: 2ab4 002c 2ab4 002c b400 3104 60b5 0031
    0x0000010: 2ab7 0033 b0

        at DefaultMethodsTest.canOverrideDefaultMethod(Test.scala:17)
        at Test$.main(Test.scala:29)
        at Test.main(Test.scala)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.lang.reflect.Method.invoke(Method.java:497)

This is a test case part of the Scala.js test suite. It is part of the cross-compiled tests that we run both on JS and on the JVM. The community build does not include the JVM version (testSuiteJVM/test) but only the JS version (testSuite/test) which explains why it was not discovered there.

@retronym
Copy link
Member

Can you report whether this problem persists if you use -target:jvm-1.8?

@sjrd
Copy link
Member Author

sjrd commented Nov 28, 2017

You're right. -target:jvm-1.8 solves the issue both in 2.10.7 and 2.11.12.

Feel free to close this issue if that's expected.

@retronym
Copy link
Member

retronym commented Nov 28, 2017

I added a compiler error in the pre-2.12 compiler version when attempting to call an interface method without -jvm:1.8. Maybe that missed out on detecting super calls? I'll leave this ticket open until I figure that out.

@SethTisue
Copy link
Member

Closing since it seems increasingly unlikely there will ever be a 2.11.13.

@SethTisue SethTisue removed this from the 2.11.13 milestone Apr 25, 2022
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