JDK-8357472 : NPE in Types.containsType for type variable used as a qualifier
  • Type: Bug
  • Component: tools
  • Sub-Component: javac
  • Affected Version: 25
  • Priority: P3
  • Status: Resolved
  • Resolution: Fixed
  • Submitted: 2025-05-21
  • Updated: 2025-07-22
  • Resolved: 2025-07-16
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
26 b07Fixed
Related Reports
Relates :  
Relates :  
Description
The following example uses a type variable as a qualifier, which is unusual but I think it's legal and should be equivalent to `A.B` here. Even if this isn't legal it shouldn't cause a crash.

class A<T> {
  protected class B<V> {}

  public static <T, M extends A<T>> void f(Object g) {
    @SuppressWarnings("unchecked")
    M.B<?> mapping = (M.B<?>) g;
  }
}

$ /google/data/ro/projects/java-platform/linux-amd64/jdk-25-latest/bin/javac -fullversion A.java
javac full version "25-ea+23-2842"
An exception has occurred in the compiler (25-ea). Please file a bug against the Java compiler via the Java bug reporting page (https://bugreport.java.com) after checking the Bug Database (https://bugs.java.com) for duplicates. Include your program, the following diagnostic, and the parameters passed to the Java compiler in your report. Thank you.
java.lang.NullPointerException: Cannot invoke "com.sun.tools.javac.code.Type.accept(com.sun.tools.javac.code.Type$Visitor, Object)" because "t" is null
        at jdk.compiler/com.sun.tools.javac.code.Types$DefaultTypeVisitor.visit(Types.java:4936)
        at jdk.compiler/com.sun.tools.javac.code.Types.containsType(Types.java:1553)
        at jdk.compiler/com.sun.tools.javac.code.Types$1.visitClassType(Types.java:519)
        at jdk.compiler/com.sun.tools.javac.code.Types$1.visitClassType(Types.java:504)
        at jdk.compiler/com.sun.tools.javac.code.Type$ClassType.accept(Type.java:1052)
        at jdk.compiler/com.sun.tools.javac.code.Types$UnaryVisitor.visit(Types.java:5016)
        at jdk.compiler/com.sun.tools.javac.code.Types.isUnbounded(Types.java:501)
        at jdk.compiler/com.sun.tools.javac.code.Types.giveWarning(Types.java:4566)
        at jdk.compiler/com.sun.tools.javac.code.Types$7.visitClassType(Types.java:1813)
        at jdk.compiler/com.sun.tools.javac.code.Types$7.visitClassType(Types.java:1722)
        at jdk.compiler/com.sun.tools.javac.code.Type$ClassType.accept(Type.java:1052)
        at jdk.compiler/com.sun.tools.javac.code.Types$DefaultTypeVisitor.visit(Types.java:4936)
        at jdk.compiler/com.sun.tools.javac.code.Types.isCastable(Types.java:1656)
        at jdk.compiler/com.sun.tools.javac.comp.Check.checkCastable(Check.java:630)
        at jdk.compiler/com.sun.tools.javac.comp.Check.checkCastable(Check.java:627)
        at jdk.compiler/com.sun.tools.javac.comp.Attr.visitTypeCast(Attr.java:4120)
        at jdk.compiler/com.sun.tools.javac.tree.JCTree$JCTypeCast.accept(JCTree.java:2249)
Comments
Changeset: 5e4a2ead Branch: master Author: Aggelos Biboudis <abimpoudis@openjdk.org> Date: 2025-07-16 10:52:26 +0000 URL: https://git.openjdk.org/jdk/commit/5e4a2ead714814cb4eb90ca88debc226f9c75864
16-07-2025

A pull request was submitted for review. Branch: master URL: https://git.openjdk.org/jdk/pull/25451 Date: 2025-05-26 15:51:06 +0000
07-07-2025

The situation in the linked JBS is similar, it handles the type normalization for expressions (checkIdInternal) and not for types (as in the case of using the type in a cast). It has been observed that asOuterSuper and asEnclosingSuper are closely related and the code that has been changed seems that it was unrelated to this work. Another observation is that the case TYPEVAR and case ARRAY were not triggered in the past by any test for either of those methods. In the linked JBS asEnclosingSuper is triggered for the TYPEVAR case in three tests of T8357653.java.
04-07-2025