Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] UtilityClass with generics produces NullPointerException in Javac #3274

Closed
juriad opened this issue Oct 4, 2022 · 1 comment · Fixed by #3326
Closed

[BUG] UtilityClass with generics produces NullPointerException in Javac #3274

juriad opened this issue Oct 4, 2022 · 1 comment · Fixed by #3326

Comments

@juriad
Copy link

juriad commented Oct 4, 2022

Describe the bug

@UtilityClass together with a generic method and two methods of the same name causes Javac to crash with NPE in Java 11, 17, 18 and 19 but not 8 (not tested others).

There are a lot of small changes that make the code compile:

  • static is added to the inner class DTO;
  • one of the convert methods is renamed;
  • convertValue(DTO.class) is replaced with just null;
  • the parameter of convertValue method is removed.
  • changing Class<T> to Class.

I have seen a few NPE reports but all were connected with val, while this is not.

To Reproduce

import lombok.experimental.UtilityClass;

@UtilityClass
class Converter {
    <T> T convertValue(Class<T> toValueType) {
        return null;
    }

    DTO convert(Object json) {
        return convertValue(DTO.class);
    }

    Object convert(DTO dto) {
        return null;
    }

    class DTO {
    }
}

The full stack trace is:

An exception has occurred in the compiler (11.0.16.1). Please file a bug against the Java compiler via the Java bug reporting page (http://bugreport.java.com) after checking the Bug Database (http://bugs.java.com) for duplicates. Include your program and the following diagnostic in your report. Thank you.
java.lang.NullPointerException
	at jdk.compiler/com.sun.tools.javac.code.Types.asSuper(Types.java:2111)
	at jdk.compiler/com.sun.tools.javac.code.Types$4.visitClassType(Types.java:1179)
	at jdk.compiler/com.sun.tools.javac.code.Types$4.visitClassType(Types.java:1100)
	at jdk.compiler/com.sun.tools.javac.code.Type$ClassType.accept(Type.java:993)
	at jdk.compiler/com.sun.tools.javac.code.Types$DefaultTypeVisitor.visit(Types.java:4857)
	at jdk.compiler/com.sun.tools.javac.code.Types.isSubtype(Types.java:1096)
	at jdk.compiler/com.sun.tools.javac.code.Types.isSubtypeNoCapture(Types.java:1070)
	at jdk.compiler/com.sun.tools.javac.code.Types$4.visitClassType(Types.java:1186)
	at jdk.compiler/com.sun.tools.javac.code.Types$4.visitClassType(Types.java:1100)
	at jdk.compiler/com.sun.tools.javac.code.Type$ClassType.accept(Type.java:993)
	at jdk.compiler/com.sun.tools.javac.code.Types$DefaultTypeVisitor.visit(Types.java:4857)
	at jdk.compiler/com.sun.tools.javac.code.Types.isSubtype(Types.java:1096)
	at jdk.compiler/com.sun.tools.javac.code.Types.isSubtypeUncheckedInternal(Types.java:1022)
	at jdk.compiler/com.sun.tools.javac.code.Types.isSubtypeUnchecked(Types.java:1008)
	at jdk.compiler/com.sun.tools.javac.comp.Infer$IncorporationBinaryOpKind$1.apply(Infer.java:1183)
	at jdk.compiler/com.sun.tools.javac.comp.Infer$IncorporationBinaryOp.apply(Infer.java:1238)
	at jdk.compiler/com.sun.tools.javac.comp.Infer.doIncorporationOp(Infer.java:1169)
	at jdk.compiler/com.sun.tools.javac.comp.Infer$IncorporationAction.isSubtype(Infer.java:721)
	at jdk.compiler/com.sun.tools.javac.comp.Infer$CheckBounds.checkBound(Infer.java:796)
	at jdk.compiler/com.sun.tools.javac.comp.Infer$CheckBounds.apply(Infer.java:772)
	at jdk.compiler/com.sun.tools.javac.comp.Infer.doIncorporation(Infer.java:1115)
	at jdk.compiler/com.sun.tools.javac.comp.Infer$GraphSolver.solve(Infer.java:1655)
	at jdk.compiler/com.sun.tools.javac.comp.InferenceContext.solve(InferenceContext.java:475)
	at jdk.compiler/com.sun.tools.javac.comp.InferenceContext.solve(InferenceContext.java:482)
	at jdk.compiler/com.sun.tools.javac.comp.Infer.instantiateMethod(Infer.java:218)
	at jdk.compiler/com.sun.tools.javac.comp.Resolve.rawInstantiate(Resolve.java:605)
	at jdk.compiler/com.sun.tools.javac.comp.Resolve.checkMethod(Resolve.java:644)
	at jdk.compiler/com.sun.tools.javac.comp.Attr.checkMethod(Attr.java:4122)
	at jdk.compiler/com.sun.tools.javac.comp.Attr.checkIdInternal(Attr.java:3915)
	at jdk.compiler/com.sun.tools.javac.comp.Attr.checkMethodIdInternal(Attr.java:3820)
	at jdk.compiler/com.sun.tools.javac.comp.Attr.checkId(Attr.java:3805)
	at jdk.compiler/com.sun.tools.javac.comp.Attr.visitIdent(Attr.java:3555)
	at jdk.compiler/com.sun.tools.javac.tree.JCTree$JCIdent.accept(JCTree.java:2264)
	at jdk.compiler/com.sun.tools.javac.comp.Attr.attribTree(Attr.java:655)
	at jdk.compiler/com.sun.tools.javac.comp.Attr.visitApply(Attr.java:2006)
	at jdk.compiler/com.sun.tools.javac.tree.JCTree$JCMethodInvocation.accept(JCTree.java:1650)
	at jdk.compiler/com.sun.tools.javac.comp.Attr.attribTree(Attr.java:655)
	at jdk.compiler/com.sun.tools.javac.comp.Attr.visitReturn(Attr.java:1866)
	at jdk.compiler/com.sun.tools.javac.tree.JCTree$JCReturn.accept(JCTree.java:1562)
	at jdk.compiler/com.sun.tools.javac.comp.Attr.attribTree(Attr.java:655)
	at jdk.compiler/com.sun.tools.javac.comp.Attr.attribStat(Attr.java:724)
	at jdk.compiler/com.sun.tools.javac.comp.Attr.attribStats(Attr.java:743)
	at jdk.compiler/com.sun.tools.javac.comp.Attr.visitBlock(Attr.java:1294)
	at jdk.compiler/com.sun.tools.javac.tree.JCTree$JCBlock.accept(JCTree.java:1036)
	at jdk.compiler/com.sun.tools.javac.comp.Attr.attribTree(Attr.java:655)
	at jdk.compiler/com.sun.tools.javac.comp.Attr.attribStat(Attr.java:724)
	at jdk.compiler/com.sun.tools.javac.comp.Attr.visitMethodDef(Attr.java:1098)
	at jdk.compiler/com.sun.tools.javac.tree.JCTree$JCMethodDecl.accept(JCTree.java:866)
	at jdk.compiler/com.sun.tools.javac.comp.Attr.attribTree(Attr.java:655)
	at jdk.compiler/com.sun.tools.javac.comp.Attr.attribStat(Attr.java:724)
	at jdk.compiler/com.sun.tools.javac.comp.Attr.attribClassBody(Attr.java:4685)
	at jdk.compiler/com.sun.tools.javac.comp.Attr.attribClass(Attr.java:4576)
	at jdk.compiler/com.sun.tools.javac.comp.Attr.attribClass(Attr.java:4505)
	at jdk.compiler/com.sun.tools.javac.comp.Attr.attrib(Attr.java:4450)
	at jdk.compiler/com.sun.tools.javac.main.JavaCompiler.attribute(JavaCompiler.java:1337)
	at jdk.compiler/com.sun.tools.javac.main.JavaCompiler.compile(JavaCompiler.java:973)
	at jdk.compiler/com.sun.tools.javac.main.Main.compile(Main.java:311)
	at jdk.compiler/com.sun.tools.javac.main.Main.compile(Main.java:170)
	at jdk.compiler/com.sun.tools.javac.Main.compile(Main.java:57)
	at jdk.compiler/com.sun.tools.javac.Main.main(Main.java:43)

Stacktrace in Java 17 looks very similar (frames are a few lines off) but we get more information:

An exception has occurred in the compiler (17.0.4.1). Please file a bug against the Java compiler via the Java bug reporting page (http://bugreport.java.com) after checking the Bug Database (http://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 read field "type" because "sym" is null

Version info:

  • Lombok version org.projectlombok:lombok:1.18.24 (used in Gradle)
  • Platform: Javas were installed using SDKMAN!

works:
openjdk version "1.8.0_345"
OpenJDK Runtime Environment (Temurin)(build 1.8.0_345-b01)
OpenJDK 64-Bit Server VM (Temurin)(build 25.345-b01, mixed mode)

fails:
openjdk version "11.0.12" 2021-07-20
OpenJDK Runtime Environment 18.9 (build 11.0.12+7)
OpenJDK 64-Bit Server VM 18.9 (build 11.0.12+7, mixed mode)

also fails:
openjdk version "17.0.4.1" 2022-08-12
OpenJDK Runtime Environment Temurin-17.0.4.1+1 (build 17.0.4.1+1)
OpenJDK 64-Bit Server VM Temurin-17.0.4.1+1 (build 17.0.4.1+1, mixed mode, sharing)

Rawi01 added a commit to Rawi01/lombok that referenced this issue Jan 9, 2023
@Rawi01
Copy link
Collaborator

Rawi01 commented Jan 9, 2023

Thanks for this excellent bug report. It is similar to #3097 but it seems like I missed to also reset a second field that only gets used sometimes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants