Package edu.umd.cs.findbugs.detect
Class FindRefComparison
java.lang.Object
edu.umd.cs.findbugs.detect.FindRefComparison
- All Implemented Interfaces:
ExtendedTypes,Detector,Priorities
Find suspicious reference comparisons. This includes:
- Strings and other java.lang objects compared by reference equality
- Calls to equals(Object) where the argument is a different type than the receiver object
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classType representing a dynamically created String.static classstatic classstatic classType representing a String passed as a parameter.private static classprivate static classType merger to use the extended String types.private static final classstatic classType representing a static String.private static interfaceprivate static classA BugInstance and its WarningPropertySet. -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate static final intprivate final BugAccumulatorprivate final BugReporterprivate ClassContextprivate static final booleanClasses that are suspicious if compared by reference.private static final org.apache.bcel.generic.Typeprivate static final org.apache.bcel.generic.Typeprivate static final BitSetSet of opcodes that invoke instance methods on an object.private static final org.apache.bcel.generic.Typeprivate static final BitSetSet of bytecodes using for prescreening.private static final booleanprivate static final org.apache.bcel.generic.Typeprivate static final Stringprivate static final byteprivate static final byteprivate static final byteprivate final booleanFields inherited from interface edu.umd.cs.findbugs.ba.type.ExtendedTypes
T_AVAIL_TYPE, T_BOTTOM, T_DOUBLE_EXTRA, T_EXCEPTION, T_LONG_EXTRA, T_NULL, T_TOPFields inherited from interface edu.umd.cs.findbugs.Priorities
EXP_PRIORITY, HIGH_PRIORITY, IGNORE_PRIORITY, LOW_PRIORITY, NORMAL_PRIORITY -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescription(package private) voidaddEqualsCheck(String type, int pc) private voidanalyzeMethod(ClassContext classContext, org.apache.bcel.classfile.Method method) private voidcheckEqualsComparison(Location location, org.apache.bcel.classfile.JavaClass jclass, org.apache.bcel.classfile.Method method, org.apache.bcel.generic.MethodGen methodGen, org.apache.bcel.generic.ConstantPoolGen cpg, TypeDataflow typeDataflow) private booleancheckForWeirdEquals(String lhsSig, String rhsSig, Set<XMethod> targets) private voidcheckRefComparison(Location location, org.apache.bcel.classfile.JavaClass jclass, org.apache.bcel.classfile.Method method, org.apache.bcel.generic.MethodGen methodGen, FindRefComparison.RefComparisonTypeFrameModelingVisitor visitor, TypeDataflow typeDataflow, List<FindRefComparison.WarningWithProperties> stringComparisonList, List<FindRefComparison.WarningWithProperties> refComparisonList) private voiddecorateWarnings(LinkedList<FindRefComparison.WarningWithProperties> stringComparisonList, FindRefComparison.WarningDecorator warningDecorator) getInvokedMethod(org.apache.bcel.generic.ConstantPoolGen cpg, org.apache.bcel.generic.InvokeInstruction inv) getMethodCalledAnnotation(org.apache.bcel.generic.ConstantPoolGen cpg, org.apache.bcel.generic.InvokeInstruction inv) private voidhandleStringComparison(org.apache.bcel.classfile.JavaClass jclass, org.apache.bcel.classfile.Method method, org.apache.bcel.generic.MethodGen methodGen, FindRefComparison.RefComparisonTypeFrameModelingVisitor visitor, List<FindRefComparison.WarningWithProperties> stringComparisonList, Location location, org.apache.bcel.generic.Type lhsType, org.apache.bcel.generic.Type rhsType) private voidhandleSuspiciousRefComparison(org.apache.bcel.classfile.JavaClass jclass, org.apache.bcel.classfile.Method method, org.apache.bcel.generic.MethodGen methodGen, List<FindRefComparison.WarningWithProperties> refComparisonList, Location location, String lhs, org.apache.bcel.generic.ReferenceType lhsType, org.apache.bcel.generic.ReferenceType rhsType) private voidinspectLocation(org.apache.bcel.classfile.JavaClass jclass, org.apache.bcel.generic.ConstantPoolGen cpg, org.apache.bcel.classfile.Method method, org.apache.bcel.generic.MethodGen methodGen, LinkedList<FindRefComparison.WarningWithProperties> refComparisonList, LinkedList<FindRefComparison.WarningWithProperties> stringComparisonList, FindRefComparison.RefComparisonTypeFrameModelingVisitor visitor, TypeDataflow typeDataflow, Location location) (package private) booleanvoidreport()This method is called after all classes to be visited.private voidreportBest(ClassContext classContext, org.apache.bcel.classfile.Method method, LinkedList<FindRefComparison.WarningWithProperties> warningList, boolean relaxed) voidvisitClassContext(ClassContext classContext) Visit the ClassContext for a class which should be analyzed for instances of bug patterns.
-
Field Details
-
DEBUG
private static final boolean DEBUG -
REPORT_ALL_REF_COMPARISONS
private static final boolean REPORT_ALL_REF_COMPARISONS- See Also:
-
BASE_ES_PRIORITY
private static final int BASE_ES_PRIORITY -
DEFAULT_SUSPICIOUS_SET
Classes that are suspicious if compared by reference. -
invokeInstanceSet
Set of opcodes that invoke instance methods on an object. -
prescreenSet
Set of bytecodes using for prescreening. -
T_DYNAMIC_STRING
private static final byte T_DYNAMIC_STRING- See Also:
-
T_STATIC_STRING
private static final byte T_STATIC_STRING- See Also:
-
T_PARAMETER_STRING
private static final byte T_PARAMETER_STRING- See Also:
-
STRING_SIGNATURE
- See Also:
-
dynamicStringTypeInstance
private static final org.apache.bcel.generic.Type dynamicStringTypeInstance -
staticStringTypeInstance
private static final org.apache.bcel.generic.Type staticStringTypeInstance -
emptyStringTypeInstance
private static final org.apache.bcel.generic.Type emptyStringTypeInstance -
parameterStringTypeInstance
private static final org.apache.bcel.generic.Type parameterStringTypeInstance -
bugReporter
-
bugAccumulator
-
classContext
-
suspiciousSet
-
testingEnabled
private final boolean testingEnabled -
comparedForEqualityInThisMethod
-
-
Constructor Details
-
FindRefComparison
-
-
Method Details
-
visitClassContext
Description copied from interface:DetectorVisit the ClassContext for a class which should be analyzed for instances of bug patterns.- Specified by:
visitClassContextin interfaceDetector- Parameters:
classContext- the ClassContext
-
analyzeMethod
private void analyzeMethod(ClassContext classContext, org.apache.bcel.classfile.Method method) throws CFGBuilderException, DataflowAnalysisException -
mightBeLaterCheckedUsingEquals
-
inspectLocation
private void inspectLocation(org.apache.bcel.classfile.JavaClass jclass, org.apache.bcel.generic.ConstantPoolGen cpg, org.apache.bcel.classfile.Method method, org.apache.bcel.generic.MethodGen methodGen, LinkedList<FindRefComparison.WarningWithProperties> refComparisonList, LinkedList<FindRefComparison.WarningWithProperties> stringComparisonList, FindRefComparison.RefComparisonTypeFrameModelingVisitor visitor, TypeDataflow typeDataflow, Location location) throws DataflowAnalysisException - Throws:
DataflowAnalysisException
-
decorateWarnings
private void decorateWarnings(LinkedList<FindRefComparison.WarningWithProperties> stringComparisonList, FindRefComparison.WarningDecorator warningDecorator) -
reportBest
private void reportBest(ClassContext classContext, org.apache.bcel.classfile.Method method, LinkedList<FindRefComparison.WarningWithProperties> warningList, boolean relaxed) -
checkRefComparison
private void checkRefComparison(Location location, org.apache.bcel.classfile.JavaClass jclass, org.apache.bcel.classfile.Method method, org.apache.bcel.generic.MethodGen methodGen, FindRefComparison.RefComparisonTypeFrameModelingVisitor visitor, TypeDataflow typeDataflow, List<FindRefComparison.WarningWithProperties> stringComparisonList, List<FindRefComparison.WarningWithProperties> refComparisonList) throws DataflowAnalysisException - Throws:
DataflowAnalysisException
-
handleStringComparison
private void handleStringComparison(org.apache.bcel.classfile.JavaClass jclass, org.apache.bcel.classfile.Method method, org.apache.bcel.generic.MethodGen methodGen, FindRefComparison.RefComparisonTypeFrameModelingVisitor visitor, List<FindRefComparison.WarningWithProperties> stringComparisonList, Location location, org.apache.bcel.generic.Type lhsType, org.apache.bcel.generic.Type rhsType) -
handleSuspiciousRefComparison
private void handleSuspiciousRefComparison(org.apache.bcel.classfile.JavaClass jclass, org.apache.bcel.classfile.Method method, org.apache.bcel.generic.MethodGen methodGen, List<FindRefComparison.WarningWithProperties> refComparisonList, Location location, String lhs, org.apache.bcel.generic.ReferenceType lhsType, org.apache.bcel.generic.ReferenceType rhsType) -
addEqualsCheck
-
checkEqualsComparison
private void checkEqualsComparison(Location location, org.apache.bcel.classfile.JavaClass jclass, org.apache.bcel.classfile.Method method, org.apache.bcel.generic.MethodGen methodGen, org.apache.bcel.generic.ConstantPoolGen cpg, TypeDataflow typeDataflow) throws DataflowAnalysisException - Throws:
DataflowAnalysisException
-
getMethodCalledAnnotation
@CheckForNull public MethodAnnotation getMethodCalledAnnotation(org.apache.bcel.generic.ConstantPoolGen cpg, org.apache.bcel.generic.InvokeInstruction inv) -
getInvokedMethod
public MethodDescriptor getInvokedMethod(org.apache.bcel.generic.ConstantPoolGen cpg, org.apache.bcel.generic.InvokeInstruction inv) -
checkForWeirdEquals
-
report
public void report()Description copied from interface:DetectorThis method is called after all classes to be visited. It should be used by any detectors which accumulate information over all visited classes to generate results.
-