RFR: 8365676: javac incorrectly allows calling interface static method via type variable [v2]

Chen Liang liach at openjdk.org
Wed Sep 3 21:07:48 UTC 2025


> 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.

Chen Liang has updated the pull request with a new target base due to a merge or a rebase. The incremental webrev excludes the unrelated changes brought in by the merge/rebase. The pull request contains three additional commits since the last revision:

 - Break up long conditional, add intersection bounded test case
 - Merge branch 'master' of https://github.com/openjdk/jdk into fix/typevar-inherit-interface-static
 - 8365676: javac incorrectly allows calling interface static method via type variable

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

Changes:
  - all: https://git.openjdk.org/jdk/pull/27015/files
  - new: https://git.openjdk.org/jdk/pull/27015/files/266dc4c3..c3abc487

Webrevs:
 - full: https://webrevs.openjdk.org/?repo=jdk&pr=27015&range=01
 - incr: https://webrevs.openjdk.org/?repo=jdk&pr=27015&range=00-01

  Stats: 7304 lines in 671 files changed: 4112 ins; 1396 del; 1796 mod
  Patch: https://git.openjdk.org/jdk/pull/27015.diff
  Fetch: git fetch https://git.openjdk.org/jdk.git pull/27015/head:pull/27015

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


More information about the compiler-dev mailing list