Skip to content

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

@rrramiro

Description

@rrramiro

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/JayfF4WNRJSGZiBN8v0Atw/7

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

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions