Skip to content

Commit

Permalink
fix(deps): update dependency com.google.guava:guava to v32 (#2229)
Browse files Browse the repository at this point in the history
* fix(deps): update dependency com.google.guava:guava to v32

* Update Ideas_2011_07_22 tests to the new type (#2438)

Co-authored-by: Judit Knoll <judit.knoll@sigmatechnology.com>

---------

Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
Co-authored-by: Judit Knoll <123470644+JuditKnoll@users.noreply.github.com>
Co-authored-by: Judit Knoll <judit.knoll@sigmatechnology.com>
  • Loading branch information
3 people committed Jun 1, 2023
1 parent 439e612 commit 0301036
Show file tree
Hide file tree
Showing 3 changed files with 75 additions and 18 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
package edu.umd.cs.findbugs.detect;

import edu.umd.cs.findbugs.AbstractIntegrationTest;
import edu.umd.cs.findbugs.test.matcher.BugInstanceMatcher;
import edu.umd.cs.findbugs.test.matcher.BugInstanceMatcherBuilder;
import org.junit.Test;

import static edu.umd.cs.findbugs.test.CountMatcher.containsExactly;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.hasItem;

public class RegressionIdeas20110722Test extends AbstractIntegrationTest {
@Test
public void testArgumentAssertions() {
performAnalysis("bugIdeas/Ideas_2011_07_22.class");

assertNumOfBugs("NP_NULL_ON_SOME_PATH", 0);
assertNumOfBugs("RCN_REDUNDANT_NULLCHECK_WOULD_HAVE_BEEN_A_NPE", 4);
assertNumOfBugs("NP_PARAMETER_MUST_BE_NONNULL_BUT_MARKED_AS_NULLABLE", 2);

assertNoNpBugInMethod("getHashCode");
assertNoNpBugInMethod("getHashCode1");
assertNoNpBugInMethod("getHashCode2");
assertNoNpBugInMethod("getHashCode3");
assertRCNBug("getHashCode3", "x", 34);
assertNoNpBugInMethod("getHashCode4");
assertRCNBug("getHashCode4", "x", 41);
assertNoNpBugInMethod("getHashCode5");
assertRCNBug("getHashCode5", "x", 48);
assertRCNBug("getHashCode6", "x", 55);
assertNpParamBug("getHashCode6", "x");
assertNpParamBug("getHashCode7", "x");
}

private void assertNumOfBugs(String error, int num) {
final BugInstanceMatcher bugTypeMatcher = new BugInstanceMatcherBuilder()
.bugType(error).build();
assertThat(getBugCollection(), containsExactly(num, bugTypeMatcher));
}

private void assertNoNpBugInMethod(String method) {
final BugInstanceMatcher bugInstanceMatcher = new BugInstanceMatcherBuilder()
.bugType("NP_NULL_ON_SOME_PATH")
.inClass("Ideas_2011_07_22")
.inMethod(method)
.build();
assertThat(getBugCollection(), containsExactly(0, bugInstanceMatcher));
}

private void assertRCNBug(String method, String var, int line) {
final BugInstanceMatcher bugInstanceMatcher = new BugInstanceMatcherBuilder()
.bugType("RCN_REDUNDANT_NULLCHECK_WOULD_HAVE_BEEN_A_NPE")
.inClass("Ideas_2011_07_22")
.inMethod(method)
.atVariable(var)
.atLine(line)
.build();
assertThat(getBugCollection(), hasItem(bugInstanceMatcher));
}

private void assertNpParamBug(String method, String var) {
final BugInstanceMatcher bugInstanceMatcher = new BugInstanceMatcherBuilder()
.bugType("NP_PARAMETER_MUST_BE_NONNULL_BUT_MARKED_AS_NULLABLE")
.inClass("Ideas_2011_07_22")
.inMethod(method)
.atVariable(var)
.build();
assertThat(getBugCollection(), hasItem(bugInstanceMatcher));
}
}
2 changes: 1 addition & 1 deletion spotbugsTestCases/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ dependencies {
implementation fileTree(dir: 'lib', include: '*.jar')

implementation 'com.google.code.gson:gson:2.10.1'
implementation 'com.google.guava:guava:30.1.1-jre'
implementation 'com.google.guava:guava:32.0.0-jre'
implementation libs.guice
implementation libs.guice.assistedinject
implementation libs.guice.servlet
Expand Down
21 changes: 4 additions & 17 deletions spotbugsTestCases/src/java/bugIdeas/Ideas_2011_07_22.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,9 @@

import com.google.common.base.Preconditions;

import edu.umd.cs.findbugs.annotations.DesireNoWarning;
import edu.umd.cs.findbugs.annotations.DesireWarning;
import edu.umd.cs.findbugs.annotations.ExpectWarning;
import edu.umd.cs.findbugs.annotations.NoWarning;

public class Ideas_2011_07_22 {

@DesireNoWarning("NP_NULL_ON_SOME_PATH")
public int getHashCode(Object x, Object y) {
Preconditions.checkArgument(x != null && y != null, "arguments must be nonnull");
return x.hashCode() + y.hashCode();
Expand All @@ -24,55 +19,47 @@ public int getHashCode0(Object x) {
System.out.println("Good");
return x.hashCode();
}
@DesireNoWarning("NP_NULL_ON_SOME_PATH")
public int getHashCode(Object x) {

public int getHashCode1(Object x) {
Preconditions.checkArgument(x != null, "x is null");
return x.hashCode();
}

@NoWarning("NP_NULL_ON_SOME_PATH")
public int getHashCode2(Object x) {
Preconditions.checkNotNull(x, "x is null");
return x.hashCode();
}

@NoWarning("NP_NULL_ON_SOME_PATH")
@ExpectWarning("RCN_REDUNDANT_NULLCHECK_WOULD_HAVE_BEEN_A_NPE")
public int getHashCode3(Object x) {
Preconditions.checkNotNull(x, "x is null");
if (x == null)
System.out.println("huh?");
return x.hashCode();
}
@NoWarning("NP_NULL_ON_SOME_PATH")
@ExpectWarning("RCN_REDUNDANT_NULLCHECK_WOULD_HAVE_BEEN_A_NPE")

public int getHashCode4(Object x) {
Preconditions.checkNotNull(x);
if (x == null)
System.out.println("huh?");
return x.hashCode();
}
@NoWarning("NP_NULL_ON_SOME_PATH")
@ExpectWarning("RCN_REDUNDANT_NULLCHECK_WOULD_HAVE_BEEN_A_NPE")

public int getHashCode5(Object x) {
Preconditions.checkNotNull(x, "x is null %d", 42);
if (x == null)
System.out.println("huh?");
return x.hashCode();
}

@ExpectWarning("NP_PARAMETER_MUST_BE_NONNULL_BUT_MARKED_AS_NULLABLE,RCN_REDUNDANT_NULLCHECK_WOULD_HAVE_BEEN_A_NPE")
public int getHashCode6(@Nullable Object x) {
Preconditions.checkNotNull(x, "x is null %d", 42);
if (x == null)
System.out.println("huh?");
return x.hashCode();
}

@ExpectWarning("NP_PARAMETER_MUST_BE_NONNULL_BUT_MARKED_AS_NULLABLE")
public int getHashCode7(@Nullable Object x) {
Preconditions.checkNotNull(x, "x is null %d", 42);
return 42;
}

}

0 comments on commit 0301036

Please sign in to comment.