Package edu.umd.cs.findbugs
Class BugInstance
- java.lang.Object
-
- edu.umd.cs.findbugs.BugInstance
-
- All Implemented Interfaces:
XMLWriteable,java.lang.Cloneable,java.lang.Comparable<BugInstance>
public class BugInstance extends java.lang.Object implements java.lang.Comparable<BugInstance>, XMLWriteable, java.lang.Cloneable
An instance of a bug pattern. A BugInstance consists of several parts:
- the type, which is a string indicating what kind of bug it is; used as a key for the FindBugsMessages resource bundle
- the priority; how likely this instance is to actually be a bug
- a list of annotations
The annotations describe classes, methods, fields, source locations, and other relevant context information about the bug instance. Every BugInstance must have at least one ClassAnnotation, which describes the class in which the instance was found. This is the "primary class annotation".
BugInstance objects are built up by calling a string of
addmethods. (These methods all "return this", so they can be chained). Some of the add methods are specialized to get information automatically from a BetterVisitor or DismantleBytecode object.- See Also:
BugAnnotation
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description private classBugInstance.BugPropertyIteratorstatic classBugInstance.NoSuchBugPattern
-
Field Summary
Fields Modifier and Type Field Description private static booleanadjustExperimentalThis value is used to indicate whether BugInstances should be reprioritized very low, when the BugPattern is marked as experimentalprivate java.util.List<BugAnnotation>annotationListprivate intcachedHashCodeprivate @Nullable DetectorFactorydetectorFactoryprivate static java.lang.StringELEMENT_NAMEprivate longfirstVersionprivate java.lang.StringinstanceHashprivate intinstanceOccurrenceMaxprivate intinstanceOccurrenceNumprivate booleanintroducedByChangeOfExistingClassprivate static intINVALID_HASH_CODEThis value is used to indicate that the cached hashcode is invalid, and should be recomputed.private longlastVersionprivate static org.slf4j.LoggerLOGprivate static java.util.Set<java.lang.String>missingBugTypesprivate java.lang.StringoldInstanceHashprivate intpriorityprivate BugPropertypropertyListHeadprivate BugPropertypropertyListTailprivate booleanremovedByChangeOfPersistingClassprivate java.lang.Stringtype
-
Constructor Summary
Constructors Constructor Description BugInstance(Detector2 detector, java.lang.String type, int priority)Create a new BugInstance.BugInstance(Detector detector, java.lang.String type, int priority)Create a new BugInstance.BugInstance(java.lang.String type, int priority)Constructor.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description BugInstanceadd(@NonNull BugAnnotation annotation)private static voidaddAnnotationNames(PackageMemberAnnotation pma, org.apache.bcel.classfile.AnnotationEntry[] annotationEntries)@NonNull BugInstanceaddAnnotations(java.util.Collection<? extends BugAnnotation> annotationCollection)Add a Collection of BugAnnotations.@NonNull BugInstanceaddCalledMethod(XMethod m)@NonNull BugInstanceaddCalledMethod(DismantleBytecode visitor)Add a method annotation for the method which has been called by the method currently being visited by given visitor.@NonNull BugInstanceaddCalledMethod(java.lang.String className, java.lang.String methodName, java.lang.String methodSig, boolean isStatic)Add a method annotation.@NonNull BugInstanceaddCalledMethod(org.apache.bcel.generic.ConstantPoolGen cpg, org.apache.bcel.generic.InvokeInstruction inv)Add a method annotation for the method which is called by given instruction.@NonNull BugInstanceaddCalledMethod(org.apache.bcel.generic.MethodGen methodGen, org.apache.bcel.generic.InvokeInstruction inv)Add a method annotation for the method which is called by given instruction.@NonNull BugInstanceaddClass(ClassDescriptor classDescriptor)Add a class annotation.@NonNull BugInstanceaddClass(PreorderVisitor visitor)Add a class annotation for the class that the visitor is currently visiting.@NonNull BugInstanceaddClass(java.lang.String className)Add a class annotation.@NonNull BugInstanceaddClass(java.lang.String className, java.lang.String sourceFileName)Add a class annotation.@NonNull BugInstanceaddClass(org.apache.bcel.classfile.JavaClass jclass)Add a class annotation.@NonNull BugInstanceaddClass(org.objectweb.asm.tree.ClassNode classNode)Add a class annotation for the classNode.BugInstanceaddClassAndMethod(XMethod xMethod)@NonNull BugInstanceaddClassAndMethod(MethodDescriptor methodDescriptor)@NonNull BugInstanceaddClassAndMethod(MethodAnnotation methodAnnotation)Add class and method annotations for given method.@NonNull BugInstanceaddClassAndMethod(PreorderVisitor visitor)Add a class annotation and a method annotation for the class and method which the given visitor is currently visiting.@NonNull BugInstanceaddClassAndMethod(org.apache.bcel.classfile.JavaClass javaClass, org.apache.bcel.classfile.Method method)Add class and method annotations for given class and method.@NonNull BugInstanceaddClassAndMethod(org.apache.bcel.generic.MethodGen methodGen, java.lang.String sourceFile)Add class and method annotations for given method.@NonNull BugInstanceaddEqualsMethodUsed(@Nullable java.util.Collection<XMethod> equalsMethods)@NonNull BugInstanceaddEqualsMethodUsed(ClassDescriptor expectedClass)@NonNull BugInstanceaddField(FieldVariable field)Add a field annotation for a FieldVariable matched in a ByteCodePattern.@NonNull BugInstanceaddField(XField xfield)Add a field annotation for an XField.@NonNull BugInstanceaddField(FieldDescriptor fieldDescriptor)Add a field annotation for a FieldDescriptor.@NonNull BugInstanceaddField(FieldAnnotation fieldAnnotation)Add a field annotation@NonNull BugInstanceaddField(PreorderVisitor visitor)@NonNull BugInstanceaddField(java.lang.String className, java.lang.String fieldName, java.lang.String fieldSig, boolean isStatic)Add a field annotation.@NonNull BugInstanceaddField(java.lang.String className, java.lang.String fieldName, java.lang.String fieldSig, int accessFlags)Add a field annotation.BugInstanceaddFieldOrMethodValueSource(OpcodeStack.Item item)@NonNull BugInstanceaddFoundAndExpectedType(java.lang.String foundType, java.lang.String expectedType)@NonNull BugInstanceaddFoundAndExpectedType(org.apache.bcel.generic.Type foundType, org.apache.bcel.generic.Type expectedType)@NonNull BugInstanceaddInt(int value)Add an integer annotation.private voidaddJavaAnnotationNames(BugAnnotation annotation)@NonNull BugInstanceaddMethod(JavaClassAndMethod classAndMethod)Add a method annotation.@NonNull BugInstanceaddMethod(XMethod xmethod)Add a MethodAnnotation from an XMethod.@NonNull BugInstanceaddMethod(MethodDescriptor method)Add a MethodAnnotation from an MethodDescriptor.@NonNull BugInstanceaddMethod(MethodAnnotation methodAnnotation)Add a method annotation.@NonNull BugInstanceaddMethod(PreorderVisitor visitor)Add a method annotation for the method which the given visitor is currently visiting.@NonNull BugInstanceaddMethod(java.lang.String className, java.lang.String methodName, java.lang.String methodSig, boolean isStatic)Add a method annotation.@NonNull BugInstanceaddMethod(java.lang.String className, java.lang.String methodName, java.lang.String methodSig, int accessFlags)Add a method annotation.@NonNull BugInstanceaddMethod(org.apache.bcel.classfile.JavaClass javaClass, org.apache.bcel.classfile.Method method)Add a method annotation.@NonNull BugInstanceaddMethod(org.apache.bcel.generic.MethodGen methodGen, java.lang.String sourceFile)Add a method annotation.BugInstanceaddOptionalAnnotation(@Nullable BugAnnotation annotation)BugInstanceaddOptionalAnnotation(@Nullable BugAnnotation annotation, java.lang.String role)@NonNull BugInstanceaddOptionalField(@Nullable XField xfield)Add a field annotation for an XField.@NonNull BugInstanceaddOptionalLocalVariable(DismantleBytecode dbc, OpcodeStack.Item item)Local variable addersBugInstanceaddOptionalUniqueAnnotations(BugAnnotation... annotations)BugInstanceaddOptionalUniqueAnnotationsWithFallback(BugAnnotation fallback, BugAnnotation... annotations)@NonNull BugInstanceaddParameterAnnotation(int index, java.lang.String role)Add an annotation about a parameterprivate voidaddProperty(BugProperty prop)@NonNull BugInstanceaddReferencedField(FieldAnnotation fa)Add a field annotation for the field referenced by the FieldAnnotation parameter@NonNull BugInstanceaddReferencedField(DismantleBytecode visitor)Add a field annotation for the field which has just been accessed by the method currently being visited by given visitor.BugInstanceaddSomeSourceForTopTwoStackValues(ClassContext classContext, org.apache.bcel.classfile.Method method, Location location)BugInstanceaddSourceForTopStackValue(ClassContext classContext, org.apache.bcel.classfile.Method method, Location location)@NonNull BugInstanceaddSourceLine(ClassContext classContext, PreorderVisitor visitor, int pc)Add a source line annotation for instruction whose PC is given in the method that the given visitor is currently visiting.@NonNull BugInstanceaddSourceLine(ClassContext classContext, org.apache.bcel.classfile.Method method, Location location)Add source line annotation for given Location in a method.@NonNull BugInstanceaddSourceLine(ClassContext classContext, org.apache.bcel.classfile.Method method, org.apache.bcel.generic.InstructionHandle handle)Add source line annotation for given Location in a method.@NonNull BugInstanceaddSourceLine(ClassContext classContext, org.apache.bcel.generic.MethodGen methodGen, java.lang.String sourceFile, @NonNull org.apache.bcel.generic.InstructionHandle handle)Add a source line annotation for the given instruction in the given method.@NonNull BugInstanceaddSourceLine(ClassContext classContext, org.apache.bcel.generic.MethodGen methodGen, java.lang.String sourceFile, org.apache.bcel.generic.InstructionHandle start, org.apache.bcel.generic.InstructionHandle end)Add a source line annotation describing a range of instructions.@NonNull BugInstanceaddSourceLine(BytecodeScanningDetector visitor)Add a source line annotation for instruction currently being visited by given visitor.@NonNull BugInstanceaddSourceLine(BytecodeScanningDetector visitor, int pc)Add a source line annotation for instruction whose PC is given in the method that the given visitor is currently visiting.@NonNull BugInstanceaddSourceLine(MethodDescriptor methodDescriptor, Location location)Add source line annotation for given Location in a method.@NonNull BugInstanceaddSourceLine(SourceLineAnnotation sourceLine)Add a source line annotation.@NonNull BugInstanceaddSourceLineRange(ClassContext classContext, PreorderVisitor visitor, int startPC, int endPC)Add a source line annotation describing the source line numbers for a range of instructions in the method being visited by the given visitor.@NonNull BugInstanceaddSourceLineRange(BytecodeScanningDetector visitor, int startPC, int endPC)Add a source line annotation describing the source line numbers for a range of instructions in the method being visited by the given visitor.private voidaddSourceLinesForMethod(MethodAnnotation methodAnnotation, SourceLineAnnotation sourceLineAnnotation)@NonNull BugInstanceaddString(char c)Add a String annotation.@NonNull BugInstanceaddString(java.lang.String value)Add a String annotation.@NonNull BugInstanceaddSuperclass(PreorderVisitor visitor)Add a class annotation for the superclass of the class the visitor is currently visiting.@NonNull BugInstanceaddType(ClassDescriptor c)@NonNull BugInstanceaddType(java.lang.String typeDescriptor)Add a type annotation.@NonNull BugInstanceaddType(org.apache.bcel.generic.Type type)@NonNull BugInstanceaddTypeOfNamedClass(java.lang.String typeName)@NonNull BugInstanceaddUnknownSourceLine(java.lang.String className, java.lang.String sourceFile)Add a non-specific source line annotation.BugInstanceaddValueSource(@Nullable OpcodeStack.Item item, DismantleBytecode dbc)BugInstanceaddValueSource(OpcodeStack.Item item, org.apache.bcel.classfile.Method method, int pc)@NonNull BugInstanceaddVisitedField(PreorderVisitor visitor)Add a field annotation for the field which is being visited by given visitor.voidadjustForDetector(java.lang.String detectorName)Deprecated, for removal: This API element is subject to removal in a future version.java.util.Iterator<BugAnnotation>annotationIterator()Get an Iterator over all bug annotations.static intboundedPriority(int p)private voidboundPriority()voidclearHistory()java.lang.Objectclone()intcompareTo(BugInstance other)booleandeleteProperty(java.lang.String name)Delete property with given name.@NonNull BugInstancedescribe(java.lang.String description)Add a description to the most recently added bug annotation.booleanequals(java.lang.Object o)private <T extends BugAnnotation>
@Nullable TfindPrimaryAnnotationOfType(java.lang.Class<T> cls)Find the first BugAnnotation in the list of annotations that is the same type or a subtype as the given Class parameter.static java.text.DateFormatfirstSeenXMLFormat()private voidfoundInAutogeneratedMethod()java.lang.StringgetAbbrev()Get the abbreviation of this bug instance's BugPattern.java.lang.StringgetAbridgedMessage()java.util.List<BugAnnotation>getAnnotations()Get an Iterator over all bug annotations.java.util.List<BugAnnotation>getAnnotationsForMessage(boolean showContext)<A extends BugAnnotation>
@Nullable AgetAnnotationWithRole(java.lang.Class<A> c, java.lang.String role)Get the first bug annotation with the specified class and role; return null if no such annotation exists;java.util.Collection<SourceLineAnnotation>getAnotherInstanceSourceLineAnnotations()@NonNull BugPatterngetBugPattern()Get the BugPattern.intgetBugRank()BugRankCategorygetBugRankCategory()java.lang.StringgetCategoryAbbrev()intgetCWEid()@Nullable DetectorFactorygetDetectorFactory()static @Nullable BugAnnotationgetFieldOrMethodValueSource(@Nullable OpcodeStack.Item item)longgetFirstVersion()java.lang.StringgetInstanceHash()java.lang.StringgetInstanceKey()private java.lang.StringgetInstanceKeyNew()intgetInstanceOccurrenceMax()intgetInstanceOccurrenceNum()longgetLastVersion()(package private) java.lang.StringgetLongDescription()java.lang.StringgetMessage()Format a string describing this bug instance.@NonNull java.lang.StringgetMessageWithoutPrefix()Format a string describing this bug instance.java.lang.StringgetMessageWithPriorityType()Format a string describing this bug pattern, with the priority and type at the beginning.java.lang.StringgetMessageWithPriorityTypeAbbreviation()ClassAnnotationgetPrimaryClass()Get the primary class annotation, which indicates where the bug occurs.@Nullable FieldAnnotationgetPrimaryField()Get the primary field annotation, which indicates where the bug occurs.LocalVariableAnnotationgetPrimaryLocalVariableAnnotation()@Nullable MethodAnnotationgetPrimaryMethod()Get the primary method annotation, which indicates where the bug occurs.@NonNull SourceLineAnnotationgetPrimarySourceLineAnnotation()Get the primary source line annotation.@Nullable TypeAnnotationgetPrimaryType()Get the primary type annotation, which indicates where the bug occurs.intgetPriority()Get the bug priority.java.lang.StringgetPriorityAbbreviation()java.lang.StringgetPriorityString()java.lang.StringgetPriorityTypeAbbreviation()java.lang.StringgetPriorityTypeString()Get a string describing the bug priority and type.java.lang.StringgetProperty(java.lang.String name)Get value of given property.java.lang.StringgetProperty(java.lang.String name, java.lang.String defaultValue)Get value of given property, returning given default value if the property has not been set.static @Nullable BugAnnotationgetSomeSource(ClassContext classContext, org.apache.bcel.classfile.Method method, Location location, OpcodeStack stack, int stackPos)static @Nullable BugAnnotationgetSourceForStackValue(ClassContext classContext, org.apache.bcel.classfile.Method method, Location location, int depth)static @Nullable BugAnnotationgetSourceForTopStackValue(ClassContext classContext, org.apache.bcel.classfile.Method method, Location location)java.lang.StringgetType()Get the bug pattern name (e.g., IL_INFINITE_RECURSIVE_LOOP)static @Nullable BugAnnotationgetValueSource(OpcodeStack.Item item, org.apache.bcel.classfile.Method method, int pc)inthashCode()private SourceLineAnnotationinspectPackageMemberSourceLines(PackageMemberAnnotation packageMember)If given PackageMemberAnnotation is non-null, return its SourceLineAnnotation.booleanisDead()booleanisExperimental()Is this bug instance the result of an experimental detector?booleanisInstanceHashConsistent()booleanisIntroducedByChangeOfExistingClass()booleanisRemovedByChangeOfPersistingClass()BugPropertylookupProperty(java.lang.String name)Look up a property by name.voidlowerPriority()voidlowerPriorityALot()@NonNull BugInstancelowerPriorityIfDeprecated()private voidoptionalAdd(java.util.Collection<BugAnnotation> c, BugAnnotation a)java.util.Iterator<BugProperty>propertyIterator()Get an Iterator over the properties defined in this BugInstance.voidraisePriority()voidrememberDetectorFactory(java.lang.String detectorName)static voidsetAdjustExperimental(boolean adjust)voidsetFirstVersion(long firstVersion)voidsetHistory(BugInstance from)voidsetInstanceHash(java.lang.String instanceHash)voidsetInstanceOccurrenceMax(int instanceOccurrenceMax)voidsetInstanceOccurrenceNum(int instanceOccurrenceNum)voidsetIntroducedByChangeOfExistingClass(boolean introducedByChangeOfExistingClass)voidsetLastVersion(long lastVersion)voidsetLive()Mark the bug instance is being alive (still present in the last version)voidsetOldInstanceHash(java.lang.String oldInstanceHash)voidsetPriority(int p)Set the bug priority.@NonNull BugInstancesetProperty(java.lang.String name, java.lang.String value)Set value of given property.voidsetRemovedByChangeOfPersistingClass(boolean removedByChangeOfPersistingClass)java.lang.StringtoString()Convert to String.booleantryAddingOptionalUniqueAnnotations(BugAnnotation... annotations)voidwriteXML(XMLOutput xmlOutput)Write this object to given XMLOutput.voidwriteXML(XMLOutput xmlOutput, BugCollection bugCollection, boolean addMessages)
-
-
-
Field Detail
-
LOG
private static final org.slf4j.Logger LOG
-
type
private final java.lang.String type
-
priority
private int priority
-
annotationList
private final java.util.List<BugAnnotation> annotationList
-
cachedHashCode
private int cachedHashCode
-
propertyListHead
private BugProperty propertyListHead
-
propertyListTail
private BugProperty propertyListTail
-
oldInstanceHash
private java.lang.String oldInstanceHash
-
instanceHash
private java.lang.String instanceHash
-
instanceOccurrenceNum
private int instanceOccurrenceNum
-
instanceOccurrenceMax
private int instanceOccurrenceMax
-
detectorFactory
private @Nullable DetectorFactory detectorFactory
-
firstVersion
private long firstVersion
-
lastVersion
private long lastVersion
-
introducedByChangeOfExistingClass
private boolean introducedByChangeOfExistingClass
-
removedByChangeOfPersistingClass
private boolean removedByChangeOfPersistingClass
-
INVALID_HASH_CODE
private static final int INVALID_HASH_CODE
This value is used to indicate that the cached hashcode is invalid, and should be recomputed.- See Also:
- Constant Field Values
-
ELEMENT_NAME
private static final java.lang.String ELEMENT_NAME
- See Also:
- Constant Field Values
-
adjustExperimental
private static boolean adjustExperimental
This value is used to indicate whether BugInstances should be reprioritized very low, when the BugPattern is marked as experimental
-
missingBugTypes
private static final java.util.Set<java.lang.String> missingBugTypes
-
-
Constructor Detail
-
BugInstance
public BugInstance(java.lang.String type, int priority)Constructor.- Parameters:
type- the bug typepriority- the bug priority
-
BugInstance
public BugInstance(Detector detector, java.lang.String type, int priority)
Create a new BugInstance. This is the constructor that should be used by Detectors.- Parameters:
detector- the Detector that is reporting the BugInstancetype- the bug typepriority- the bug priority
-
BugInstance
public BugInstance(Detector2 detector, java.lang.String type, int priority)
Create a new BugInstance. This is the constructor that should be used by Detectors.- Parameters:
detector- the Detector2 that is reporting the BugInstancetype- the bug typepriority- the bug priority
-
-
Method Detail
-
firstSeenXMLFormat
public static java.text.DateFormat firstSeenXMLFormat()
-
boundPriority
private void boundPriority()
-
clone
public java.lang.Object clone()
- Overrides:
clonein classjava.lang.Object
-
adjustForDetector
@Deprecated(forRemoval=true) public void adjustForDetector(java.lang.String detectorName)
Deprecated, for removal: This API element is subject to removal in a future version.
-
rememberDetectorFactory
public void rememberDetectorFactory(java.lang.String detectorName)
- Parameters:
detectorName-
-
setAdjustExperimental
public static void setAdjustExperimental(boolean adjust)
-
getType
public java.lang.String getType()
Get the bug pattern name (e.g., IL_INFINITE_RECURSIVE_LOOP)
-
getBugPattern
public @NonNull BugPattern getBugPattern()
Get the BugPattern.
-
getPriority
public int getPriority()
Get the bug priority.
-
getBugRank
public int getBugRank()
-
getBugRankCategory
public BugRankCategory getBugRankCategory()
-
getPriorityTypeString
public java.lang.String getPriorityTypeString()
Get a string describing the bug priority and type. e.g. "High Priority Correctness"- Returns:
- a string describing the bug priority and type
-
getPriorityTypeAbbreviation
public java.lang.String getPriorityTypeAbbreviation()
-
getCategoryAbbrev
public java.lang.String getCategoryAbbrev()
-
getPriorityString
public java.lang.String getPriorityString()
-
getPriorityAbbreviation
public java.lang.String getPriorityAbbreviation()
-
setPriority
public void setPriority(int p)
Set the bug priority.
-
boundedPriority
public static int boundedPriority(int p)
-
raisePriority
public void raisePriority()
-
lowerPriority
public void lowerPriority()
-
lowerPriorityALot
public void lowerPriorityALot()
-
isExperimental
public boolean isExperimental()
Is this bug instance the result of an experimental detector?
-
getPrimaryClass
public ClassAnnotation getPrimaryClass()
Get the primary class annotation, which indicates where the bug occurs.
-
getPrimaryType
public @Nullable TypeAnnotation getPrimaryType()
Get the primary type annotation, which indicates where the bug occurs.
-
getPrimaryMethod
public @Nullable MethodAnnotation getPrimaryMethod()
Get the primary method annotation, which indicates where the bug occurs.
-
getPrimaryField
public @Nullable FieldAnnotation getPrimaryField()
Get the primary field annotation, which indicates where the bug occurs.
-
lowerPriorityIfDeprecated
public @NonNull BugInstance lowerPriorityIfDeprecated()
-
findPrimaryAnnotationOfType
private <T extends BugAnnotation> @Nullable T findPrimaryAnnotationOfType(java.lang.Class<T> cls)
Find the first BugAnnotation in the list of annotations that is the same type or a subtype as the given Class parameter.- Parameters:
cls- the Class parameter- Returns:
- the first matching BugAnnotation of the given type, or null if there is no such BugAnnotation
-
getPrimaryLocalVariableAnnotation
public LocalVariableAnnotation getPrimaryLocalVariableAnnotation()
-
getPrimarySourceLineAnnotation
public @NonNull SourceLineAnnotation getPrimarySourceLineAnnotation()
Get the primary source line annotation. There is guaranteed to be one (unless some Detector constructed an invalid BugInstance).- Returns:
- the source line annotation
-
getAnotherInstanceSourceLineAnnotations
public java.util.Collection<SourceLineAnnotation> getAnotherInstanceSourceLineAnnotations()
-
getInstanceKey
public java.lang.String getInstanceKey()
-
getInstanceKeyNew
private java.lang.String getInstanceKeyNew()
-
inspectPackageMemberSourceLines
private SourceLineAnnotation inspectPackageMemberSourceLines(PackageMemberAnnotation packageMember)
If given PackageMemberAnnotation is non-null, return its SourceLineAnnotation.- Parameters:
packageMember- a PackageMemberAnnotation- Returns:
- the PackageMemberAnnotation's SourceLineAnnotation, or null if there is no SourceLineAnnotation
-
annotationIterator
public java.util.Iterator<BugAnnotation> annotationIterator()
Get an Iterator over all bug annotations.
-
getAnnotations
public java.util.List<BugAnnotation> getAnnotations()
Get an Iterator over all bug annotations.
-
getAnnotationWithRole
public <A extends BugAnnotation> @Nullable A getAnnotationWithRole(java.lang.Class<A> c, java.lang.String role)
Get the first bug annotation with the specified class and role; return null if no such annotation exists;
-
getAbbrev
public java.lang.String getAbbrev()
Get the abbreviation of this bug instance's BugPattern. This is the same abbreviation used by the BugCode which the BugPattern is a particular species of.
-
getProperty
public java.lang.String getProperty(java.lang.String name)
Get value of given property.- Parameters:
name- name of the property to get- Returns:
- the value of the named property, or null if the property has not been set
-
getProperty
public java.lang.String getProperty(java.lang.String name, java.lang.String defaultValue)Get value of given property, returning given default value if the property has not been set.- Parameters:
name- name of the property to getdefaultValue- default value to return if property is not set- Returns:
- the value of the named property, or the default value if the property has not been set
-
propertyIterator
public java.util.Iterator<BugProperty> propertyIterator()
Get an Iterator over the properties defined in this BugInstance.- Returns:
- Iterator over properties
-
setProperty
public @NonNull BugInstance setProperty(java.lang.String name, java.lang.String value)
Set value of given property.- Parameters:
name- name of the property to setvalue- the value of the property- Returns:
- this object, so calls can be chained
-
lookupProperty
public BugProperty lookupProperty(java.lang.String name)
Look up a property by name.- Parameters:
name- name of the property to look for- Returns:
- the BugProperty with the given name, or null if the property has not been set
-
deleteProperty
public boolean deleteProperty(java.lang.String name)
Delete property with given name.- Parameters:
name- name of the property to delete- Returns:
- true if a property with that name was deleted, or false if there is no such property
-
addProperty
private void addProperty(BugProperty prop)
-
addAnnotations
public @NonNull BugInstance addAnnotations(java.util.Collection<? extends BugAnnotation> annotationCollection)
Add a Collection of BugAnnotations.- Parameters:
annotationCollection- Collection of BugAnnotations
-
addClassAndMethod
public @NonNull BugInstance addClassAndMethod(MethodDescriptor methodDescriptor)
-
addClassAndMethod
public BugInstance addClassAndMethod(XMethod xMethod)
-
addClassAndMethod
public @NonNull BugInstance addClassAndMethod(PreorderVisitor visitor)
Add a class annotation and a method annotation for the class and method which the given visitor is currently visiting.- Parameters:
visitor- the BetterVisitor- Returns:
- this object
-
foundInAutogeneratedMethod
private void foundInAutogeneratedMethod()
-
addClassAndMethod
public @NonNull BugInstance addClassAndMethod(MethodAnnotation methodAnnotation)
Add class and method annotations for given method.- Parameters:
methodAnnotation- the method- Returns:
- this object
-
addClassAndMethod
public @NonNull BugInstance addClassAndMethod(org.apache.bcel.generic.MethodGen methodGen, java.lang.String sourceFile)
Add class and method annotations for given method.- Parameters:
methodGen- the methodsourceFile- source file the method is defined in- Returns:
- this object
-
addClassAndMethod
public @NonNull BugInstance addClassAndMethod(org.apache.bcel.classfile.JavaClass javaClass, org.apache.bcel.classfile.Method method)
Add class and method annotations for given class and method.- Parameters:
javaClass- the classmethod- the method- Returns:
- this object
-
addClass
public @NonNull BugInstance addClass(java.lang.String className, java.lang.String sourceFileName)
Add a class annotation. If this is the first class annotation added, it becomes the primary class annotation.- Parameters:
className- the name of the classsourceFileName- the source file of the class- Returns:
- this object
-
addClass
public @NonNull BugInstance addClass(@SlashedClassName(when=UNKNOWN) java.lang.String className)
Add a class annotation. If this is the first class annotation added, it becomes the primary class annotation.- Parameters:
className- the name of the class- Returns:
- this object
-
addClass
public @NonNull BugInstance addClass(org.objectweb.asm.tree.ClassNode classNode)
Add a class annotation for the classNode.- Parameters:
classNode- the ASM visitor- Returns:
- this object
-
addClass
public @NonNull BugInstance addClass(ClassDescriptor classDescriptor)
Add a class annotation. If this is the first class annotation added, it becomes the primary class annotation.- Parameters:
classDescriptor- the class to add- Returns:
- this object
-
addClass
public @NonNull BugInstance addClass(org.apache.bcel.classfile.JavaClass jclass)
Add a class annotation. If this is the first class annotation added, it becomes the primary class annotation.- Parameters:
jclass- the JavaClass object for the class- Returns:
- this object
-
addClass
public @NonNull BugInstance addClass(PreorderVisitor visitor)
Add a class annotation for the class that the visitor is currently visiting.- Parameters:
visitor- the BetterVisitor- Returns:
- this object
-
addSuperclass
public @NonNull BugInstance addSuperclass(PreorderVisitor visitor)
Add a class annotation for the superclass of the class the visitor is currently visiting.- Parameters:
visitor- the BetterVisitor- Returns:
- this object
-
addType
public @NonNull BugInstance addType(java.lang.String typeDescriptor)
Add a type annotation. Handy for referring to array types.For information on type descriptors,
see TypeDescriptors.- Parameters:
typeDescriptor- a jvm type descriptor, such as "[I"- Returns:
- this object
-
addType
public @NonNull BugInstance addType(org.apache.bcel.generic.Type type)
-
addFoundAndExpectedType
public @NonNull BugInstance addFoundAndExpectedType(org.apache.bcel.generic.Type foundType, org.apache.bcel.generic.Type expectedType)
-
addFoundAndExpectedType
public @NonNull BugInstance addFoundAndExpectedType(java.lang.String foundType, java.lang.String expectedType)
-
addEqualsMethodUsed
public @NonNull BugInstance addEqualsMethodUsed(ClassDescriptor expectedClass)
-
addEqualsMethodUsed
public @NonNull BugInstance addEqualsMethodUsed(@Nullable java.util.Collection<XMethod> equalsMethods)
-
addTypeOfNamedClass
public @NonNull BugInstance addTypeOfNamedClass(@DottedClassName java.lang.String typeName)
-
addType
public @NonNull BugInstance addType(ClassDescriptor c)
-
addField
public @NonNull BugInstance addField(@DottedClassName java.lang.String className, java.lang.String fieldName, java.lang.String fieldSig, boolean isStatic)
Add a field annotation.- Parameters:
className- the dotted name of the class containing the fieldfieldName- the name of the fieldfieldSig- type signature of the fieldisStatic- whether the field is static- Returns:
- this object
-
addField
public @NonNull BugInstance addField(@DottedClassName java.lang.String className, java.lang.String fieldName, java.lang.String fieldSig, int accessFlags)
Add a field annotation.- Parameters:
className- the dotted name of the class containing the fieldfieldName- the name of the fieldfieldSig- type signature of the fieldaccessFlags- access flags for the field- Returns:
- this object
-
addField
public @NonNull BugInstance addField(PreorderVisitor visitor)
-
addField
public @NonNull BugInstance addField(FieldAnnotation fieldAnnotation)
Add a field annotation- Parameters:
fieldAnnotation- the field annotation- Returns:
- this object
-
addField
public @NonNull BugInstance addField(FieldVariable field)
Add a field annotation for a FieldVariable matched in a ByteCodePattern.- Parameters:
field- the FieldVariable- Returns:
- this object
-
addOptionalField
public @NonNull BugInstance addOptionalField(@Nullable XField xfield)
Add a field annotation for an XField.- Parameters:
xfield- the XField- Returns:
- this object
-
addField
public @NonNull BugInstance addField(XField xfield)
Add a field annotation for an XField.- Parameters:
xfield- the XField- Returns:
- this object
-
addField
public @NonNull BugInstance addField(FieldDescriptor fieldDescriptor)
Add a field annotation for a FieldDescriptor.- Parameters:
fieldDescriptor- the FieldDescriptor- Returns:
- this object
-
addReferencedField
public @NonNull BugInstance addReferencedField(DismantleBytecode visitor)
Add a field annotation for the field which has just been accessed by the method currently being visited by given visitor. Assumes that a getfield/putfield or getstatic/putstatic has just been seen.- Parameters:
visitor- the DismantleBytecode object- Returns:
- this object
-
addReferencedField
public @NonNull BugInstance addReferencedField(FieldAnnotation fa)
Add a field annotation for the field referenced by the FieldAnnotation parameter
-
addVisitedField
public @NonNull BugInstance addVisitedField(PreorderVisitor visitor)
Add a field annotation for the field which is being visited by given visitor.- Parameters:
visitor- the visitor- Returns:
- this object
-
addOptionalLocalVariable
public @NonNull BugInstance addOptionalLocalVariable(DismantleBytecode dbc, OpcodeStack.Item item)
Local variable adders
-
addMethod
public @NonNull BugInstance addMethod(java.lang.String className, java.lang.String methodName, java.lang.String methodSig, boolean isStatic)
Add a method annotation. If this is the first method annotation added, it becomes the primary method annotation.- Parameters:
className- name of the class containing the methodmethodName- name of the methodmethodSig- type signature of the methodisStatic- true if the method is static, false otherwise- Returns:
- this object
-
addMethod
public @NonNull BugInstance addMethod(@SlashedClassName java.lang.String className, java.lang.String methodName, java.lang.String methodSig, int accessFlags)
Add a method annotation. If this is the first method annotation added, it becomes the primary method annotation.- Parameters:
className- name of the class containing the methodmethodName- name of the methodmethodSig- type signature of the methodaccessFlags- accessFlags for the method- Returns:
- this object
-
addMethod
public @NonNull BugInstance addMethod(org.apache.bcel.generic.MethodGen methodGen, java.lang.String sourceFile)
Add a method annotation. If this is the first method annotation added, it becomes the primary method annotation. If the method has source line information, then a SourceLineAnnotation is added to the method.- Parameters:
methodGen- the MethodGen object for the methodsourceFile- source file method is defined in- Returns:
- this object
-
addMethod
public @NonNull BugInstance addMethod(org.apache.bcel.classfile.JavaClass javaClass, org.apache.bcel.classfile.Method method)
Add a method annotation. If this is the first method annotation added, it becomes the primary method annotation. If the method has source line information, then a SourceLineAnnotation is added to the method.- Parameters:
javaClass- the class the method is defined inmethod- the method- Returns:
- this object
-
addMethod
public @NonNull BugInstance addMethod(JavaClassAndMethod classAndMethod)
Add a method annotation. If this is the first method annotation added, it becomes the primary method annotation. If the method has source line information, then a SourceLineAnnotation is added to the method.- Parameters:
classAndMethod- JavaClassAndMethod identifying the method to add- Returns:
- this object
-
addMethod
public @NonNull BugInstance addMethod(PreorderVisitor visitor)
Add a method annotation for the method which the given visitor is currently visiting. If the method has source line information, then a SourceLineAnnotation is added to the method.- Parameters:
visitor- the BetterVisitor- Returns:
- this object
-
addCalledMethod
public @NonNull BugInstance addCalledMethod(DismantleBytecode visitor)
Add a method annotation for the method which has been called by the method currently being visited by given visitor. Assumes that the visitor has just looked at an invoke instruction of some kind.- Parameters:
visitor- the DismantleBytecode object- Returns:
- this object
-
addCalledMethod
public @NonNull BugInstance addCalledMethod(XMethod m)
-
addCalledMethod
public @NonNull BugInstance addCalledMethod(java.lang.String className, java.lang.String methodName, java.lang.String methodSig, boolean isStatic)
Add a method annotation.- Parameters:
className- name of class containing called methodmethodName- name of called methodmethodSig- signature of called methodisStatic- true if called method is static, false if not- Returns:
- this object
-
addCalledMethod
public @NonNull BugInstance addCalledMethod(org.apache.bcel.generic.ConstantPoolGen cpg, org.apache.bcel.generic.InvokeInstruction inv)
Add a method annotation for the method which is called by given instruction.- Parameters:
cpg- the constant pool for the method containing the callinv- the InvokeInstruction- Returns:
- this object
-
addCalledMethod
public @NonNull BugInstance addCalledMethod(org.apache.bcel.generic.MethodGen methodGen, org.apache.bcel.generic.InvokeInstruction inv)
Add a method annotation for the method which is called by given instruction.- Parameters:
methodGen- the method containing the callinv- the InvokeInstruction- Returns:
- this object
-
addMethod
public @NonNull BugInstance addMethod(XMethod xmethod)
Add a MethodAnnotation from an XMethod.- Parameters:
xmethod- the XMethod- Returns:
- this object
-
addMethod
public @NonNull BugInstance addMethod(MethodDescriptor method)
Add a MethodAnnotation from an MethodDescriptor.- Parameters:
method- the method- Returns:
- this object
-
addMethod
public @NonNull BugInstance addMethod(MethodAnnotation methodAnnotation)
Add a method annotation. If this is the first method annotation added, it becomes the primary method annotation.- Parameters:
methodAnnotation- the method annotation- Returns:
- this object
-
addInt
public @NonNull BugInstance addInt(int value)
Add an integer annotation.- Parameters:
value- the integer value- Returns:
- this object
-
addParameterAnnotation
public @NonNull BugInstance addParameterAnnotation(int index, java.lang.String role)
Add an annotation about a parameter- Parameters:
index- parameter index, starting from 0role- the role used to describe the parameter
-
addString
public @NonNull BugInstance addString(java.lang.String value)
Add a String annotation.- Parameters:
value- the String value- Returns:
- this object
-
addString
public @NonNull BugInstance addString(char c)
Add a String annotation.- Parameters:
c- the char value- Returns:
- this object
-
addSourceLine
public @NonNull BugInstance addSourceLine(SourceLineAnnotation sourceLine)
Add a source line annotation.- Parameters:
sourceLine- the source line annotation- Returns:
- this object
-
addSourceLine
public @NonNull BugInstance addSourceLine(BytecodeScanningDetector visitor, int pc)
Add a source line annotation for instruction whose PC is given in the method that the given visitor is currently visiting. Note that if the method does not have line number information, then no source line annotation will be added.- Parameters:
visitor- a BytecodeScanningDetector that is currently visiting the methodpc- bytecode offset of the instruction- Returns:
- this object
-
addSourceLine
public @NonNull BugInstance addSourceLine(ClassContext classContext, PreorderVisitor visitor, int pc)
Add a source line annotation for instruction whose PC is given in the method that the given visitor is currently visiting. Note that if the method does not have line number information, then no source line annotation will be added.- Parameters:
classContext- the ClassContextvisitor- a PreorderVisitor that is currently visiting the methodpc- bytecode offset of the instruction- Returns:
- this object
-
addSourceLine
public @NonNull BugInstance addSourceLine(ClassContext classContext, org.apache.bcel.generic.MethodGen methodGen, java.lang.String sourceFile, @NonNull org.apache.bcel.generic.InstructionHandle handle)
Add a source line annotation for the given instruction in the given method. Note that if the method does not have line number information, then no source line annotation will be added.- Parameters:
classContext- the ClassContextmethodGen- the method being visitedsourceFile- source file the method is defined inhandle- the InstructionHandle containing the visited instruction- Returns:
- this object
-
addSourceLine
public @NonNull BugInstance addSourceLine(ClassContext classContext, org.apache.bcel.generic.MethodGen methodGen, java.lang.String sourceFile, org.apache.bcel.generic.InstructionHandle start, org.apache.bcel.generic.InstructionHandle end)
Add a source line annotation describing a range of instructions.- Parameters:
classContext- the ClassContextmethodGen- the methodsourceFile- source file the method is defined instart- the start instruction in the rangeend- the end instruction in the range (inclusive)- Returns:
- this object
-
addSourceLine
public @NonNull BugInstance addSourceLine(ClassContext classContext, org.apache.bcel.classfile.Method method, Location location)
Add source line annotation for given Location in a method.- Parameters:
classContext- the ClassContextmethod- the Methodlocation- the Location in the method- Returns:
- this BugInstance
-
addSourceLine
public @NonNull BugInstance addSourceLine(MethodDescriptor methodDescriptor, Location location)
Add source line annotation for given Location in a method.- Parameters:
methodDescriptor- the methodlocation- the Location in the method- Returns:
- this BugInstance
-
addSourceLine
public @NonNull BugInstance addSourceLine(ClassContext classContext, org.apache.bcel.classfile.Method method, org.apache.bcel.generic.InstructionHandle handle)
Add source line annotation for given Location in a method.- Parameters:
classContext- the ClassContextmethod- the Methodhandle- InstructionHandle of an instruction in the method- Returns:
- this BugInstance
-
addSourceLineRange
public @NonNull BugInstance addSourceLineRange(BytecodeScanningDetector visitor, int startPC, int endPC)
Add a source line annotation describing the source line numbers for a range of instructions in the method being visited by the given visitor. Note that if the method does not have line number information, then no source line annotation will be added.- Parameters:
visitor- a BetterVisitor which is visiting the methodstartPC- the bytecode offset of the start instruction in the rangeendPC- the bytecode offset of the end instruction in the range- Returns:
- this object
-
addSourceLineRange
public @NonNull BugInstance addSourceLineRange(ClassContext classContext, PreorderVisitor visitor, int startPC, int endPC)
Add a source line annotation describing the source line numbers for a range of instructions in the method being visited by the given visitor. Note that if the method does not have line number information, then no source line annotation will be added.- Parameters:
classContext- the ClassContextvisitor- a BetterVisitor which is visiting the methodstartPC- the bytecode offset of the start instruction in the rangeendPC- the bytecode offset of the end instruction in the range- Returns:
- this object
-
addSourceLine
public @NonNull BugInstance addSourceLine(BytecodeScanningDetector visitor)
Add a source line annotation for instruction currently being visited by given visitor. Note that if the method does not have line number information, then no source line annotation will be added.- Parameters:
visitor- a BytecodeScanningDetector visitor that is currently visiting the instruction- Returns:
- this object
-
addUnknownSourceLine
public @NonNull BugInstance addUnknownSourceLine(java.lang.String className, java.lang.String sourceFile)
Add a non-specific source line annotation. This will result in the entire source file being displayed.- Parameters:
className- the class namesourceFile- the source file name- Returns:
- this object
-
getMessageWithoutPrefix
public @NonNull java.lang.String getMessageWithoutPrefix()
Format a string describing this bug instance.- Returns:
- the description
-
getLongDescription
java.lang.String getLongDescription()
-
getAbridgedMessage
public java.lang.String getAbridgedMessage()
-
getMessage
public java.lang.String getMessage()
Format a string describing this bug instance.- Returns:
- the description
-
getMessageWithPriorityType
public java.lang.String getMessageWithPriorityType()
Format a string describing this bug pattern, with the priority and type at the beginning. e.g. "(High Priority Correctness) Guaranteed null pointer dereference..."
-
getMessageWithPriorityTypeAbbreviation
public java.lang.String getMessageWithPriorityTypeAbbreviation()
-
describe
public @NonNull BugInstance describe(java.lang.String description)
Add a description to the most recently added bug annotation.- Parameters:
description- the description to add- Returns:
- this object
-
toString
public java.lang.String toString()
Convert to String. This method returns the "short" message describing the bug, as opposed to the longer format returned by getMessage(). The short format is appropriate for the tree view in a GUI, where the annotations are listed separately as part of the overall bug instance.- Overrides:
toStringin classjava.lang.Object
-
writeXML
public void writeXML(XMLOutput xmlOutput) throws java.io.IOException
Description copied from interface:XMLWriteableWrite this object to given XMLOutput.- Specified by:
writeXMLin interfaceXMLWriteable- Parameters:
xmlOutput- the XMLOutput for the document- Throws:
java.io.IOException
-
getCWEid
public int getCWEid()
-
writeXML
public void writeXML(XMLOutput xmlOutput, BugCollection bugCollection, boolean addMessages) throws java.io.IOException
- Throws:
java.io.IOException
-
addOptionalAnnotation
public BugInstance addOptionalAnnotation(@Nullable BugAnnotation annotation)
-
addOptionalAnnotation
public BugInstance addOptionalAnnotation(@Nullable BugAnnotation annotation, java.lang.String role)
-
addJavaAnnotationNames
private void addJavaAnnotationNames(BugAnnotation annotation)
-
addAnnotationNames
private static void addAnnotationNames(PackageMemberAnnotation pma, org.apache.bcel.classfile.AnnotationEntry[] annotationEntries)
-
add
public BugInstance add(@NonNull BugAnnotation annotation)
-
addSomeSourceForTopTwoStackValues
public BugInstance addSomeSourceForTopTwoStackValues(ClassContext classContext, org.apache.bcel.classfile.Method method, Location location)
-
addSourceForTopStackValue
public BugInstance addSourceForTopStackValue(ClassContext classContext, org.apache.bcel.classfile.Method method, Location location)
-
getSourceForTopStackValue
public static @Nullable BugAnnotation getSourceForTopStackValue(ClassContext classContext, org.apache.bcel.classfile.Method method, Location location)
-
getSourceForStackValue
public static @Nullable BugAnnotation getSourceForStackValue(ClassContext classContext, org.apache.bcel.classfile.Method method, Location location, int depth)
-
getSomeSource
public static @Nullable BugAnnotation getSomeSource(ClassContext classContext, org.apache.bcel.classfile.Method method, Location location, OpcodeStack stack, int stackPos)
-
getValueSource
public static @Nullable BugAnnotation getValueSource(OpcodeStack.Item item, org.apache.bcel.classfile.Method method, int pc)
-
addValueSource
public BugInstance addValueSource(@Nullable OpcodeStack.Item item, DismantleBytecode dbc)
-
addValueSource
public BugInstance addValueSource(OpcodeStack.Item item, org.apache.bcel.classfile.Method method, int pc)
-
addFieldOrMethodValueSource
public BugInstance addFieldOrMethodValueSource(OpcodeStack.Item item)
-
addOptionalUniqueAnnotations
public BugInstance addOptionalUniqueAnnotations(BugAnnotation... annotations)
-
tryAddingOptionalUniqueAnnotations
public boolean tryAddingOptionalUniqueAnnotations(BugAnnotation... annotations)
-
addOptionalUniqueAnnotationsWithFallback
public BugInstance addOptionalUniqueAnnotationsWithFallback(BugAnnotation fallback, BugAnnotation... annotations)
-
getFieldOrMethodValueSource
public static @Nullable BugAnnotation getFieldOrMethodValueSource(@Nullable OpcodeStack.Item item)
-
addSourceLinesForMethod
private void addSourceLinesForMethod(MethodAnnotation methodAnnotation, SourceLineAnnotation sourceLineAnnotation)
-
hashCode
public int hashCode()
- Overrides:
hashCodein classjava.lang.Object
-
equals
public boolean equals(java.lang.Object o)
- Overrides:
equalsin classjava.lang.Object
-
compareTo
public int compareTo(BugInstance other)
- Specified by:
compareToin interfacejava.lang.Comparable<BugInstance>
-
setFirstVersion
public void setFirstVersion(long firstVersion)
-
clearHistory
public void clearHistory()
-
getFirstVersion
public long getFirstVersion()
-
setHistory
public void setHistory(BugInstance from)
-
setLastVersion
public void setLastVersion(long lastVersion)
-
setLive
public void setLive()
Mark the bug instance is being alive (still present in the last version)
-
getLastVersion
public long getLastVersion()
-
isDead
public boolean isDead()
-
setIntroducedByChangeOfExistingClass
public void setIntroducedByChangeOfExistingClass(boolean introducedByChangeOfExistingClass)
-
isIntroducedByChangeOfExistingClass
public boolean isIntroducedByChangeOfExistingClass()
-
setRemovedByChangeOfPersistingClass
public void setRemovedByChangeOfPersistingClass(boolean removedByChangeOfPersistingClass)
-
isRemovedByChangeOfPersistingClass
public boolean isRemovedByChangeOfPersistingClass()
-
setInstanceHash
public void setInstanceHash(java.lang.String instanceHash)
-
setOldInstanceHash
public void setOldInstanceHash(java.lang.String oldInstanceHash)
-
getInstanceHash
public java.lang.String getInstanceHash()
-
isInstanceHashConsistent
public boolean isInstanceHashConsistent()
-
setInstanceOccurrenceNum
public void setInstanceOccurrenceNum(int instanceOccurrenceNum)
-
getInstanceOccurrenceNum
public int getInstanceOccurrenceNum()
-
setInstanceOccurrenceMax
public void setInstanceOccurrenceMax(int instanceOccurrenceMax)
-
getInstanceOccurrenceMax
public int getInstanceOccurrenceMax()
-
getDetectorFactory
public @Nullable DetectorFactory getDetectorFactory()
-
optionalAdd
private void optionalAdd(java.util.Collection<BugAnnotation> c, BugAnnotation a)
-
getAnnotationsForMessage
public java.util.List<BugAnnotation> getAnnotationsForMessage(boolean showContext)
-
-