Integrated: 8365676: javac incorrectly allows calling interface static method via type variable

Chen Liang liach at openjdk.org
Wed Sep 10 21:28:18 UTC 2025


On Sat, 30 Aug 2025 00:37:44 GMT, Chen Liang <liach at openjdk.org> wrote:

> The interface static methods added in Java 8 are never inherited in method resolution. However, javac incorrectly allowed them to be resolved against type variables with an interface as its only upper bound, which violates JLS 4.9:
> 
>> The members of an intersection type are the members of the class or interface it induces.
> 
> Combined with JLS 4.4:
> 
>> The members of a type variable X with bound T & I1 & ... & In are the members of the intersection type ([§4.9](https://docs.oracle.com/javase/specs/jls/se24/html/jls-4.html#jls-4.9)) T & I1 & ... & In appearing at the point where the type variable is declared
> 
> Last time this piece of code in Attr was updated was around Java 7, so this was probably missed in Java 8.
> 
> The test cases added showcases wrong ways to refer to interface static methods: `Collator`, a subtype of `Comparator`, cannot use `reverseOrder`, so shouldn't type variable `T` bounded by `Comparator<Integer>` be able to do so.
> 
> In addition, the error for private member access on type variables should probably have been symbol not found instead of access errors - we might revisit that later. I made the new error symbol not found for parity with interface static reference on classes, as showcased in the compiler output in this new test.

This pull request has now been integrated.

Changeset: 85996572
Author:    Chen Liang <liach at openjdk.org>
URL:       https://git.openjdk.org/jdk/commit/85996572b61e789d7e45bd26b23d233a0a41e158
Stats:     37 lines in 3 files changed: 34 ins; 0 del; 3 mod

8365676: javac incorrectly allows calling interface static method via type variable

Co-authored-by: Maurizio Cimadamore <mcimadamore at openjdk.org>
Reviewed-by: vromero

-------------

PR: https://git.openjdk.org/jdk/pull/27015


More information about the compiler-dev mailing list