Skip to content
Permalink
Browse files

change annotation to use confidence rather than priority

git-svn-id: https://findbugs.googlecode.com/svn/trunk@13610 eae3c2d3-9b19-0410-a86e-396b6ccb6ab3
  • Loading branch information...
Bill Pugh
Bill Pugh committed Aug 6, 2011
1 parent 0d06523 commit d3b41945e03f854ce8613e1521b16230a62fb9c9
Showing with 112 additions and 37 deletions.
  1. +1 −0 findbugs/src/java/edu/umd/cs/findbugs/annotations/CheckForNull.java
  2. +4 −0 findbugs/src/java/edu/umd/cs/findbugs/annotations/CheckReturnValue.java
  3. +40 −0 findbugs/src/java/edu/umd/cs/findbugs/annotations/Confidence.java
  4. +4 −0 findbugs/src/java/edu/umd/cs/findbugs/annotations/DefaultAnnotation.java
  5. +4 −0 findbugs/src/java/edu/umd/cs/findbugs/annotations/DefaultAnnotationForFields.java
  6. +4 −0 findbugs/src/java/edu/umd/cs/findbugs/annotations/DefaultAnnotationForMethods.java
  7. +4 −0 findbugs/src/java/edu/umd/cs/findbugs/annotations/DefaultAnnotationForParameters.java
  8. +4 −1 findbugs/src/java/edu/umd/cs/findbugs/annotations/DesireNoWarning.java
  9. +1 −1 findbugs/src/java/edu/umd/cs/findbugs/annotations/DesireWarning.java
  10. +1 −1 findbugs/src/java/edu/umd/cs/findbugs/annotations/ExpectWarning.java
  11. +1 −1 findbugs/src/java/edu/umd/cs/findbugs/annotations/NoWarning.java
  12. +1 −0 findbugs/src/java/edu/umd/cs/findbugs/annotations/Nullable.java
  13. +1 −0 findbugs/src/java/edu/umd/cs/findbugs/annotations/OverrideMustInvoke.java
  14. +1 −0 findbugs/src/java/edu/umd/cs/findbugs/annotations/Priority.java
  15. +1 −0 findbugs/src/java/edu/umd/cs/findbugs/annotations/ReturnValuesAreNonnullByDefault.java
  16. +1 −0 findbugs/src/java/edu/umd/cs/findbugs/annotations/UnknownNullness.java
  17. +1 −0 findbugs/src/java/edu/umd/cs/findbugs/annotations/When.java
  18. +9 −5 findbugs/src/java/edu/umd/cs/findbugs/detect/CheckExpectedWarnings.java
  19. +0 −1 findbugs/src/java/edu/umd/cs/findbugs/detect/FindNullDeref.java
  20. +2 −2 findbugsTestCases/src/java/AnnotationTest.java
  21. +2 −2 findbugsTestCases/src/java/bugIdeas/Ideas_2009_12_11.java
  22. +2 −2 findbugsTestCases/src/java/bugIdeas/Ideas_2010_10_04.java
  23. +5 −3 findbugsTestCases/src/java/bugIdeas/Ideas_2011_07_25.java
  24. +9 −9 findbugsTestCases/src/java/bugIdeas/Ideas_2011_08_02.java
  25. +2 −2 findbugsTestCases/src/java/sfBugs/Bug3104124.java
  26. +1 −1 findbugsTestCases/src/java/sfBugs/Bug3204236.java
  27. +3 −3 findbugsTestCases/src/java/sfBugs/RFE2891944.java
  28. +3 −3 findbugsTestCases/src/java/sfBugs/RFE3062724.java
