Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
JSpecify: fix crash with calls to static methods (#856)
After adding com.google.common to annotated packages for buildWithNullAway in JSpecify Mode, we got the following exception: ```java error: An unhandled exception was thrown by the Error Prone static analysis plugin. return findEnclosingMethodOrLambdaOrInitializer(path, ImmutableSet.of()); com.google.common.util.concurrent.UncheckedExecutionException: java.lang.NullPointerException: castToNonNull failed! at com.google.common.cache.LocalCache$Segment.get(LocalCache.java:2086) at com.google.common.cache.LocalCache.get(LocalCache.java:4012) at com.google.common.cache.LocalCache.getOrLoad(LocalCache.java:4035) at com.google.common.cache.LocalCache$LocalLoadingCache.get(LocalCache.java:5011) Caused by: java.lang.NullPointerException: castToNonNull failed! at com.uber.nullaway.NullabilityUtil.castToNonNull(NullabilityUtil.java:409) at com.uber.nullaway.GenericsChecks.getGenericReturnNullnessAtInvocation(GenericsChecks.java:800) at com.uber.nullaway.dataflow.AccessPathNullnessPropagation.genericReturnIsNullable(AccessPathNullnessPropagation.java:1031) at com.uber.nullaway.dataflow.AccessPathNullnessPropagation.returnValueNullness(AccessPathNullnessPropagation.java:1008) at com.uber.nullaway.dataflow.AccessPathNullnessPropagation.visit ``` With the call to ```java ImmutableSet.of()``` which is a static call, we were wrongly trying to return null from getTreeType in GenericChecks.java for this case which caused the above Exception. A unit test which reproduces the issue has been added to NullAwayJSpecifyGenerickChecks.java: ```java import org.jspecify.annotations.Nullable; import com.google.common.collect.ImmutableSet; class Test { static void funcImmutableSet(ImmutableSet<Object> is){ } static void testNegative() { //We were getting the issue on this line funcImmutableSet(ImmutableSet.of()); } } ``` All the unit tests from the NullAway build have passed for these changes. --------- Co-authored-by: Manu Sridharan <[email protected]>
- Loading branch information