JDK-8282161 : java.lang.NullPointerException at jdk.compiler/com.sun.tools.javac.comp.Flow
  • Type: Bug
  • Component: tools
  • Sub-Component: javac
  • Affected Version: 11,17
  • Priority: P4
  • Status: Resolved
  • Resolution: Fixed
  • OS: generic
  • CPU: generic
  • Submitted: 2022-02-10
  • Updated: 2022-05-10
  • Resolved: 2022-05-10
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 18
18Fixed
Related Reports
Relates :  
Relates :  
Description
ADDITIONAL SYSTEM INFORMATION :
java compiler 11.0.11

A DESCRIPTION OF THE PROBLEM :
NPE while compiling code with empty diamond to infer generic type. See the code provided

STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
compile the code

EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
compiles and infers the type from the function argument
ACTUAL -
doesnt compile, NPE

---------- BEGIN SOURCE ----------
import com.google.common.reflect.TypeToken;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;

import java.math.BigDecimal;
import java.util.Map;

public class Test {

    private static final Gson GSON = new GsonBuilder().create();

    public void testFunc() {
        testFunc2(fromMongoJsonObject(new TypeToken<>() {
        }));
    }

    void testFunc2(Map<Long, BigDecimal> aMap) {
    }

    private static <R> R fromMongoJsonObject(TypeToken<R> aTypeToken) {
        return GSON.fromJson("Test", aTypeToken.getType());
    }
}

---------- END SOURCE ----------

CUSTOMER SUBMITTED WORKAROUND :
Specify the generic explicitly in diamond:

import com.google.common.reflect.TypeToken;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;

import java.math.BigDecimal;
import java.util.Map;

public class Test {

    private static final Gson GSON = new GsonBuilder().create();

    public void testFunc() {
        testFunc2(fromMongoJsonObject(new TypeToken<Map<Long, BigDecimal>>() {
        }));
    }

    void testFunc2(Map<Long, BigDecimal> aMap) {
    }

    private static <R> R fromMongoJsonObject(TypeToken<R> aTypeToken) {
        return GSON.fromJson("Test", aTypeToken.getType());
    }
}


FREQUENCY : always



Comments
Fixed in JDK 18.
10-05-2022

The issue is reproducible with JDK 17.0.2. I checked with build 8 Please see the attached reproducer and the crash logs. It is not reproducible wit JDK 18b 13 onwards as it was fixed in JDK-8262095. However the fix for JDK-8274904 is still crashing.
21-02-2022