Package edu.umd.cs.findbugs.detect
Class ResourceInMultipleThreadsDetector
- java.lang.Object
-
- edu.umd.cs.findbugs.visitclass.BetterVisitor
-
- edu.umd.cs.findbugs.visitclass.PreorderVisitor
-
- edu.umd.cs.findbugs.visitclass.AnnotationVisitor
-
- edu.umd.cs.findbugs.visitclass.DismantleBytecode
-
- edu.umd.cs.findbugs.BytecodeScanningDetector
-
- edu.umd.cs.findbugs.bcel.OpcodeStackDetector
-
- edu.umd.cs.findbugs.detect.ResourceInMultipleThreadsDetector
-
- All Implemented Interfaces:
Detector,Priorities,org.apache.bcel.classfile.Visitor
public class ResourceInMultipleThreadsDetector extends OpcodeStackDetector
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description private static classResourceInMultipleThreadsDetector.FieldData-
Nested classes/interfaces inherited from class edu.umd.cs.findbugs.bcel.OpcodeStackDetector
OpcodeStackDetector.WithCustomJumpInfo
-
-
Field Summary
Fields Modifier and Type Field Description private BugReporterbugReporterprivate java.util.Map<XMethod,java.util.Set<XMethod>>calledMethodsByMethodsprivate java.util.Map<XField,ResourceInMultipleThreadsDetector.FieldData>fieldsUsedInThreadsprivate booleanfirstPassprivate java.util.Set<XMethod>methodsUsedInThreadsprivate booleansynchronizedBlockprivate java.util.Set<XField>synchronizedCollectionTypedFields-
Fields inherited from class edu.umd.cs.findbugs.bcel.OpcodeStackDetector
stack
-
Fields inherited from class edu.umd.cs.findbugs.visitclass.DismantleBytecode
codeBytes, lineNumberTable, M_BR, M_CP, M_INT, M_PAD, M_R, M_UINT
-
Fields inherited from interface edu.umd.cs.findbugs.Priorities
EXP_PRIORITY, HIGH_PRIORITY, IGNORE_PRIORITY, LOW_PRIORITY, NORMAL_PRIORITY
-
-
Constructor Summary
Constructors Constructor Description ResourceInMultipleThreadsDetector(BugReporter bugReporter)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description private voidaddToMethodsUsedInThreads(XMethod methodToAdd)private voidcollectFieldsUsedInThreads(int seen)private voidcollectMethodsUsedInThreads(int seen)private voidcreateOrUpdateFieldData(XField xField, boolean putfield, org.apache.bcel.classfile.Method containerMethod, XMethod xMethod)private java.util.Optional<org.apache.bcel.classfile.Method>getMethodFromBootstrap(org.apache.bcel.classfile.JavaClass javaClass, org.apache.bcel.classfile.ConstantInvokeDynamic constDyn)private booleanisAtomicTypedField(XField xField)private static booleanisBug(ResourceInMultipleThreadsDetector.FieldData data)A bug is reported if the field is modified in multiple methods, it is not only accessed in synchronized blocks, and it is not a synchronized collection or an atomic typed field.private booleanisJavaRuntimeMethod()Ignore a special case where a Thread is passed to thejava.lang.Runtimeclass, so it is used as a shutdown hook.private voidresetState()voidsawOpcode(int seen)By default, this method will not be called when stack is TOP.voidvisit(org.apache.bcel.classfile.JavaClass obj)voidvisit(org.apache.bcel.classfile.Method method)voidvisitAfter(org.apache.bcel.classfile.JavaClass javaClass)-
Methods inherited from class edu.umd.cs.findbugs.bcel.OpcodeStackDetector
afterOpcode, beforeOpcode, getStack, isUsingCustomUserValue, visitCode
-
Methods inherited from class edu.umd.cs.findbugs.BytecodeScanningDetector
getClassContext, report, shouldVisitCode, visitClassContext
-
Methods inherited from class edu.umd.cs.findbugs.visitclass.DismantleBytecode
areOppositeBranches, atCatchBlock, getBranchFallThrough, getBranchOffset, getBranchTarget, getClassConstantOperand, getClassDescriptorOperand, getCodeByte, getConstantRefOperand, getDefaultSwitchOffset, getDottedClassConstantOperand, getFieldDescriptorOperand, getIntConstant, getLongConstant, getMaxPC, getMethodDescriptorOperand, getNameConstantOperand, getNextCodeByte, getNextOpcode, getNextPC, getOpcode, getPC, getPrevOpcode, getRefConstantOperand, getRefFieldIsStatic, getRegisterOperand, getSigConstantOperand, getStringConstantOperand, getSwitchLabels, getSwitchOffsets, getXClassOperand, getXFieldOperand, getXMethodOperand, isBranch, isMethodCall, isRegisterLoad, isRegisterStore, isRegisterStore, isReturn, isShift, isSwitch, isWideOpcode, printOpCode, sawBranchTo, sawClass, sawDouble, sawField, sawFloat, sawIMethod, sawInt, sawLong, sawMethod, sawRegister, sawString, visit
-
Methods inherited from class edu.umd.cs.findbugs.visitclass.AnnotationVisitor
getAnnotationParameterAsEnum, getAnnotationParameterAsString, getAnnotationParameterAsStringArray, visitAnnotation, visitAnnotation, visitParameterAnnotation, visitParameterAnnotation, visitSyntheticParameterAnnotation
-
Methods inherited from class edu.umd.cs.findbugs.visitclass.PreorderVisitor
amVisitingMainMethod, asUnsignedByte, doVisitMethod, getClassDescriptor, getClassName, getCode, getConstantPool, getDottedClassName, getDottedFieldSig, getDottedMethodSig, getDottedSuperclassName, getField, getFieldDescriptor, getFieldIsStatic, getFieldName, getFieldSig, getFullyQualifiedFieldName, getFullyQualifiedMethodName, getMethod, getMethodDescriptor, getMethodName, getMethodSig, getMethodVisitOrder, getNumberArguments, getNumberMethodArguments, getPackageName, getSizeOfSurroundingTryBlock, getSizeOfSurroundingTryBlock, getSourceFile, getStringFromIndex, getSuperclassName, getSurroundingCaughtExceptions, getSurroundingCaughtExceptions, getSurroundingCaughtExceptionTypes, getSurroundingTryBlock, getSurroundingTryBlock, getThisClass, getXClass, getXField, getXMethod, hasInterestingClass, hasInterestingMethod, isVisitMethodsInCallOrder, setupVisitorForClass, setVisitMethodsInCallOrder, shouldVisit, toString, visitAfter, visitAnnotationDefault, visitAnnotationEntry, visitBootstrapMethods, visitConstantInvokeDynamic, visitConstantMethodHandle, visitConstantMethodType, visitConstantModule, visitConstantPackage, visitConstantPool, visitEnclosingMethod, visitingField, visitingMethod, visitInnerClasses, visitJavaClass, visitLineNumberTable, visitLocalVariableTable, visitMethodParameters, visitParameterAnnotationEntry, visitStackMap, visitStackMapEntry
-
Methods inherited from class edu.umd.cs.findbugs.visitclass.BetterVisitor
clone, report, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visitCodeException, visitConstantClass, visitConstantDouble, visitConstantFieldref, visitConstantFloat, visitConstantInteger, visitConstantInterfaceMethodref, visitConstantLong, visitConstantMethodref, visitConstantNameAndType, visitConstantString, visitConstantUtf8, visitConstantValue, visitDeprecated, visitExceptionTable, visitField, visitInnerClass, visitLineNumber, visitLocalVariable, visitLocalVariableTypeTable, visitMethod, visitSignature, visitSourceFile, visitSynthetic, visitUnknown
-
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface org.apache.bcel.classfile.Visitor
visitConstantDynamic, visitMethodParameter, visitModule, visitModuleExports, visitModuleMainClass, visitModuleOpens, visitModulePackages, visitModuleProvides, visitModuleRequires, visitNestHost, visitNestMembers, visitRecord, visitRecordComponent, visitStackMapType
-
-
-
-
Field Detail
-
bugReporter
private final BugReporter bugReporter
-
synchronizedCollectionTypedFields
private final java.util.Set<XField> synchronizedCollectionTypedFields
-
calledMethodsByMethods
private final java.util.Map<XMethod,java.util.Set<XMethod>> calledMethodsByMethods
-
methodsUsedInThreads
private final java.util.Set<XMethod> methodsUsedInThreads
-
fieldsUsedInThreads
private final java.util.Map<XField,ResourceInMultipleThreadsDetector.FieldData> fieldsUsedInThreads
-
synchronizedBlock
private boolean synchronizedBlock
-
firstPass
private boolean firstPass
-
-
Constructor Detail
-
ResourceInMultipleThreadsDetector
public ResourceInMultipleThreadsDetector(BugReporter bugReporter)
-
-
Method Detail
-
visit
public void visit(org.apache.bcel.classfile.JavaClass obj)
- Overrides:
visitin classBetterVisitor
-
visit
public void visit(org.apache.bcel.classfile.Method method)
- Overrides:
visitin classBetterVisitor
-
sawOpcode
public void sawOpcode(int seen)
Description copied from class:OpcodeStackDetectorBy default, this method will not be called when stack is TOP. To change this behavior, override
#beforeOpcode(int)and change to return true even if stack is TOP.see Using FindBugs for Research to learn lattice and what TOP means.
- Specified by:
sawOpcodein classOpcodeStackDetector- See Also:
OpcodeStackDetector.beforeOpcode(int)
-
collectMethodsUsedInThreads
private void collectMethodsUsedInThreads(int seen)
-
addToMethodsUsedInThreads
private void addToMethodsUsedInThreads(XMethod methodToAdd)
-
isJavaRuntimeMethod
private boolean isJavaRuntimeMethod()
Ignore a special case where a Thread is passed to thejava.lang.Runtimeclass, so it is used as a shutdown hook.- Returns:
trueif the Thread is passed to thejava.lang.Runtimeclass,falseotherwise
-
getMethodFromBootstrap
private java.util.Optional<org.apache.bcel.classfile.Method> getMethodFromBootstrap(org.apache.bcel.classfile.JavaClass javaClass, org.apache.bcel.classfile.ConstantInvokeDynamic constDyn)
-
collectFieldsUsedInThreads
private void collectFieldsUsedInThreads(int seen) throws CheckedAnalysisException- Throws:
CheckedAnalysisException
-
isAtomicTypedField
private boolean isAtomicTypedField(XField xField)
-
createOrUpdateFieldData
private void createOrUpdateFieldData(XField xField, boolean putfield, org.apache.bcel.classfile.Method containerMethod, XMethod xMethod)
-
visitAfter
public void visitAfter(org.apache.bcel.classfile.JavaClass javaClass)
- Overrides:
visitAfterin classPreorderVisitor
-
isBug
private static boolean isBug(ResourceInMultipleThreadsDetector.FieldData data)
A bug is reported if the field is modified in multiple methods, it is not only accessed in synchronized blocks, and it is not a synchronized collection or an atomic typed field.- Parameters:
data- the field data- Returns:
trueif the field is a bug,falseotherwise
-
resetState
private void resetState()
-
-