Compile error with Java 26 - Ordering inherits conflicting members
This code doesn't compile with the latest builds of JDK 26:
https://github.com/FasterXML/jackson-module-scala/blob/3bdeb0846ee135529714dae4dd6d410efe7e4ee2/src/main/scala/com/fasterxml/jackson/module/scala/introspect/OrderingLocator.scala#L31-L34
A recent JDK change JDK-8357219: Provide default methods min(T, T) and max(T, T) in Comparator interface adds default methods named min and max to the Comparator interface, which clash with existing methods inherited in Ordering, and cause the following error:
com/fasterxml/jackson/module/scala/introspect/OrderingLocator.scala:31: error: <$anon: Ordering[T]> inherits conflicting members:
<defaultmethod> def max[U <: T](o1: U, o2: U): U (defined in trait Comparator) and
def max[U <: T](x: U, y: U): U (defined in trait Ordering)
(note: this can be resolved by declaring an `override` in <$anon: Ordering[T]>.);
other members with override errors are: min
new Ordering[T] {
^
1 error
One possible fix is to explicitly declare min and max methods in the Ordering implementation, with the same behaviour as the conflicting inherited methods:
new Ordering[T] {
+ override def min[U <: T](x: U, y: U): U = if (compare(x, y) < 0) x else y
+ override def max[U <: T](x: U, y: U): U = if (compare(x, y) > 0) x else y
def compare(x: T, y: T): Int = {
x.asInstanceOf[Comparable[T]].compareTo(y)
}
}
I'm not going to worry about this until Java 26, a non-LTS release that is months away from GA, is officially released. Scala releases in the mean time may make adjustments that alleviate this.
Releases are built with Java 8 (Jackson 2) and Java 17 (Jackson 3). It could be many years until releases are done with Java 26+. A bigger issue is if the pre-built released jars don't work with Java 26 ea.
@cushon do you know if this has been reported to Scala 2 and 3 teams? It would be better, as far as I am concerned if the Scala Ordering trait (or class), implemented the max and min functions by default.