@@ -39,6 +39,7 @@
@Retention(RetentionPolicy.CLASS)
@javax.annotation.Nonnull(when = When.MAYBE)
@TypeQualifierNickname
@Deprecated
public @interface CheckForNull {

}
@@ -33,10 +33,14 @@
@Documented
@Target({ ElementType.METHOD, ElementType.CONSTRUCTOR })
@Retention(RetentionPolicy.CLASS)
@Deprecated
public @interface CheckReturnValue {

@Deprecated
Priority priority() default Priority.MEDIUM;

Confidence confidence() default Confidence.MEDIUM;

/**
* A textual explanation of why the return value should be checked
*/
@@ -0,0 +1,40 @@
/*
* FindBugs - Find Bugs in Java programs
* Copyright (C) 2005, University of Maryland
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/

package edu.umd.cs.findbugs.annotations;

import edu.umd.cs.findbugs.Priorities;

/**
* @author pugh
*/
public enum Confidence {
HIGH(Priorities.HIGH_PRIORITY), MEDIUM(Priorities.NORMAL_PRIORITY), LOW(Priorities.LOW_PRIORITY), IGNORE(
Priorities.IGNORE_PRIORITY);

private final int confidenceValue;

public int getConfidenceValue() {
return confidenceValue;
}

private Confidence(int p) {
confidenceValue = p;
}
}
@@ -43,8 +43,12 @@
@Documented
@Target({ ElementType.TYPE, ElementType.PACKAGE })
@Retention(RetentionPolicy.CLASS)
@Deprecated
public @interface DefaultAnnotation {
Class<? extends Annotation>[] value();

@Deprecated
Priority priority() default Priority.MEDIUM;

Confidence confidence() default Confidence.MEDIUM;
}
@@ -43,8 +43,12 @@
@Documented
@Target({ ElementType.TYPE, ElementType.PACKAGE })
@Retention(RetentionPolicy.CLASS)
@Deprecated
public @interface DefaultAnnotationForFields {
Class<? extends Annotation>[] value();

@Deprecated
Priority priority() default Priority.MEDIUM;

Confidence confidence() default Confidence.MEDIUM;
}
@@ -43,8 +43,12 @@
@Documented
@Target({ ElementType.TYPE, ElementType.PACKAGE })
@Retention(RetentionPolicy.CLASS)
@Deprecated
public @interface DefaultAnnotationForMethods {
Class<? extends Annotation>[] value();

@Deprecated
Priority priority() default Priority.MEDIUM;

Confidence confidence() default Confidence.MEDIUM;
}
@@ -43,8 +43,12 @@
@Documented
@Target({ ElementType.TYPE, ElementType.PACKAGE })
@Retention(RetentionPolicy.CLASS)
@Deprecated
public @interface DefaultAnnotationForParameters {
Class<? extends Annotation>[] value();

@Deprecated
Priority priority() default Priority.MEDIUM;

Confidence confidence() default Confidence.MEDIUM;
}
@@ -24,6 +24,9 @@
*/
public String value();

@Deprecated
Priority priority() default Priority.LOW;

/** Want no warning at this priority or higher */
public Priority priority() default Priority.LOW;
Confidence confidence() default Confidence.LOW;
}
@@ -24,7 +24,7 @@
public String value();

/** Want a warning at this priority or higher */
public Priority priority() default Priority.LOW;
public Confidence priority() default Confidence.LOW;

/** Expect a warning at least this scary */
public int rank() default 20;
@@ -24,7 +24,7 @@
public String value();

/** Want a warning at this priority or higher */
public Priority priority() default Priority.LOW;
public Confidence confidence() default Confidence.LOW;

/** Expect a warning at least this scary */
public int rank() default 20;
@@ -24,7 +24,7 @@
public String value();

/** Want no warning at this priority or higher */
public Priority priority() default Priority.LOW;
public Confidence confidence() default Confidence.LOW;

