ucr-riple / NullAwayAnnotator

A tool to help adapting code bases to NullAway type system.
MIT License
13 stars 6 forks source link

Crash by Precondition - Missing triggered fixes from downstream #209

Closed nimakarimipour closed 11 months ago

nimakarimipour commented 12 months ago

Describe the bug Annotator incorrectly considers some fixes to be safe to inject on target. It currently considers fixes that introduce new errors on downstream dependencies that can be resolved via a separate fix on target, safe. It fails to also ensure that the resolving fix is also included in the fix tree.

To Reproduce

@Test
  public void upperBoundCountForResolvableErrorOnDownstreamTest() {
    coreTestHelper
        .onTarget()
        .withSourceLines(
            "Bar.java",
            "package test;",
            "public class Bar {",
            "   public String foo;",
            "   public String foo2;",
            "   public void setFoo(String foo) {",
            "     this.foo = foo;",
            "   }",
            "   public String getFoo() {",
            "     return foo;",
            "   }",
            "}")
        .withDependency("Dep")
        .withSourceLines(
            "Dep.java",
            "package test.dep;",
            "import test.Bar;",
            "public class Dep {",
            "   public Bar bar = new Bar();",
            "   public void exec() {",
            "     bar.foo2 = bar.getFoo();",
            "   }",
            "}")
        .withExpectedReports()
        .disableBailOut()
        .enableDownstreamDependencyAnalysis(AnalysisMode.STRICT)
        .toDepth(5)
        .start();
  }

Expected behavior Even though errors due to fix on getFoo() is resolvable on downstream, the corresponding fix is not included in the fix tree, hence, Annotator should consider this fix as unsafe.

Stack trace

java.lang.IllegalArgumentException
    at com.google.common.base.Preconditions.checkArgument(Preconditions.java:131)
    at edu.ucr.cs.riple.core.AnalysisMode$2.lambda$tag$0(AnalysisMode.java:69)
    at java.base/java.lang.Iterable.forEach(Iterable.java:75)
    at edu.ucr.cs.riple.core.AnalysisMode$2.tag(AnalysisMode.java:61)
    at edu.ucr.cs.riple.core.Annotator.executeNextIteration(Annotator.java:150)
    at edu.ucr.cs.riple.core.Annotator.annotate(Annotator.java:110)
    at edu.ucr.cs.riple.core.Annotator.start(Annotator.java:72)
...

Please complete the following information:

Additional context None

nimakarimipour commented 12 months ago

After a more detailed investigation of the issue, realized that the root cause of this issue is missing flow of nullable back to stream through writes to fields.