Package edu.umd.cs.findbugs
Class BugInstance
- java.lang.Object
-
- edu.umd.cs.findbugs.BugInstance
-
- All Implemented Interfaces:
XMLWriteable
,XMLWriteableWithMessages
,java.io.Serializable
,java.lang.Cloneable
,java.lang.Comparable<BugInstance>
public class BugInstance extends java.lang.Object implements java.lang.Comparable<BugInstance>, XMLWriteableWithMessages, java.io.Serializable, 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
BugInstance objects are built up by calling a string of
add
methods. (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.- Author:
- David Hovemeyer
- See Also:
BugAnnotation
, Serialized Form
-
-
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 BugInstance
add(BugAnnotation annotation)
BugInstance
addAnnotations(java.util.Collection<? extends BugAnnotation> annotationCollection)
Add a Collection of BugAnnotations.BugInstance
addCalledMethod(DismantleBytecode visitor)
Add a method annotation for the method which has been called by the method currently being visited by given visitor.BugInstance
addCalledMethod(java.lang.String className, java.lang.String methodName, java.lang.String methodSig, boolean isStatic)
Add a method annotation.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.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.BugInstance
addClass(ClassDescriptor classDescriptor)
Add a class annotation.BugInstance
addClass(PreorderVisitor visitor)
Add a class annotation for the class that the visitor is currently visiting.BugInstance
addClass(java.lang.String className)
Add a class annotation.BugInstance
addClass(java.lang.String className, java.lang.String sourceFileName)
Deprecated.use addClass(String) insteadBugInstance
addClass(org.apache.bcel.classfile.JavaClass jclass)
Add a class annotation.BugInstance
addClass(org.objectweb.asm.tree.ClassNode classNode)
Add a class annotation for the classNode.BugInstance
addClassAndMethod(XMethod xMethod)
BugInstance
addClassAndMethod(MethodDescriptor methodDescriptor)
BugInstance
addClassAndMethod(MethodAnnotation methodAnnotation)
Add class and method annotations for given method.BugInstance
addClassAndMethod(PreorderVisitor visitor)
Add a class annotation and a method annotation for the class and method which the given visitor is currently visiting.BugInstance
addClassAndMethod(org.apache.bcel.classfile.JavaClass javaClass, org.apache.bcel.classfile.Method method)
Add class and method annotations for given class and method.BugInstance
addClassAndMethod(org.apache.bcel.generic.MethodGen methodGen, java.lang.String sourceFile)
Add class and method annotations for given method.BugInstance
addEqualsMethodUsed(ClassDescriptor expectedClass)
BugInstance
addEqualsMethodUsed(java.util.Collection<XMethod> equalsMethods)
BugInstance
addField(FieldVariable field)
Add a field annotation for a FieldVariable matched in a ByteCodePattern.BugInstance
addField(XField xfield)
Add a field annotation for an XField.BugInstance
addField(FieldDescriptor fieldDescriptor)
Add a field annotation for a FieldDescriptor.BugInstance
addField(FieldAnnotation fieldAnnotation)
Add a field annotationBugInstance
addField(PreorderVisitor visitor)
BugInstance
addField(java.lang.String className, java.lang.String fieldName, java.lang.String fieldSig, boolean isStatic)
Add a field annotation.BugInstance
addField(java.lang.String className, java.lang.String fieldName, java.lang.String fieldSig, int accessFlags)
Add a field annotation.BugInstance
addFieldOrMethodValueSource(OpcodeStack.Item item)
BugInstance
addFoundAndExpectedType(java.lang.String foundType, java.lang.String expectedType)
BugInstance
addFoundAndExpectedType(org.apache.bcel.generic.Type foundType, org.apache.bcel.generic.Type expectedType)
BugInstance
addInt(int value)
Add an integer annotation.BugInstance
addMethod(JavaClassAndMethod classAndMethod)
Add a method annotation.BugInstance
addMethod(XMethod xmethod)
Add a MethodAnnotation from an XMethod.BugInstance
addMethod(MethodAnnotation methodAnnotation)
Add a method annotation.BugInstance
addMethod(PreorderVisitor visitor)
Add a method annotation for the method which the given visitor is currently visiting.BugInstance
addMethod(java.lang.String className, java.lang.String methodName, java.lang.String methodSig, boolean isStatic)
Add a method annotation.BugInstance
addMethod(java.lang.String className, java.lang.String methodName, java.lang.String methodSig, int accessFlags)
Add a method annotation.BugInstance
addMethod(org.apache.bcel.classfile.JavaClass javaClass, org.apache.bcel.classfile.Method method)
Add a method annotation.BugInstance
addMethod(org.apache.bcel.generic.MethodGen methodGen, java.lang.String sourceFile)
Add a method annotation.BugInstance
addOptionalAnnotation(BugAnnotation annotation)
BugInstance
addOptionalAnnotation(BugAnnotation annotation, java.lang.String role)
BugInstance
addOptionalField(XField xfield)
Add a field annotation for an XField.BugInstance
addOptionalLocalVariable(DismantleBytecode dbc, OpcodeStack.Item item)
Local variable addersBugInstance
addOptionalUniqueAnnotations(BugAnnotation... annotations)
BugInstance
addOptionalUniqueAnnotationsWithFallback(BugAnnotation fallback, BugAnnotation... annotations)
BugInstance
addParameterAnnotation(int index, java.lang.String role)
BugInstance
addReferencedField(FieldAnnotation fa)
Add a field annotation for the field referenced by the FieldAnnotation parameterBugInstance
addReferencedField(DismantleBytecode visitor)
Add a field annotation for the field which has just been accessed by the method currently being visited by given visitor.BugInstance
addSomeSourceForTopTwoStackValues(ClassContext classContext, org.apache.bcel.classfile.Method method, Location location)
BugInstance
addSourceForTopStackValue(ClassContext classContext, org.apache.bcel.classfile.Method method, Location location)
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.BugInstance
addSourceLine(ClassContext classContext, org.apache.bcel.classfile.Method method, Location location)
Add source line annotation for given Location in a method.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.BugInstance
addSourceLine(ClassContext classContext, org.apache.bcel.generic.MethodGen methodGen, java.lang.String sourceFile, org.apache.bcel.generic.InstructionHandle handle)
Add a source line annotation for the given instruction in the given method.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.BugInstance
addSourceLine(BytecodeScanningDetector visitor)
Add a source line annotation for instruction currently being visited by given visitor.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.BugInstance
addSourceLine(MethodDescriptor methodDescriptor, Location location)
Add source line annotation for given Location in a method.BugInstance
addSourceLine(SourceLineAnnotation sourceLine)
Add a source line annotation.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.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.BugInstance
addString(char c)
Add a String annotation.BugInstance
addString(java.lang.String value)
Add a String annotation.BugInstance
addSuperclass(PreorderVisitor visitor)
Add a class annotation for the superclass of the class the visitor is currently visiting.BugInstance
addType(ClassDescriptor c)
BugInstance
addType(java.lang.String typeDescriptor)
Add a type annotation.BugInstance
addType(org.apache.bcel.generic.Type type)
BugInstance
addTypeOfNamedClass(java.lang.String typeName)
BugInstance
addUnknownSourceLine(java.lang.String className, java.lang.String sourceFile)
Add a non-specific source line annotation.BugInstance
addValueSource(OpcodeStack.Item item, DismantleBytecode dbc)
BugInstance
addValueSource(OpcodeStack.Item item, org.apache.bcel.classfile.Method method, int pc)
BugInstance
addVisitedField(PreorderVisitor visitor)
Add a field annotation for the field which is being visited by given visitor.java.util.Iterator<BugAnnotation>
annotationIterator()
Get an Iterator over all bug annotations.boolean
annotationTextContainsWord(java.lang.String word)
Determine whether or not the annotation text contains the given word.java.lang.Object
clone()
int
compareTo(BugInstance other)
boolean
deleteProperty(java.lang.String name)
Delete property with given name.BugInstance
describe(java.lang.String description)
Add a description to the most recently added bug annotation.boolean
equals(java.lang.Object o)
java.lang.String
getAbbrev()
Get the abbreviation of this bug instance's BugPattern.java.lang.String
getAbridgedMessage()
java.util.List<? extends BugAnnotation>
getAnnotations()
Get an Iterator over all bug annotations.java.lang.String
getAnnotationText()
Get the user annotation text.BugPattern
getBugPattern()
Get the BugPattern.int
getBugRank()
java.lang.String
getCategoryAbbrev()
DetectorFactory
getDetectorFactory()
static BugAnnotation
getFieldOrMethodValueSource(OpcodeStack.Item item)
long
getFirstVersion()
java.lang.String
getInstanceHash()
java.lang.String
getInstanceKey()
int
getInstanceOccurrenceMax()
int
getInstanceOccurrenceNum()
long
getLastVersion()
java.lang.String
getMessage()
Format a string describing this bug instance.java.lang.String
getMessageWithoutPrefix()
Format a string describing this bug instance.java.lang.String
getMessageWithPriorityType()
Format a string describing this bug pattern, with the priority and type at the beginning.java.lang.String
getMessageWithPriorityTypeAbbreviation()
BugDesignation
getNonnullUserDesignation()
Deprecated.ClassAnnotation
getPrimaryClass()
Get the primary class annotation, which indicates where the bug occurs.FieldAnnotation
getPrimaryField()
Get the primary method annotation, which indicates where the bug occurs.LocalVariableAnnotation
getPrimaryLocalVariableAnnotation()
MethodAnnotation
getPrimaryMethod()
Get the primary method annotation, which indicates where the bug occurs.SourceLineAnnotation
getPrimarySourceLineAnnotation()
Get the primary source line annotation.int
getPriority()
Get the bug priority.java.lang.String
getPriorityAbbreviation()
java.lang.String
getPriorityString()
java.lang.String
getPriorityTypeAbbreviation()
java.lang.String
getPriorityTypeString()
Get a string describing the bug priority and type.java.lang.String
getProperty(java.lang.String name)
Get value of given property.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.static BugAnnotation
getSomeSource(ClassContext classContext, org.apache.bcel.classfile.Method method, Location location, OpcodeStack stack, int stackPos)
static BugAnnotation
getSourceForTopStackValue(ClassContext classContext, org.apache.bcel.classfile.Method method, Location location)
java.util.Set<java.lang.String>
getTextAnnotationWords()
Get set of words in the text annotation.java.lang.String
getType()
Get the bug type.BugDesignation
getUserDesignation()
Deprecated.java.lang.String
getUserDesignationKey()
Get the user designation key.int
getUserDesignationKeyIndex()
java.lang.String
getUserName()
long
getUserTimestamp()
static BugAnnotation
getValueSource(OpcodeStack.Item item, org.apache.bcel.classfile.Method method, int pc)
int
hashCode()
boolean
isDead()
boolean
isExperimental()
Is this bug instance the result of an experimental detector?boolean
isInstanceHashConsistent()
boolean
isIntroducedByChangeOfExistingClass()
boolean
isRemovedByChangeOfPersistingClass()
BugProperty
lookupProperty(java.lang.String name)
Look up a property by name.void
lowerPriority()
void
lowerPriorityALot()
BugInstance
lowerPriorityIfDeprecated()
java.util.Iterator<BugProperty>
propertyIterator()
Get an Iterator over the properties defined in this BugInstance.void
raisePriority()
static void
setAdjustExperimental(boolean adjust)
void
setAnnotationText(java.lang.String annotationText, BugCollection bugCollection)
Set the user annotation text.void
setFirstVersion(long firstVersion)
void
setInstanceHash(java.lang.String instanceHash)
void
setInstanceOccurrenceMax(int instanceOccurrenceMax)
void
setInstanceOccurrenceNum(int instanceOccurrenceNum)
void
setIntroducedByChangeOfExistingClass(boolean introducedByChangeOfExistingClass)
void
setLastVersion(long lastVersion)
void
setOldInstanceHash(java.lang.String oldInstanceHash)
void
setPriority(int p)
Set the bug priority.BugInstance
setProperty(java.lang.String name, java.lang.String value)
Set value of given property.void
setRemovedByChangeOfPersistingClass(boolean removedByChangeOfPersistingClass)
void
setUser(java.lang.String user)
void
setUserAnnotationTimestamp(long timestamp)
void
setUserDesignation(BugDesignation bd)
Deprecated.void
setUserDesignationKey(java.lang.String key, BugCollection bugCollection)
void
setUserDesignationKeyIndex(int index, BugCollection bugCollection)
sjava.lang.String
toString()
Convert to String.void
writeXML(XMLOutput xmlOutput)
Write this object to given XMLOutput.void
writeXML(XMLOutput xmlOutput, boolean addMessages, boolean isPrimary)
-
-
-
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
-
clone
public java.lang.Object clone()
- Overrides:
clone
in classjava.lang.Object
-
setAdjustExperimental
public static void setAdjustExperimental(boolean adjust)
-
getType
public java.lang.String getType()
Get the bug type.
-
getBugPattern
@NonNull public BugPattern getBugPattern()
Get the BugPattern.
-
getPriority
public int getPriority()
Get the bug priority.
-
getBugRank
public int getBugRank()
-
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.
-
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.
-
getPrimaryMethod
public MethodAnnotation getPrimaryMethod()
Get the primary method annotation, which indicates where the bug occurs.
-
getPrimaryField
public FieldAnnotation getPrimaryField()
Get the primary method annotation, which indicates where the bug occurs.
-
lowerPriorityIfDeprecated
public BugInstance lowerPriorityIfDeprecated()
-
getPrimaryLocalVariableAnnotation
public LocalVariableAnnotation getPrimaryLocalVariableAnnotation()
-
getPrimarySourceLineAnnotation
public 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
-
getInstanceKey
public java.lang.String getInstanceKey()
-
annotationIterator
public java.util.Iterator<BugAnnotation> annotationIterator()
Get an Iterator over all bug annotations.
-
getAnnotations
public java.util.List<? extends BugAnnotation> getAnnotations()
Get an Iterator over all bug annotations.
-
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.
-
setUserDesignation
@Deprecated public void setUserDesignation(BugDesignation bd)
Deprecated.set the user designation object. This will clobber any existing annotationText (or any other BugDesignation field).
-
getUserDesignation
@Deprecated @Nullable public BugDesignation getUserDesignation()
Deprecated.return the user designation object, which may be null. A previous calls to getSafeUserDesignation(), setAnnotationText(), or setUserDesignation() will ensure it will be non-null [barring an intervening setUserDesignation(null)].- See Also:
getNonnullUserDesignation()
-
getNonnullUserDesignation
@Deprecated @NonNull public BugDesignation getNonnullUserDesignation()
Deprecated.return the user designation object, creating one if necessary. So callinggetSafeUserDesignation().setDesignation("HARMLESS")
will always work without the possibility of a NullPointerException.- See Also:
getUserDesignation()
-
getUserDesignationKey
@NonNull public java.lang.String getUserDesignationKey()
Get the user designation key. E.g., "MOSTLY_HARMLESS", "CRITICAL", "NOT_A_BUG", etc. If the user designation object is null,returns UNCLASSIFIED. To set the user designation key, callgetSafeUserDesignation().setDesignation("HARMLESS")
.- Returns:
- the user designation key
- See Also:
I18N.getUserDesignation(String key)
-
getUserName
@CheckForNull public java.lang.String getUserName()
-
getUserTimestamp
public long getUserTimestamp()
-
getUserDesignationKeyIndex
@NonNull public int getUserDesignationKeyIndex()
-
setUserDesignationKey
public void setUserDesignationKey(java.lang.String key, @CheckForNull BugCollection bugCollection)
- Parameters:
key
-bugCollection
- TODO
-
setUserDesignationKeyIndex
public void setUserDesignationKeyIndex(int index, @CheckForNull BugCollection bugCollection)
s- Parameters:
index
-bugCollection
- TODO
-
setAnnotationText
public void setAnnotationText(java.lang.String annotationText, @CheckForNull BugCollection bugCollection)
Set the user annotation text.- Parameters:
annotationText
- the user annotation textbugCollection
- TODO
-
getAnnotationText
@NonNull public java.lang.String getAnnotationText()
Get the user annotation text.- Returns:
- the user annotation text
-
setUser
public void setUser(java.lang.String user)
-
setUserAnnotationTimestamp
public void setUserAnnotationTimestamp(long timestamp)
-
annotationTextContainsWord
public boolean annotationTextContainsWord(java.lang.String word)
Determine whether or not the annotation text contains the given word.- Parameters:
word
- the word- Returns:
- true if the annotation text contains the word, false otherwise
-
getTextAnnotationWords
public java.util.Set<java.lang.String> getTextAnnotationWords()
Get set of words in the text annotation.
-
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 propery 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 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
-
addAnnotations
public BugInstance addAnnotations(java.util.Collection<? extends BugAnnotation> annotationCollection)
Add a Collection of BugAnnotations.- Parameters:
annotationCollection
- Collection of BugAnnotations
-
addClassAndMethod
public BugInstance addClassAndMethod(MethodDescriptor methodDescriptor)
-
addClassAndMethod
public BugInstance addClassAndMethod(XMethod xMethod)
-
addClassAndMethod
public 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
-
addClassAndMethod
public BugInstance addClassAndMethod(MethodAnnotation methodAnnotation)
Add class and method annotations for given method.- Parameters:
methodAnnotation
- the method- Returns:
- this object
-
addClassAndMethod
public 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 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
@Deprecated public BugInstance addClass(java.lang.String className, java.lang.String sourceFileName)
Deprecated.use addClass(String) insteadAdd 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 BugInstance addClass(@DottedClassName 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 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 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 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 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 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 BugInstance addType(java.lang.String typeDescriptor)
Add a type annotation. Handy for referring to array types.For information on type descriptors,
see http://java.sun.com/docs/books/vmspec/2nd-edition/html/ClassFile.doc.html#14152
or http://www.murrayc.com/learning/java/java_classfileformat.shtml#TypeDescriptors- Parameters:
typeDescriptor
- a jvm type descriptor, such as "[I"- Returns:
- this object
-
addType
public BugInstance addType(org.apache.bcel.generic.Type type)
-
addFoundAndExpectedType
public BugInstance addFoundAndExpectedType(org.apache.bcel.generic.Type foundType, org.apache.bcel.generic.Type expectedType)
-
addFoundAndExpectedType
public BugInstance addFoundAndExpectedType(java.lang.String foundType, java.lang.String expectedType)
-
addEqualsMethodUsed
public BugInstance addEqualsMethodUsed(ClassDescriptor expectedClass)
-
addEqualsMethodUsed
public BugInstance addEqualsMethodUsed(@CheckForNull java.util.Collection<XMethod> equalsMethods)
-
addTypeOfNamedClass
public BugInstance addTypeOfNamedClass(java.lang.String typeName)
-
addType
public BugInstance addType(ClassDescriptor c)
-
addField
public BugInstance addField(java.lang.String className, java.lang.String fieldName, java.lang.String fieldSig, boolean isStatic)
Add a field annotation.- Parameters:
className
- name of the class containing the fieldfieldName
- the name of the fieldfieldSig
- type signature of the fieldisStatic
- whether or not the field is static- Returns:
- this object
-
addField
public BugInstance addField(java.lang.String className, java.lang.String fieldName, java.lang.String fieldSig, int accessFlags)
Add a field annotation.- Parameters:
className
- 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 BugInstance addField(PreorderVisitor visitor)
-
addField
public BugInstance addField(FieldAnnotation fieldAnnotation)
Add a field annotation- Parameters:
fieldAnnotation
- the field annotation- Returns:
- this object
-
addField
public BugInstance addField(FieldVariable field)
Add a field annotation for a FieldVariable matched in a ByteCodePattern.- Parameters:
field
- the FieldVariable- Returns:
- this object
-
addOptionalField
public BugInstance addOptionalField(@CheckForNull XField xfield)
Add a field annotation for an XField.- Parameters:
xfield
- the XField- Returns:
- this object
-
addField
public BugInstance addField(XField xfield)
Add a field annotation for an XField.- Parameters:
xfield
- the XField- Returns:
- this object
-
addField
public BugInstance addField(FieldDescriptor fieldDescriptor)
Add a field annotation for a FieldDescriptor.- Parameters:
fieldDescriptor
- the FieldDescriptor- Returns:
- this object
-
addReferencedField
public 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 BugInstance addReferencedField(FieldAnnotation fa)
Add a field annotation for the field referenced by the FieldAnnotation parameter
-
addVisitedField
public 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 BugInstance addOptionalLocalVariable(DismantleBytecode dbc, OpcodeStack.Item item)
Local variable adders
-
addMethod
public 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 BugInstance addMethod(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 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 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 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 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 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 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 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 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 BugInstance addMethod(XMethod xmethod)
Add a MethodAnnotation from an XMethod.- Parameters:
xmethod
- the XMethod- Returns:
- this object
-
addMethod
public 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 BugInstance addInt(int value)
Add an integer annotation.- Parameters:
value
- the integer value- Returns:
- this object
-
addParameterAnnotation
public BugInstance addParameterAnnotation(int index, java.lang.String role)
-
addString
public BugInstance addString(java.lang.String value)
Add a String annotation.- Parameters:
value
- the String value- Returns:
- this object
-
addString
public BugInstance addString(char c)
Add a String annotation.- Parameters:
c
- the char value- Returns:
- this object
-
addSourceLine
public BugInstance addSourceLine(SourceLineAnnotation sourceLine)
Add a source line annotation.- Parameters:
sourceLine
- the source line annotation- Returns:
- this object
-
addSourceLine
public 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 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 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 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 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 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 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 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 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 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 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 java.lang.String getMessageWithoutPrefix()
Format a string describing this bug instance.- Returns:
- the description
-
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 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:
toString
in classjava.lang.Object
-
writeXML
public void writeXML(XMLOutput xmlOutput) throws java.io.IOException
Description copied from interface:XMLWriteable
Write this object to given XMLOutput.- Specified by:
writeXML
in interfaceXMLWriteable
- Parameters:
xmlOutput
- the XMLOutput for the document- Throws:
java.io.IOException
-
writeXML
public void writeXML(XMLOutput xmlOutput, boolean addMessages, boolean isPrimary) throws java.io.IOException
- Specified by:
writeXML
in interfaceXMLWriteableWithMessages
- Throws:
java.io.IOException
-
addOptionalAnnotation
public BugInstance addOptionalAnnotation(@CheckForNull BugAnnotation annotation)
-
addOptionalAnnotation
public BugInstance addOptionalAnnotation(@CheckForNull BugAnnotation annotation, java.lang.String role)
-
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
@CheckForNull public static BugAnnotation getSourceForTopStackValue(ClassContext classContext, org.apache.bcel.classfile.Method method, Location location)
-
getSomeSource
@CheckForNull public static BugAnnotation getSomeSource(ClassContext classContext, org.apache.bcel.classfile.Method method, Location location, OpcodeStack stack, int stackPos)
-
getValueSource
public static BugAnnotation getValueSource(OpcodeStack.Item item, org.apache.bcel.classfile.Method method, int pc)
-
addValueSource
public BugInstance addValueSource(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)
- Parameters:
item
-
-
addOptionalUniqueAnnotations
public BugInstance addOptionalUniqueAnnotations(BugAnnotation... annotations)
-
addOptionalUniqueAnnotationsWithFallback
public BugInstance addOptionalUniqueAnnotationsWithFallback(BugAnnotation fallback, BugAnnotation... annotations)
-
getFieldOrMethodValueSource
@CheckForNull public static BugAnnotation getFieldOrMethodValueSource(@CheckForNull OpcodeStack.Item item)
-
hashCode
public int hashCode()
- Overrides:
hashCode
in classjava.lang.Object
-
equals
public boolean equals(java.lang.Object o)
- Overrides:
equals
in classjava.lang.Object
-
compareTo
public int compareTo(BugInstance other)
- Specified by:
compareTo
in interfacejava.lang.Comparable<BugInstance>
-
setFirstVersion
public void setFirstVersion(long firstVersion)
- Parameters:
firstVersion
- The firstVersion to set.
-
getFirstVersion
public long getFirstVersion()
- Returns:
- Returns the firstVersion.
-
setLastVersion
public void setLastVersion(long lastVersion)
- Parameters:
lastVersion
- The lastVersion to set.
-
getLastVersion
public long getLastVersion()
- Returns:
- Returns the lastVersion.
-
isDead
public boolean isDead()
-
setIntroducedByChangeOfExistingClass
public void setIntroducedByChangeOfExistingClass(boolean introducedByChangeOfExistingClass)
- Parameters:
introducedByChangeOfExistingClass
- The introducedByChangeOfExistingClass to set.
-
isIntroducedByChangeOfExistingClass
public boolean isIntroducedByChangeOfExistingClass()
- Returns:
- Returns the introducedByChangeOfExistingClass.
-
setRemovedByChangeOfPersistingClass
public void setRemovedByChangeOfPersistingClass(boolean removedByChangeOfPersistingClass)
- Parameters:
removedByChangeOfPersistingClass
- The removedByChangeOfPersistingClass to set.
-
isRemovedByChangeOfPersistingClass
public boolean isRemovedByChangeOfPersistingClass()
- Returns:
- Returns the removedByChangeOfPersistingClass.
-
setInstanceHash
public void setInstanceHash(java.lang.String instanceHash)
- Parameters:
instanceHash
- The instanceHash to set.
-
setOldInstanceHash
public void setOldInstanceHash(java.lang.String oldInstanceHash)
- Parameters:
oldInstanceHash
- The oldInstanceHash to set.
-
getInstanceHash
public java.lang.String getInstanceHash()
- Returns:
- Returns the instanceHash.
-
isInstanceHashConsistent
public boolean isInstanceHashConsistent()
-
setInstanceOccurrenceNum
public void setInstanceOccurrenceNum(int instanceOccurrenceNum)
- Parameters:
instanceOccurrenceNum
- The instanceOccurrenceNum to set.
-
getInstanceOccurrenceNum
public int getInstanceOccurrenceNum()
- Returns:
- Returns the instanceOccurrenceNum.
-
setInstanceOccurrenceMax
public void setInstanceOccurrenceMax(int instanceOccurrenceMax)
- Parameters:
instanceOccurrenceMax
- The instanceOccurrenceMax to set.
-
getInstanceOccurrenceMax
public int getInstanceOccurrenceMax()
- Returns:
- Returns the instanceOccurrenceMax.
-
getDetectorFactory
public DetectorFactory getDetectorFactory()
-
-