/** Want no warning at this rank or scarier */
public int rank() default 20;
@@ -42,6 +42,7 @@
@Retention(RetentionPolicy.CLASS)
@javax.annotation.Nonnull(when = When.UNKNOWN)
@TypeQualifierNickname
@Deprecated
public @interface Nullable {

}
@@ -39,6 +39,7 @@
@Documented
@Target({ ElementType.METHOD })
@Retention(RetentionPolicy.CLASS)
@Deprecated
public @interface OverrideMustInvoke {
When value() default When.ANYTIME;

@@ -24,6 +24,7 @@
/**
* @author pugh
*/
@Deprecated
public enum Priority {
HIGH(Priorities.HIGH_PRIORITY), MEDIUM(Priorities.NORMAL_PRIORITY), LOW(Priorities.LOW_PRIORITY), IGNORE(
Priorities.IGNORE_PRIORITY);
@@ -43,5 +43,6 @@
@Nonnull
@TypeQualifierDefault(ElementType.METHOD)
@Retention(RetentionPolicy.RUNTIME)
@Deprecated
public @interface ReturnValuesAreNonnullByDefault {
}
@@ -36,6 +36,7 @@
@Retention(RetentionPolicy.CLASS)
@javax.annotation.Nonnull(when = When.UNKNOWN)
@TypeQualifierNickname
@Deprecated
public @interface UnknownNullness {

}
@@ -22,6 +22,7 @@
/**
* @author pugh
*/
@Deprecated
public enum When {
FIRST, ANYTIME, LAST

@@ -44,6 +44,7 @@
import edu.umd.cs.findbugs.annotations.DesireWarning;
import edu.umd.cs.findbugs.annotations.ExpectWarning;
import edu.umd.cs.findbugs.annotations.NoWarning;
import edu.umd.cs.findbugs.annotations.Confidence;
import edu.umd.cs.findbugs.annotations.Priority;
import edu.umd.cs.findbugs.ba.AnalysisContext;
import edu.umd.cs.findbugs.ba.XClass;
@@ -179,6 +180,7 @@ private void check(XMethod xmethod, ClassDescriptor annotation, boolean expectWa
System.out.println("*** Found " + annotation + " annotation");
}
String expectedBugCodes = (String) expect.getValue("value");
EnumValue wantedConfidence = (EnumValue) expect.getValue("confidence");
EnumValue wantedPriority = (EnumValue) expect.getValue("priority");
Integer num = (Integer) expect.getValue("num");
if (num == null)
@@ -187,9 +189,11 @@ private void check(XMethod xmethod, ClassDescriptor annotation, boolean expectWa
if (rank == null)
rank = 20;

Priority minPriority = Priority.LOW;
if (wantedPriority != null)
minPriority = Priority.valueOf(wantedPriority.value);
int minPriority = Confidence.LOW.getConfidenceValue();
if (wantedConfidence != null)
minPriority = Confidence.valueOf(wantedConfidence.value).getConfidenceValue();
else if (wantedPriority != null)
minPriority = Priority.valueOf(wantedPriority.value).getPriorityValue();

StringTokenizer tok = new StringTokenizer(expectedBugCodes, ",");
while (tok.hasMoreTokens()) {
@@ -214,7 +218,7 @@ private void check(XMethod xmethod, ClassDescriptor annotation, boolean expectWa
}

private Collection<SourceLineAnnotation> countWarnings(MethodDescriptor methodDescriptor, String bugCode,
Priority minPriority, int rank) {
int desiredPriority, int rank) {
Collection<BugInstance> warnings = warningsByMethod.get(methodDescriptor);
Collection<SourceLineAnnotation> matching = new HashSet<SourceLineAnnotation>();
DetectorFactoryCollection i18n = DetectorFactoryCollection.instance();
@@ -227,7 +231,7 @@ private void check(XMethod xmethod, ClassDescriptor annotation, boolean expectWa

if (warnings != null) {
for (BugInstance warning : warnings) {
if (warning.getPriority() > minPriority.getPriorityValue())
if (warning.getPriority() > desiredPriority)
continue;
if (warning.getBugRank() > rank)
continue;
@@ -68,7 +68,6 @@
import edu.umd.cs.findbugs.SystemProperties;
import edu.umd.cs.findbugs.UseAnnotationDatabase;
import edu.umd.cs.findbugs.annotations.NonNull;
import edu.umd.cs.findbugs.annotations.Priority;
import edu.umd.cs.findbugs.ba.AnalysisContext;
import edu.umd.cs.findbugs.ba.BasicBlock;
import edu.umd.cs.findbugs.ba.CFG;
@@ -1,8 +1,8 @@
import edu.umd.cs.findbugs.annotations.CheckReturnValue;
import edu.umd.cs.findbugs.annotations.Priority;
import edu.umd.cs.findbugs.annotations.Confidence;

class AnnotationTest {
@CheckReturnValue(priority = Priority.HIGH)
@CheckReturnValue(confidence = Confidence.HIGH)
int f() {
return 42;
}
@@ -4,7 +4,7 @@

import edu.umd.cs.findbugs.annotations.DesireNoWarning;
import edu.umd.cs.findbugs.annotations.DesireWarning;
import edu.umd.cs.findbugs.annotations.Priority;
import edu.umd.cs.findbugs.annotations.Confidence;

public class Ideas_2009_12_11 {

@@ -28,7 +28,7 @@ public int hashCode() {
return Arrays.deepHashCode(data);
}

@DesireNoWarning(value="EC_ARRAY_AND_NONARRAY", priority=Priority.MEDIUM)
@DesireNoWarning(value="EC_ARRAY_AND_NONARRAY", confidence=Confidence.MEDIUM)
@DesireWarning("EC_INCOMPATIBLE_TYPES")
public static void main(String args[]) {
Ideas_2009_12_11 a = new Ideas_2009_12_11();
@@ -4,7 +4,7 @@

import edu.umd.cs.findbugs.annotations.ExpectWarning;
import edu.umd.cs.findbugs.annotations.NoWarning;
import edu.umd.cs.findbugs.annotations.Priority;
import edu.umd.cs.findbugs.annotations.Confidence;

public class Ideas_2010_10_04 {

@@ -43,7 +43,7 @@ public boolean equals(Object obj) {
return false;
}

@NoWarning(value = "EC_ARRAY_AND_NONARRAY", priority = Priority.MEDIUM)
@NoWarning(value = "EC_ARRAY_AND_NONARRAY", confidence = Confidence.MEDIUM)
public static void main(String args[]) {
int [] x = {1};
int [] y = {1};
@@ -3,7 +3,8 @@
import com.google.common.base.Preconditions;

import edu.umd.cs.findbugs.annotations.ExpectWarning;
import edu.umd.cs.findbugs.annotations.Priority;
import edu.umd.cs.findbugs.annotations.NoWarning;
import edu.umd.cs.findbugs.annotations.Confidence;

/** Bug pattern suggested by Curtis Light and Kevin Bourrillion.
* Variations on test1 version occur 80+ times in Google's codebase. */
@@ -34,7 +35,8 @@ public Object getX() {
return x;
}

@ExpectWarning("RCN_REDUNDANT_NULLCHECK_WOULD_HAVE_BEEN_A_NPE")
@NoWarning(value="RCN_REDUNDANT_NULLCHECK_WOULD_HAVE_BEEN_A_NPE",
confidence=Confidence.MEDIUM)
public int test2(Object x) {
int result = x.hashCode();
Preconditions.checkNotNull(x, "x should be nonnull");
@@ -47,7 +49,7 @@ public int test3(Object x) {
Preconditions.checkNotNull(x, "x should be nonnull");
return x.hashCode();
}
@ExpectWarning("RCN_REDUNDANT_NULLCHECK_OF_NONNULL_VALUE")
@NoWarning(value="RCN_REDUNDANT_NULLCHECK_OF_NONNULL_VALUE", confidence=Confidence.MEDIUM)
public int test3a(Object x) {
if (x == null)
return 42;
@@ -13,7 +13,7 @@

import edu.umd.cs.findbugs.annotations.ExpectWarning;
import edu.umd.cs.findbugs.annotations.NoWarning;
import edu.umd.cs.findbugs.annotations.Priority;
import edu.umd.cs.findbugs.annotations.Confidence;

public class Ideas_2011_08_02 {

@@ -38,35 +38,35 @@ public boolean okCheck(int x) {

Collection<Map.Entry<Color, Integer>> c = new ArrayList<Map.Entry<Color, Integer>>();

@NoWarning(value="DMI_ENTRY_SETS_MAY_REUSE_ENTRY_OBJECTS", priority=Priority.HIGH)
@ExpectWarning(value="DMI_ENTRY_SETS_MAY_REUSE_ENTRY_OBJECTS", priority=Priority.MEDIUM)
@NoWarning(value="DMI_ENTRY_SETS_MAY_REUSE_ENTRY_OBJECTS", confidence=Confidence.HIGH)
@ExpectWarning(value="DMI_ENTRY_SETS_MAY_REUSE_ENTRY_OBJECTS", confidence=Confidence.MEDIUM)
public void addAll(Map<Color, Integer> m) {
c.addAll(m.entrySet());
}

@ExpectWarning(value="DMI_ENTRY_SETS_MAY_REUSE_ENTRY_OBJECTS", priority=Priority.HIGH)
@ExpectWarning(value="DMI_ENTRY_SETS_MAY_REUSE_ENTRY_OBJECTS", confidence=Confidence.HIGH)
public void addAll(IdentityHashMap<Color, Integer> m) {
c.addAll(m.entrySet());
}
@ExpectWarning(value="DMI_ENTRY_SETS_MAY_REUSE_ENTRY_OBJECTS", priority=Priority.HIGH)
@ExpectWarning(value="DMI_ENTRY_SETS_MAY_REUSE_ENTRY_OBJECTS", confidence=Confidence.HIGH)

public void addAll(EnumMap<Color, Integer> m) {
c.addAll(m.entrySet());
}
@ExpectWarning(value="DMI_ENTRY_SETS_MAY_REUSE_ENTRY_OBJECTS", priority=Priority.MEDIUM)
@ExpectWarning(value="DMI_ENTRY_SETS_MAY_REUSE_ENTRY_OBJECTS", confidence=Confidence.LOW)
public void addAll(ConcurrentHashMap<Color, Integer> m) {
c.addAll(m.entrySet());
}
@ExpectWarning(value="DMI_ENTRY_SETS_MAY_REUSE_ENTRY_OBJECTS", priority=Priority.MEDIUM)
@ExpectWarning(value="DMI_ENTRY_SETS_MAY_REUSE_ENTRY_OBJECTS", confidence=Confidence.LOW)
public void addAll(ConcurrentSkipListMap<Color, Integer> m) {
c.addAll(m.entrySet());
}

@NoWarning(value="DMI_ENTRY_SETS_MAY_REUSE_ENTRY_OBJECTS", priority=Priority.MEDIUM)
@NoWarning(value="DMI_ENTRY_SETS_MAY_REUSE_ENTRY_OBJECTS", confidence=Confidence.MEDIUM)
public void addAll(HashMap<Color, Integer> m) {
c.addAll(m.entrySet());
}
@NoWarning(value="DMI_ENTRY_SETS_MAY_REUSE_ENTRY_OBJECTS", priority=Priority.MEDIUM)
@NoWarning(value="DMI_ENTRY_SETS_MAY_REUSE_ENTRY_OBJECTS", confidence=Confidence.MEDIUM)
public void addAll(TreeMap<Color, Integer> m) {
c.addAll(m.entrySet());
}

0 comments on commit d3b4194

Please sign in to comment.
You can’t perform that action at this time.