uber / NullAway

A tool to help eliminate NullPointerExceptions (NPEs) in your Java code with low build-time overhead
MIT License
3.62k stars 290 forks source link

com.uber.nullaway.generics.CheckIdenticalNullabilityVisitor.visitClassType Did not find supertype of #1008

Closed agentgt closed 1 month ago

agentgt commented 1 month ago

NullAway 0.11.0 with JSpecifyMode turned on crashes for the following class:

https://github.com/jstachio/rainbowgum/blob/31c71243eef1661513516938005a064663930bf2/core/src/test/java/io/jstach/rainbowgum/EnumCombinations.java#L26

/Users/agent/projects/rainbowgum/core/src/test/java/io/jstach/rainbowgum/EnumCombinations.java:[26,43] error: An unhandled exception was thrown by the Error Prone static analysis plugin.
     Please report this at https://github.com/google/error-prone/issues/new and include the following:

     error-prone version: 2.28.0
     BugPattern: NullAway
     Stack Trace:
     java.lang.RuntimeException: Did not find supertype of java.lang.Class<? extends java.lang.Enum<?>>[] matching java.lang.Class<? extends java.lang.Enum<?>>
    at com.uber.nullaway.generics.CheckIdenticalNullabilityVisitor.visitClassType(CheckIdenticalNullabilityVisitor.java:33)
    at com.uber.nullaway.generics.CheckIdenticalNullabilityVisitor.visitClassType(CheckIdenticalNullabilityVisitor.java:14)
    at jdk.compiler/com.sun.tools.javac.code.Type$ClassType.accept(Type.java:1050)
    at com.uber.nullaway.generics.GenericsChecks.identicalTypeParameterNullability(GenericsChecks.java:386)
    at com.uber.nullaway.generics.GenericsChecks.subtypeParameterNullability(GenericsChecks.java:415)
    at com.uber.nullaway.generics.GenericsChecks.compareGenericTypeParameterNullabilityForCall(GenericsChecks.java:535)
    at com.uber.nullaway.NullAway.handleInvocation(NullAway.java:1774)
    at com.uber.nullaway.NullAway.matchMethodInvocation(NullAway.java:408)
    at com.google.errorprone.scanner.ErrorProneScanner.processMatchers(ErrorProneScanner.java:449)
    at com.google.errorprone.scanner.ErrorProneScanner.visitMethodInvocation(ErrorProneScanner.java:746)
    at com.google.errorprone.scanner.ErrorProneScanner.visitMethodInvocation(ErrorProneScanner.java:150)
    at jdk.compiler/com.sun.tools.javac.tree.JCTree$JCMethodInvocation.accept(JCTree.java:1832)
    at jdk.compiler/com.sun.source.util.TreePathScanner.scan(TreePathScanner.java:92)

Happy to provide more information.

SolomonSun2010 commented 1 month ago

@msridhar hello,excuse me. When I run 0.11.1,get a similary erro: error-prone version: 2.23.0 ButPattern: NullAway: Stack Trace:

java.lang.RuntimeException: Did not find supertype of java.lang.String matching java.lang.Object&java.io.Serializable&java.lang.Comparable<? extends java.lang.Object&java.io.Serializable&java.lang.Comparable<?>>

Looks at NullAway here:

Type rhsTypeAsSuper = types.asSuper(rhsType, lhsType.tsym);
// This is impossible, considering the fact that standard Java subtyping succeeds before
// running NullAway
if (rhsTypeAsSuper == null) {
  throw new RuntimeException("Did not find supertype of " + rhsType + " matching " + lhsType);
}
msridhar commented 1 month ago

@SolomonSun2010 Do you have an example input program that causes the error? Without that it'll be hard to track down the problem.

SolomonSun2010 commented 1 month ago

@SolomonSun2010 Do you have an example input program that causes the error? Without that it'll be hard to track down the problem.

@msridhar OK,when running NullAway, normally display : warning: [NullAway] xxxxxx

Suddenly, error message is:

An unhandled exception was thrown by Error Prone static analysis pluging. ", relativeServices=" + (relativeServices == null ? "relativeServices == null" : relativeServices.size())

    @Override
    public String toString() {
        return "ServiceExtraInfo{" +
            "appInfoData=" + (appInfoData == null ?  "null" : appInfoData.toString()) +
            ", relativeServices=" + (relativeServices == null ? "relativeServices == null" : relativeServices.size())
            + getRelativeServicesToString() + '}';
    }
agentgt commented 1 month ago

@msridhar I too still get a similar error w/ 0.11.1 (but in a different place) if that helps.

/Users/agent/projects/rainbowgum/core/src/main/java/io/jstach/rainbowgum/LogProperty.java:[1660,6] error: An unhandled exception was thrown by the Error Prone static analysis plugin.
     Please report this at https://github.com/google/error-prone/issues/new and include the following:

     error-prone version: 2.28.0
     BugPattern: NullAway
     Stack Trace:
     java.lang.RuntimeException: Did not find supertype of ? super java.lang.Exception matching java.lang.Exception
    at com.uber.nullaway.generics.CheckIdenticalNullabilityVisitor.visitClassType(CheckIdenticalNullabilityVisitor.java:33)
    at com.uber.nullaway.generics.CheckIdenticalNullabilityVisitor.visitClassType(CheckIdenticalNullabilityVisitor.java:14)
    at jdk.compiler/com.sun.tools.javac.code.Type$ClassType.accept(Type.java:1050)
    at com.uber.nullaway.generics.CheckIdenticalNullabilityVisitor.visitClassType(CheckIdenticalNullabilityVisitor.java:52)

https://github.com/agentgt/rainbowgum/blob/18edf552a22f279e1cc6c9c31ce6870ad387e569/core/src/main/java/io/jstach/rainbowgum/LogProperty.java#L1660

(n.b. that is a fork and branch from the main repository albeit it exists in the main repo its line might change as I continue to add/improve javadoc)

Should I file a separate bug for the above?

If you do happen to clone the repository (and branch nullaway) linked you can kick off nullaway (and errorprone) with:

bin/analyze.sh errorpone

msridhar commented 1 month ago

Thanks @SolomonSun2010 @agentgt I went ahead and opened two new issues based on your comments. Will look when I get time.