You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Unexpected errors from contract checking for !null -> !null contracts #1440
Using NullAway 0.13.0, we're seeing unexpected errors reported when contract checking is enabled. It seems to be related to !null contracts such as the following three variants of the same method:
I looked at this a bit and it seems the contract checking code is quite over-simplified and wrong for this case. I'm surprised we didn't notice before. It will need a bit of work to fix.
@wilkinsona I have a potential fix for this up in #1441. Is there some way I could test using a snapshot build on the Spring project where you were seeing issues? Was it spring-framework?
Thanks very much, @msridhar. It was Spring Boot's build rather than Spring Framework's. I'm not too sure how easy it'll be for you to try a NullAway snapshot in our build. Let me see if I can build NullAway locally and try it out.
Thanks so much for testing, @wilkinsona! I think the gap was in handling of returned ternary expressions. I've updated #1441 to fix those now. Any chance you could give it another shot?
I'm now seeing a crash during compilation within the contract checking:
/Users/aw036093/dev/spring-projects/spring-boot/4.0.x/core/spring-boot-test/src/main/java/org/springframework/boot/test/context/runner/WebApplicationContextRunner.java:88: error: An unhandled exception was thrown by the Error Prone static analysis plugin.
public static @Nullable Supplier<ConfigurableWebApplicationContext> withMockServletContext(
^
Please report this at https://github.com/google/error-prone/issues/new and include the following, as well as a reproducing code sample (if possible):
error-prone version: 2.46.0
BugPattern: NullAway
Stack Trace:
org.checkerframework.nullaway.javacutil.BugInCF: Problem with initial store for CFGLambda(
()->{
ConfigurableWebApplicationContext context = contextFactory.get();
context.setServletContext(new MockServletContext());
return context;
}
), parameters=[]
at org.checkerframework.nullaway.dataflow.analysis.ForwardAnalysisImpl.initInitialInputs(ForwardAnalysisImpl.java:351)
at org.checkerframework.nullaway.dataflow.analysis.AbstractAnalysis.init(AbstractAnalysis.java:554)
at org.checkerframework.nullaway.dataflow.analysis.ForwardAnalysisImpl.performAnalysis(ForwardAnalysisImpl.java:102)
at com.uber.nullaway.dataflow.RunOnceForwardAnalysisImpl.performAnalysis(RunOnceForwardAnalysisImpl.java:31)
at com.uber.nullaway.dataflow.DataFlow.dataflow(DataFlow.java:163)
at com.uber.nullaway.dataflow.DataFlow.resultFor(DataFlow.java:329)
at com.uber.nullaway.dataflow.DataFlow.resultForExpr(DataFlow.java:307)
at com.uber.nullaway.dataflow.DataFlow.expressionDataflow(DataFlow.java:230)
at com.uber.nullaway.dataflow.AccessPathNullnessAnalysis.getNullnessForContractDataflow(AccessPathNullnessAnalysis.java:143)
at com.uber.nullaway.handlers.contract.ContractCheckHandler$1.visitReturn(ContractCheckHandler.java:162)
at com.uber.nullaway.handlers.contract.ContractCheckHandler$1.visitReturn(ContractCheckHandler.java:144)
at jdk.compiler/com.sun.tools.javac.tree.JCTree$JCReturn.accept(JCTree.java:1780)
at jdk.compiler/com.sun.source.util.TreePathScanner.scan(TreePathScanner.java:92)
at jdk.compiler/com.sun.source.util.TreeScanner.scanAndReduce(TreeScanner.java:95)
at jdk.compiler/com.sun.source.util.TreeScanner.scan(TreeScanner.java:110)
at jdk.compiler/com.sun.source.util.TreeScanner.visitBlock(TreeScanner.java:271)
at jdk.compiler/com.sun.tools.javac.tree.JCTree$JCBlock.accept(JCTree.java:1148)
at jdk.compiler/com.sun.source.util.TreePathScanner.scan(TreePathScanner.java:92)
at jdk.compiler/com.sun.source.util.TreeScanner.scanAndReduce(TreeScanner.java:95)
at jdk.compiler/com.sun.source.util.TreeScanner.visitLambdaExpression(TreeScanner.java:648)
at jdk.compiler/com.sun.tools.javac.tree.JCTree$JCLambda.accept(JCTree.java:2042)
at jdk.compiler/com.sun.source.util.TreePathScanner.scan(TreePathScanner.java:92)
at jdk.compiler/com.sun.source.util.TreeScanner.scanAndReduce(TreeScanner.java:95)
at jdk.compiler/com.sun.source.util.TreeScanner.visitConditionalExpression(TreeScanner.java:471)
at jdk.compiler/com.sun.tools.javac.tree.JCTree$JCConditional.accept(JCTree.java:1592)
at jdk.compiler/com.sun.source.util.TreePathScanner.scan(TreePathScanner.java:92)
at jdk.compiler/com.sun.source.util.TreeScanner.visitReturn(TreeScanner.java:546)
at com.uber.nullaway.handlers.contract.ContractCheckHandler$1.visitReturn(ContractCheckHandler.java:189)
at com.uber.nullaway.handlers.contract.ContractCheckHandler$1.visitReturn(ContractCheckHandler.java:144)
at jdk.compiler/com.sun.tools.javac.tree.JCTree$JCReturn.accept(JCTree.java:1780)
at jdk.compiler/com.sun.source.util.TreePathScanner.scan(TreePathScanner.java:92)
at jdk.compiler/com.sun.source.util.TreeScanner.scan(TreeScanner.java:110)
at jdk.compiler/com.sun.source.util.TreeScanner.visitBlock(TreeScanner.java:271)
at jdk.compiler/com.sun.tools.javac.tree.JCTree$JCBlock.accept(JCTree.java:1148)
at jdk.compiler/com.sun.source.util.TreePathScanner.scan(TreePathScanner.java:92)
at jdk.compiler/com.sun.source.util.TreeScanner.scanAndReduce(TreeScanner.java:95)
at jdk.compiler/com.sun.source.util.TreeScanner.visitMethod(TreeScanner.java:223)
at jdk.compiler/com.sun.tools.javac.tree.JCTree$JCMethodDecl.accept(JCTree.java:992)
at jdk.compiler/com.sun.source.util.TreePathScanner.scan(TreePathScanner.java:66)
at com.uber.nullaway.handlers.contract.ContractCheckHandler.onMatchMethod(ContractCheckHandler.java:191)
at com.uber.nullaway.handlers.CompositeHandler.onMatchMethod(CompositeHandler.java:86)
at com.uber.nullaway.NullAway.matchMethod(NullAway.java:686)
at com.google.errorprone.scanner.ErrorProneScanner.processMatchers(ErrorProneScanner.java:539)
at com.google.errorprone.scanner.ErrorProneScanner.visitMethod(ErrorProneScanner.java:881)
at com.google.errorprone.scanner.ErrorProneScanner.visitMethod(ErrorProneScanner.java:178)
at jdk.compiler/com.sun.tools.javac.tree.JCTree$JCMethodDecl.accept(JCTree.java:992)
at jdk.compiler/com.sun.source.util.TreePathScanner.scan(TreePathScanner.java:92)
at com.google.errorprone.scanner.Scanner.scan(Scanner.java:74)
at com.google.errorprone.scanner.Scanner.scan(Scanner.java:48)
at jdk.compiler/com.sun.source.util.TreeScanner.scanAndReduce(TreeScanner.java:95)
at jdk.compiler/com.sun.source.util.TreeScanner.scan(TreeScanner.java:110)
at jdk.compiler/com.sun.source.util.TreeScanner.scanAndReduce(TreeScanner.java:118)
at jdk.compiler/com.sun.source.util.TreeScanner.visitClass(TreeScanner.java:202)
at com.google.errorprone.scanner.ErrorProneScanner.visitClass(ErrorProneScanner.java:649)
at com.google.errorprone.scanner.ErrorProneScanner.visitClass(ErrorProneScanner.java:178)
at jdk.compiler/com.sun.tools.javac.tree.JCTree$JCClassDecl.accept(JCTree.java:899)
at jdk.compiler/com.sun.source.util.TreePathScanner.scan(TreePathScanner.java:92)
at com.google.errorprone.scanner.Scanner.scan(Scanner.java:74)
at com.google.errorprone.scanner.Scanner.scan(Scanner.java:48)
at jdk.compiler/com.sun.source.util.TreeScanner.scan(TreeScanner.java:110)
at jdk.compiler/com.sun.source.util.TreeScanner.scanAndReduce(TreeScanner.java:118)
at jdk.compiler/com.sun.source.util.TreeScanner.visitCompilationUnit(TreeScanner.java:151)
at com.google.errorprone.scanner.ErrorProneScanner.visitCompilationUnit(ErrorProneScanner.java:661)
at com.google.errorprone.scanner.ErrorProneScanner.visitCompilationUnit(ErrorProneScanner.java:178)
at jdk.compiler/com.sun.tools.javac.tree.JCTree$JCCompilationUnit.accept(JCTree.java:627)
at jdk.compiler/com.sun.source.util.TreePathScanner.scan(TreePathScanner.java:66)
at com.google.errorprone.scanner.Scanner.scan(Scanner.java:58)
at com.google.errorprone.scanner.ErrorProneScannerTransformer.apply(ErrorProneScannerTransformer.java:43)
at com.google.errorprone.ErrorProneAnalyzer.finished(ErrorProneAnalyzer.java:231)
at jdk.compiler/com.sun.tools.javac.api.MultiTaskListener.finished(MultiTaskListener.java:133)
at jdk.compiler/com.sun.tools.javac.main.JavaCompiler.flow(JavaCompiler.java:1423)
at jdk.compiler/com.sun.tools.javac.main.JavaCompiler.flow(JavaCompiler.java:1370)
at jdk.compiler/com.sun.tools.javac.main.JavaCompiler.compile(JavaCompiler.java:955)
at jdk.compiler/com.sun.tools.javac.api.JavacTaskImpl.lambda$doCall$0(JavacTaskImpl.java:104)
at jdk.compiler/com.sun.tools.javac.api.JavacTaskImpl.invocationHelper(JavacTaskImpl.java:152)
at jdk.compiler/com.sun.tools.javac.api.JavacTaskImpl.doCall(JavacTaskImpl.java:100)
at jdk.compiler/com.sun.tools.javac.api.JavacTaskImpl.call(JavacTaskImpl.java:94)
at org.gradle.internal.compiler.java.IncrementalCompileTask.call(IncrementalCompileTask.java:92)
at org.gradle.api.internal.tasks.compile.AnnotationProcessingCompileTask.call(AnnotationProcessingCompileTask.java:94)
at org.gradle.api.internal.tasks.compile.ResourceCleaningCompilationTask.call(ResourceCleaningCompilationTask.java:57)
at org.gradle.api.internal.tasks.compile.JdkJavaCompiler.execute(JdkJavaCompiler.java:83)
at org.gradle.api.internal.tasks.compile.JdkJavaCompiler.execute(JdkJavaCompiler.java:50)
at org.gradle.api.internal.tasks.compile.daemon.AbstractIsolatedCompilerWorkerExecutor$CompilerWorkAction.execute(AbstractIsolatedCompilerWorkerExecutor.java:79)
at org.gradle.workers.internal.DefaultWorkerServer.execute(DefaultWorkerServer.java:68)
at org.gradle.workers.internal.AbstractClassLoaderWorker$1.create(AbstractClassLoaderWorker.java:54)
at org.gradle.workers.internal.AbstractClassLoaderWorker$1.create(AbstractClassLoaderWorker.java:48)
at org.gradle.internal.classloader.ClassLoaderUtils.executeInClassloader(ClassLoaderUtils.java:102)
at org.gradle.workers.internal.AbstractClassLoaderWorker.executeInClassLoader(AbstractClassLoaderWorker.java:48)
at org.gradle.workers.internal.FlatClassLoaderWorker.run(FlatClassLoaderWorker.java:32)
at org.gradle.workers.internal.FlatClassLoaderWorker.run(FlatClassLoaderWorker.java:22)
at org.gradle.workers.internal.WorkerDaemonServer.run(WorkerDaemonServer.java:109)
at org.gradle.workers.internal.WorkerDaemonServer.run(WorkerDaemonServer.java:78)
at org.gradle.process.internal.worker.request.WorkerAction.lambda$run$1(WorkerAction.java:150)
at org.gradle.process.internal.worker.child.WorkerLogEventListener.withWorkerLoggingProtocol(WorkerLogEventListener.java:41)
at org.gradle.process.internal.worker.request.WorkerAction.lambda$run$2(WorkerAction.java:150)
at org.gradle.internal.operations.CurrentBuildOperationRef.with(CurrentBuildOperationRef.java:84)
at org.gradle.process.internal.worker.request.WorkerAction.run(WorkerAction.java:142)
at java.base/jdk.internal.reflect.DirectMethodHandleAccessor.invoke(DirectMethodHandleAccessor.java:104)
at java.base/java.lang.reflect.Method.invoke(Method.java:565)
at org.gradle.internal.dispatch.MethodInvocation.invokeOn(MethodInvocation.java:77)
at org.gradle.internal.dispatch.ReflectionDispatch.dispatch(ReflectionDispatch.java:28)
at org.gradle.internal.dispatch.ReflectionDispatch.dispatch(ReflectionDispatch.java:19)
at org.gradle.internal.remote.internal.hub.MessageHubBackedObjectConnection$DispatchWrapper.dispatch(MessageHubBackedObjectConnection.java:182)
at org.gradle.internal.remote.internal.hub.MessageHubBackedObjectConnection$DispatchWrapper.dispatch(MessageHubBackedObjectConnection.java:164)
at org.gradle.internal.remote.internal.hub.MessageHub$Handler.run(MessageHub.java:414)
at org.gradle.internal.concurrent.ExecutorPolicy$CatchAndRecordFailures.onExecute(ExecutorPolicy.java:64)
at org.gradle.internal.concurrent.AbstractManagedExecutor$1.run(AbstractManagedExecutor.java:47)
at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1090)
at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:614)
at java.base/java.lang.Thread.run(Thread.java:1474)
Caused by: java.lang.Throwable
at org.checkerframework.nullaway.javacutil.BugInCF.<init>(BugInCF.java:26)
... 110 more
Ok, @wilkinsona that latest bug is fixed now. Could you give it one more shot? Sorry to ask; with instructions I could try it myself, but you indicated it could be a bit of a pain.
Hi @wilkinsona I decided to go ahead and merge #1441 since it clearly fixes a few issues and the PR was getting big. If you could still test again with a snapshot off the master branch that'd be great. If it doesn't work, I'd appreciate if you could file a new issue.
We're facing the same issue when trying to upgrade to 0.13.0 in the junit-framework build. I tried using the latest version from the master branch but I get the same error: https://ge.junit.org/s/dekvw4r4zkxuq/failures#1
Yes please, @msridhar. I've tested the Spring Boot and Spring Framework builds with 4c619e8 and contract checking enabled. The crash is fixed and I didn't see any false-positive violations either.
Activity
msridhar commentedon Jan 21, 2026
I looked at this a bit and it seems the contract checking code is quite over-simplified and wrong for this case. I'm surprised we didn't notice before. It will need a bit of work to fix.
msridhar commentedon Jan 21, 2026
@wilkinsona I have a potential fix for this up in #1441. Is there some way I could test using a snapshot build on the Spring project where you were seeing issues? Was it spring-framework?
wilkinsona commentedon Jan 22, 2026
Thanks very much, @msridhar. It was Spring Boot's build rather than Spring Framework's. I'm not too sure how easy it'll be for you to try a NullAway snapshot in our build. Let me see if I can build NullAway locally and try it out.
wilkinsona commentedon Jan 22, 2026
Things are better but not completely fixed. Here are a couple of build scans showing the failures:
The source that's referenced in these scans is https://github.com/spring-projects/spring-boot/tree/9fde74494d3534d350f77d39d0cfb2420b643fbf.
One simplified example of something that's still failing with #1441 in place is the following:
And here's another:
msridhar commentedon Jan 22, 2026
Thanks so much for testing, @wilkinsona! I think the gap was in handling of returned ternary expressions. I've updated #1441 to fix those now. Any chance you could give it another shot?
wilkinsona commentedon Jan 23, 2026
I'm now seeing a crash during compilation within the contract checking:
This is the code that triggered the failure.
msridhar commentedon Jan 23, 2026
Thanks for the example! I know exactly what's going wrong (returns in nested lambdas). Really appreciate you doing these test runs!
msridhar commentedon Jan 23, 2026
Ok, @wilkinsona that latest bug is fixed now. Could you give it one more shot? Sorry to ask; with instructions I could try it myself, but you indicated it could be a bit of a pain.
msridhar commentedon Jan 23, 2026
Hi @wilkinsona I decided to go ahead and merge #1441 since it clearly fixes a few issues and the PR was getting big. If you could still test again with a snapshot off the master branch that'd be great. If it doesn't work, I'd appreciate if you could file a new issue.
Improve verification of !null -> !null contracts (apache#1441)
marcphilipp commentedon Jan 24, 2026
We're facing the same issue when trying to upgrade to 0.13.0 in the junit-framework build. I tried using the latest version from the
masterbranch but I get the same error: https://ge.junit.org/s/dekvw4r4zkxuq/failures#1marcphilipp commentedon Jan 24, 2026
I opened a follow-up issue because the problem seems to persist (at least for me):
!nullreturn value #1444msridhar commentedon Jan 25, 2026
@wilkinsona would jt be helpful to you if we cut a release with these fixes? Please let us know. Thanks!
wilkinsona commentedon Jan 26, 2026
Yes please, @msridhar. I've tested the Spring Boot and Spring Framework builds with 4c619e8 and contract checking enabled. The crash is fixed and I didn't see any false-positive violations either.
msridhar commentedon Jan 27, 2026
@wilkinsona we just cut release 0.13.1 which includes the fixes for this issue. Thanks so much again with the testing help!
wilkinsona commentedon Jan 27, 2026
My pleasure, thanks for the super-quick fixes and release.