scala / scala3

The Scala 3 compiler, also known as Dotty.
https://dotty.epfl.ch
Apache License 2.0
5.84k stars 1.05k forks source link

`getGenericInterfaces` and `getInterfaces` are not the same length after extending a generic Java class #21177

Open rrramiro opened 3 months ago

rrramiro commented 3 months ago

We would like to implement a custom storage provider for Keycloak with scala3. But we have a ArrayIndexOutOfBoundsException on startup. Because getGenericInterfaces and getInterfaces are not the same length.

https://scastie.scala-lang.org/rrramiro/3ILQIagATpCd9fQQGuLLmQ/1

Compiler version

version >= 3.0.0

Minimized code

public interface BaseRootJava  {
    default void someMethod() {
    }
}
public interface GenericBaseIntermidiateJava<T> extends BaseRootJava {
}
class ChildScala extends GenericBaseIntermidiateJava[Int] {
}
object Main {
  def main(args: Array[String]): Unit = {
    val c = classOf[ChildScala]
    assert(
      c.getGenericInterfaces.length == c.getInterfaces.length,
      s"mismatch between ${c.getGenericInterfaces.mkString("Array(", ", ", ")")} and ${c.getInterfaces.mkString("Array(", ", ", ")")}"
    )
  }
}

Output

Exception in thread "main" java.lang.AssertionError: assertion failed: mismatch between Array(org.example.GenericBaseIntermidiateJava<java.lang.Object>) and Array(interface org.example.BaseRootJava, interface org.example.GenericBaseIntermidiateJava)

Expectation

The size of getGenericInterfaces and getInterfaces should be equal according to this test: https://github.com/scala/scala3/blob/main/tests/run/t8931.scala

Gedochao commented 3 months ago

This seems to indeed work differently from Scala 2... c.getGenericInterfaces.length == c.getInterfaces.length is true for 2.13.14 😕 We may need a smaller minimization outside of the keycloak dependencies.

rrramiro commented 3 months ago

@Gedochao I updated the issue with a smaller minimization. Sorry I didn't do it before.