Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ignore code coverage for method executed non-deterministically in tests #838

Merged
merged 1 commit into from
Sep 29, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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