Skip to content

Commit

Permalink
Ignore code coverage for method executed non-deterministically in tes…
Browse files Browse the repository at this point in the history
…ts (#838)

Fixes #828 (hopefully)

There is some non-determinism in whether
`com.uber.nullaway.dataflow.AccessPath.IteratorContentsKey#equals` runs
or not during tests (see the code comment). The non-determinism will be
hard for us to fix, so instead, add an annotation that tells JaCoCo to
ignore coverage of this method (which is low risk as it's an `equals()`
method that I don't expect will change).
  • Loading branch information
msridhar authored Sep 29, 2023
1 parent b64d1c1 commit 91374c3
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package com.uber.nullaway.annotations;

import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;

/**
* Annotation to indicate to Jacoco that code coverage of a method or constructor should be ignored.
* Jacoco requires such annotations to have "Generated" in their name.
*/
@Retention(RetentionPolicy.CLASS)
@Target({ElementType.METHOD, ElementType.CONSTRUCTOR})
public @interface JacocoIgnoreGenerated {}
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
import com.sun.tools.javac.code.Symbol;
import com.sun.tools.javac.code.Type;
import com.uber.nullaway.NullabilityUtil;
import com.uber.nullaway.annotations.JacocoIgnoreGenerated;
import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.List;
Expand Down Expand Up @@ -648,7 +649,14 @@ public VariableElement getIteratorVarElement() {
return iteratorVarElement;
}

/**
* We ignore this method for code coverage since there is non-determinism somewhere deep in a
* Map implementation such that, depending on how AccessPaths get bucketed in the Map (which
* depends on non-deterministic hash codes), sometimes this method is called and sometimes it is
* not.
*/
@Override
@JacocoIgnoreGenerated
public boolean equals(Object o) {
if (this == o) {
return true;
Expand Down

0 comments on commit 91374c3

Please sign in to comment.