JDK-8365676 : javac incorrectly allows calling interface static method via type variable
  • Type: Bug
  • Component: tools
  • Sub-Component: javac
  • Affected Version: 8,25,26
  • Priority: P4
  • Status: In Progress
  • Resolution: Unresolved
  • OS: generic
  • CPU: generic
  • Submitted: 2025-08-18
  • Updated: 2025-08-30
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
JDK 26
26Unresolved
Related Reports
Relates :  
Description
ADDITIONAL SYSTEM INFORMATION :
wsl2-ubuntu 22.04
Linux 5.15.167.4-microsoft-standard-WSL2 #1 SMP Tue Nov 5 00:21:55 UTC 2024 x86_64 x86_64 x86_64 GNU/Linux

javac 21.0.8

java version "21.0.8" 2025-07-15 LTS
Java(TM) SE Runtime Environment (build 21.0.8+12-LTS-250)
Java HotSpot(TM) 64-Bit Server VM (build 21.0.8+12-LTS-250, mixed mode, sharing)

A DESCRIPTION OF THE PROBLEM :
Javac (tested on JDK 21 and  8, 11, 17) incorrectly accepts code that attempts to call a static method defined in an interface via a type parameter T, where T is a generic type variable bounded by that interface.

STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Compling following code using javac in JDK21.
```
javac Test.java
```

EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
The compliation should fail and report such error message:
```
1. ERROR in Test.java (at line 18)
        T.nonExistentStaticMethod();
          ^^^^^^^^^^^^^^^^^^^^^^^
The method nonExistentStaticMethod() is undefined for the type T
```
ACTUAL -
The compliation is successful.

---------- BEGIN SOURCE ----------
public class Test {
    public static void main(String[] args) {
        TemplateClass<MyType> instance = new TemplateClass<>(new MyType());
    }
}

interface StaticMemberProvider {
    static void nonExistentStaticMethod() {
        throw new UnsupportedOperationException("This method should not be called");
    }
}

class MyType implements StaticMemberProvider {
}

class TemplateClass<T extends StaticMemberProvider> {
    public TemplateClass(T member) {
        T.nonExistentStaticMethod();
    }
}
---------- END SOURCE ----------


Comments
A pull request was submitted for review. Branch: master URL: https://git.openjdk.org/jdk/pull/27015 Date: 2025-08-30 00:37:44 +0000
30-08-2025

It is indeed special that interface static methods are not inherited - good spot. But the program produced should be ok as a binary for linkage and execution even though it violate JLS.
18-08-2025

Observation on Windows 11 ------------------------------------------ JDK 8u461 : Failed (calling static method via type variable compiles successfully) JDK 25.0.1ea: Failed
18-08-2025

Impact -> M (Somewhere in-between the extremes) Likelihood -> L (calling static method via type variable) Workaround -> M (Somewhere in-between the extremes) Priority -> P4
18-08-2025