Class BugInstance
- All Implemented Interfaces:
XMLWriteable
,Cloneable
,Comparable<BugInstance>
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 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:
-
Nested Class Summary
-
Constructor Summary
ConstructorDescriptionBugInstance
(Detector2 detector, String type, int priority) Create a new BugInstance.BugInstance
(Detector detector, String type, int priority) Create a new BugInstance.BugInstance
(String type, int priority) Constructor. -
Method Summary
Modifier and TypeMethodDescriptionadd
(BugAnnotation annotation) addAnnotations
(Collection<? extends BugAnnotation> annotationCollection) Add a Collection of BugAnnotations.addCalledMethod
(DismantleBytecode visitor) Add a method annotation for the method which has been called by the method currently being visited by given visitor.addCalledMethod
(String className, String methodName, String methodSig, boolean isStatic) Add a method annotation.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.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.addClass
(ClassDescriptor classDescriptor) Add a class annotation.addClass
(PreorderVisitor visitor) Add a class annotation for the class that the visitor is currently visiting.Add a class annotation.Add a class annotation.addClass
(org.apache.bcel.classfile.JavaClass jclass) Add a class annotation.addClass
(org.objectweb.asm.tree.ClassNode classNode) Add a class annotation for the classNode.addClassAndMethod
(XMethod xMethod) addClassAndMethod
(MethodDescriptor methodDescriptor) addClassAndMethod
(MethodAnnotation methodAnnotation) Add class and method annotations for given method.addClassAndMethod
(PreorderVisitor visitor) Add a class annotation and a method annotation for the class and method which the given visitor is currently visiting.addClassAndMethod
(org.apache.bcel.classfile.JavaClass javaClass, org.apache.bcel.classfile.Method method) Add class and method annotations for given class and method.addClassAndMethod
(org.apache.bcel.generic.MethodGen methodGen, String sourceFile) Add class and method annotations for given method.addEqualsMethodUsed
(ClassDescriptor expectedClass) addEqualsMethodUsed
(Collection<XMethod> equalsMethods) addField
(FieldVariable field) Add a field annotation for a FieldVariable matched in a ByteCodePattern.Add a field annotation for an XField.addField
(FieldDescriptor fieldDescriptor) Add a field annotation for a FieldDescriptor.addField
(FieldAnnotation fieldAnnotation) Add a field annotationaddField
(PreorderVisitor visitor) Add a field annotation.Add a field annotation.addFoundAndExpectedType
(String foundType, String expectedType) addFoundAndExpectedType
(org.apache.bcel.generic.Type foundType, org.apache.bcel.generic.Type expectedType) addInt
(int value) Add an integer annotation.addMethod
(JavaClassAndMethod classAndMethod) Add a method annotation.Add a MethodAnnotation from an XMethod.addMethod
(MethodDescriptor method) Add a MethodAnnotation from an MethodDescriptor.addMethod
(MethodAnnotation methodAnnotation) Add a method annotation.addMethod
(PreorderVisitor visitor) Add a method annotation for the method which the given visitor is currently visiting.Add a method annotation.Add a method annotation.addMethod
(org.apache.bcel.classfile.JavaClass javaClass, org.apache.bcel.classfile.Method method) Add a method annotation.Add a method annotation.addOptionalAnnotation
(BugAnnotation annotation) addOptionalAnnotation
(BugAnnotation annotation, String role) addOptionalField
(XField xfield) Add a field annotation for an XField.Local variable addersaddOptionalUniqueAnnotations
(BugAnnotation... annotations) addOptionalUniqueAnnotationsWithFallback
(BugAnnotation fallback, BugAnnotation... annotations) addParameterAnnotation
(int index, String role) Add an annotation about a parameterAdd a field annotation for the field referenced by the FieldAnnotation parameteraddReferencedField
(DismantleBytecode visitor) Add a field annotation for the field which has just been accessed by the method currently being visited by given visitor.addSomeSourceForTopTwoStackValues
(ClassContext classContext, org.apache.bcel.classfile.Method method, Location location) addSourceForTopStackValue
(ClassContext classContext, org.apache.bcel.classfile.Method method, Location location) 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.addSourceLine
(ClassContext classContext, org.apache.bcel.classfile.Method method, Location location) Add source line annotation for given Location in a method.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.addSourceLine
(ClassContext classContext, org.apache.bcel.generic.MethodGen methodGen, String sourceFile, org.apache.bcel.generic.InstructionHandle handle) Add a source line annotation for the given instruction in the given method.addSourceLine
(ClassContext classContext, org.apache.bcel.generic.MethodGen methodGen, String sourceFile, org.apache.bcel.generic.InstructionHandle start, org.apache.bcel.generic.InstructionHandle end) Add a source line annotation describing a range of instructions.addSourceLine
(BytecodeScanningDetector visitor) Add a source line annotation for instruction currently being visited by given visitor.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.addSourceLine
(MethodDescriptor methodDescriptor, Location location) Add source line annotation for given Location in a method.addSourceLine
(SourceLineAnnotation sourceLine) Add a source line annotation.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.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.addString
(char c) Add a String annotation.Add a String annotation.addSuperclass
(PreorderVisitor visitor) Add a class annotation for the superclass of the class the visitor is currently visiting.Add a type annotation.addType
(org.apache.bcel.generic.Type type) addTypeOfNamedClass
(String typeName) addUnknownSourceLine
(String className, String sourceFile) Add a non-specific source line annotation.addValueSource
(OpcodeStack.Item item, DismantleBytecode dbc) addValueSource
(OpcodeStack.Item item, org.apache.bcel.classfile.Method method, int pc) addVisitedField
(PreorderVisitor visitor) Add a field annotation for the field which is being visited by given visitor.void
adjustForDetector
(String detectorName) Get an Iterator over all bug annotations.void
clone()
int
compareTo
(BugInstance other) boolean
deleteProperty
(String name) Delete property with given name.Add a description to the most recently added bug annotation.boolean
static DateFormat
Get the abbreviation of this bug instance's BugPattern.List<? extends BugAnnotation>
Get an Iterator over all bug annotations.getAnnotationsForMessage
(boolean showContext) <A extends BugAnnotation>
AgetAnnotationWithRole
(Class<A> c, String role) Get the first bug annotation with the specified class and role; return null if no such annotation exists;Collection<? extends SourceLineAnnotation>
Get the BugPattern.int
int
getCWEid()
static BugAnnotation
long
int
int
long
Format a string describing this bug instance.Format a string describing this bug instance.Format a string describing this bug pattern, with the priority and type at the beginning.Get the primary class annotation, which indicates where the bug occurs.Get the primary field annotation, which indicates where the bug occurs.Get the primary method annotation, which indicates where the bug occurs.Get the primary source line annotation.Get the primary type annotation, which indicates where the bug occurs.int
Get the bug priority.Get a string describing the bug priority and type.getProperty
(String name) Get value of given property.getProperty
(String name, 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
getSourceForStackValue
(ClassContext classContext, org.apache.bcel.classfile.Method method, Location location, int depth) static BugAnnotation
getSourceForTopStackValue
(ClassContext classContext, org.apache.bcel.classfile.Method method, Location location) getType()
Get the bug pattern name (e.g., IL_INFINITE_RECURSIVE_LOOP)static BugAnnotation
getValueSource
(OpcodeStack.Item item, org.apache.bcel.classfile.Method method, int pc) int
hashCode()
boolean
isDead()
boolean
Is this bug instance the result of an experimental detector?boolean
boolean
boolean
lookupProperty
(String name) Look up a property by name.void
void
Get an Iterator over the properties defined in this BugInstance.void
static void
setAdjustExperimental
(boolean adjust) void
setFirstVersion
(long firstVersion) void
setHistory
(BugInstance from) void
setInstanceHash
(String instanceHash) void
setInstanceOccurrenceMax
(int instanceOccurrenceMax) void
setInstanceOccurrenceNum
(int instanceOccurrenceNum) void
setIntroducedByChangeOfExistingClass
(boolean introducedByChangeOfExistingClass) void
setLastVersion
(long lastVersion) void
setLive()
Mark the bug instance is being alive (still present in the last version)void
setOldInstanceHash
(String oldInstanceHash) void
setPriority
(int p) Set the bug priority.setProperty
(String name, String value) Set value of given property.void
setRemovedByChangeOfPersistingClass
(boolean removedByChangeOfPersistingClass) toString()
Convert to String.boolean
tryAddingOptionalUniqueAnnotations
(BugAnnotation... annotations) void
Write this object to given XMLOutput.void
writeXML
(XMLOutput xmlOutput, BugCollection bugCollection, boolean addMessages)
-
Constructor Details
-
BugInstance
Constructor.- Parameters:
type
- the bug typepriority
- the bug priority
-
BugInstance
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
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 Details
-
firstSeenXMLFormat
-
clone
-
adjustForDetector
- Parameters:
detectorName
-
-
setAdjustExperimental
public static void setAdjustExperimental(boolean adjust) -
getType
Get the bug pattern name (e.g., IL_INFINITE_RECURSIVE_LOOP) -
getBugPattern
Get the BugPattern. -
getPriority
public int getPriority()Get the bug priority. -
getBugRank
public int getBugRank() -
getBugRankCategory
-
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
-
getCategoryAbbrev
-
getPriorityString
-
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
Get the primary class annotation, which indicates where the bug occurs. -
getPrimaryType
Get the primary type annotation, which indicates where the bug occurs. -
getPrimaryMethod
Get the primary method annotation, which indicates where the bug occurs. -
getPrimaryField
Get the primary field annotation, which indicates where the bug occurs. -
lowerPriorityIfDeprecated
-
getPrimaryLocalVariableAnnotation
-
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
-
getInstanceKey
-
annotationIterator
Get an Iterator over all bug annotations. -
getAnnotations
Get an Iterator over all bug annotations. -
getAnnotationWithRole
Get the first bug annotation with the specified class and role; return null if no such annotation exists; -
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
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
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
Get an Iterator over the properties defined in this BugInstance.- Returns:
- Iterator over properties
-
setProperty
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
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
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
@Nonnull public BugInstance addAnnotations(Collection<? extends BugAnnotation> annotationCollection) Add a Collection of BugAnnotations.- Parameters:
annotationCollection
- Collection of BugAnnotations
-
addClassAndMethod
-
addClassAndMethod
-
addClassAndMethod
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
Add class and method annotations for given method.- Parameters:
methodAnnotation
- the method- Returns:
- this object
-
addClassAndMethod
@Nonnull public BugInstance addClassAndMethod(org.apache.bcel.generic.MethodGen methodGen, 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
@Nonnull 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
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
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
Add a class annotation for the classNode.- Parameters:
classNode
- the ASM visitor- Returns:
- this object
-
addClass
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
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
Add a class annotation for the class that the visitor is currently visiting.- Parameters:
visitor
- the BetterVisitor- Returns:
- this object
-
addSuperclass
Add a class annotation for the superclass of the class the visitor is currently visiting.- Parameters:
visitor
- the BetterVisitor- Returns:
- this object
-
addType
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
-
addFoundAndExpectedType
@Nonnull public BugInstance addFoundAndExpectedType(org.apache.bcel.generic.Type foundType, org.apache.bcel.generic.Type expectedType) -
addFoundAndExpectedType
-
addEqualsMethodUsed
-
addEqualsMethodUsed
-
addTypeOfNamedClass
-
addType
-
addField
@Nonnull public BugInstance addField(String className, String fieldName, 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
@Nonnull public BugInstance addField(String className, String fieldName, 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
-
addField
Add a field annotation- Parameters:
fieldAnnotation
- the field annotation- Returns:
- this object
-
addField
Add a field annotation for a FieldVariable matched in a ByteCodePattern.- Parameters:
field
- the FieldVariable- Returns:
- this object
-
addOptionalField
Add a field annotation for an XField.- Parameters:
xfield
- the XField- Returns:
- this object
-
addField
Add a field annotation for an XField.- Parameters:
xfield
- the XField- Returns:
- this object
-
addField
Add a field annotation for a FieldDescriptor.- Parameters:
fieldDescriptor
- the FieldDescriptor- Returns:
- this object
-
addReferencedField
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
Add a field annotation for the field referenced by the FieldAnnotation parameter -
addVisitedField
Add a field annotation for the field which is being visited by given visitor.- Parameters:
visitor
- the visitor- Returns:
- this object
-
addOptionalLocalVariable
Local variable adders -
addMethod
@Nonnull public BugInstance addMethod(String className, String methodName, 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
@Nonnull public BugInstance addMethod(@SlashedClassName String className, String methodName, 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
@Nonnull public BugInstance addMethod(org.apache.bcel.generic.MethodGen methodGen, 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
@Nonnull 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
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
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
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
-
addCalledMethod
@Nonnull public BugInstance addCalledMethod(String className, String methodName, 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
@Nonnull 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
@Nonnull 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
Add a MethodAnnotation from an XMethod.- Parameters:
xmethod
- the XMethod- Returns:
- this object
-
addMethod
Add a MethodAnnotation from an MethodDescriptor.- Parameters:
method
- the method- Returns:
- this object
-
addMethod
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
Add an integer annotation.- Parameters:
value
- the integer value- Returns:
- this object
-
addParameterAnnotation
Add an annotation about a parameter- Parameters:
index
- parameter index, starting from 0role
- the role used to describe the parameter
-
addString
Add a String annotation.- Parameters:
value
- the String value- Returns:
- this object
-
addString
Add a String annotation.- Parameters:
c
- the char value- Returns:
- this object
-
addSourceLine
Add a source line annotation.- Parameters:
sourceLine
- the source line annotation- Returns:
- this object
-
addSourceLine
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
@Nonnull 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
@Nonnull public BugInstance addSourceLine(ClassContext classContext, org.apache.bcel.generic.MethodGen methodGen, 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
@Nonnull public BugInstance addSourceLine(ClassContext classContext, org.apache.bcel.generic.MethodGen methodGen, 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
@Nonnull 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
Add source line annotation for given Location in a method.- Parameters:
methodDescriptor
- the methodlocation
- the Location in the method- Returns:
- this BugInstance
-
addSourceLine
@Nonnull 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
@Nonnull 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
@Nonnull 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
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
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
Format a string describing this bug instance.- Returns:
- the description
-
getAbridgedMessage
-
getMessage
Format a string describing this bug instance.- Returns:
- the description
-
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
-
describe
Add a description to the most recently added bug annotation.- Parameters:
description
- the description to add- Returns:
- this object
-
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. -
writeXML
Description copied from interface:XMLWriteable
Write this object to given XMLOutput.- Specified by:
writeXML
in interfaceXMLWriteable
- Parameters:
xmlOutput
- the XMLOutput for the document- Throws:
IOException
-
getCWEid
public int getCWEid() -
writeXML
public void writeXML(XMLOutput xmlOutput, BugCollection bugCollection, boolean addMessages) throws IOException - Throws:
IOException
-
addOptionalAnnotation
-
addOptionalAnnotation
-
add
-
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) -
getSourceForStackValue
@CheckForNull public static BugAnnotation getSourceForStackValue(ClassContext classContext, org.apache.bcel.classfile.Method method, Location location, int depth) -
getSomeSource
@CheckForNull public static BugAnnotation getSomeSource(ClassContext classContext, org.apache.bcel.classfile.Method method, Location location, OpcodeStack stack, int stackPos) -
getValueSource
@CheckForNull public static BugAnnotation getValueSource(OpcodeStack.Item item, org.apache.bcel.classfile.Method method, int pc) -
addValueSource
-
addValueSource
public BugInstance addValueSource(OpcodeStack.Item item, org.apache.bcel.classfile.Method method, int pc) -
addFieldOrMethodValueSource
-
addOptionalUniqueAnnotations
-
tryAddingOptionalUniqueAnnotations
-
addOptionalUniqueAnnotationsWithFallback
public BugInstance addOptionalUniqueAnnotationsWithFallback(BugAnnotation fallback, BugAnnotation... annotations) -
getFieldOrMethodValueSource
@CheckForNull public static BugAnnotation getFieldOrMethodValueSource(@CheckForNull OpcodeStack.Item item) -
hashCode
public int hashCode() -
equals
-
compareTo
- Specified by:
compareTo
in interfaceComparable<BugInstance>
-
setFirstVersion
public void setFirstVersion(long firstVersion) -
clearHistory
public void clearHistory() -
getFirstVersion
public long getFirstVersion() -
setHistory
-
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
-
setOldInstanceHash
-
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
-
getAnnotationsForMessage
-