Package com.mebigfatguy.fbcontrib.detect
Class WriteOnlyCollection
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
com.mebigfatguy.fbcontrib.detect.MissingMethodsDetector
com.mebigfatguy.fbcontrib.detect.WriteOnlyCollection
- All Implemented Interfaces:
edu.umd.cs.findbugs.Detector,edu.umd.cs.findbugs.Priorities,org.apache.bcel.classfile.Visitor
Looks for allocations and initializations of java collections, but that are
never read from or accessed to gain information. This represents a collection
of no use, and most probably can be removed. It is similar to a dead local
store.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate intFields inherited from class edu.umd.cs.findbugs.visitclass.DismantleBytecode
codeBytes, lineNumberTable, M_BR, M_CP, M_INT, M_PAD, M_R, M_UINTFields inherited from interface edu.umd.cs.findbugs.Priorities
EXP_PRIORITY, HIGH_PRIORITY, IGNORE_PRIORITY, LOW_PRIORITY, NORMAL_PRIORITY -
Constructor Summary
ConstructorsConstructorDescriptionWriteOnlyCollection(edu.umd.cs.findbugs.BugReporter bugReporter) constructs a WOC detector given the reporter to report bugs on -
Method Summary
Modifier and TypeMethodDescriptionprotected booleanimplements the MissingMethodsDetector to determine whether this class type is a collectionprotected booleandoesStaticFactoryReturnNeedToBeWatched(String clsName, String methodName, String signature) implements the MissingMethodsDetector to determine whether this factory-like method returns a collectionprotected booleanisMethodThatShouldBeCalled(String methodName) determines if the method is returns information that could be used by the callerprotected edu.umd.cs.findbugs.BugInstanceimplements the MissingMethodsDetector to generate a Bug Instance when a bug is found around collections stored in fieldsprotected edu.umd.cs.findbugs.BugInstanceimplements the MissingMethodsDetector to generate a Bug Instance when a bug is found around collections stored in a local variableprivate static StringnoParamsReturnType(Class<?> type) voidsawOpcode(int seen) overrides the visitor to look for PUTFIELDS of collectionsvoidvisitMethod(org.apache.bcel.classfile.Method obj) overrides the visitor to see what how many register slots are taken by parameters.Methods inherited from class com.mebigfatguy.fbcontrib.detect.MissingMethodsDetector
clearSpecialField, getParentClassName, getStack, processMethodParms, saveSpecialFieldUse, visitClassContext, visitCode, visitFieldMethods inherited from class edu.umd.cs.findbugs.BytecodeScanningDetector
getClassContext, report, shouldVisitCodeMethods inherited from class edu.umd.cs.findbugs.visitclass.DismantleBytecode
afterOpcode, areOppositeBranches, atCatchBlock, beforeOpcode, 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, visitMethods inherited from class edu.umd.cs.findbugs.visitclass.AnnotationVisitor
getAnnotationParameterAsEnum, getAnnotationParameterAsString, getAnnotationParameterAsStringArray, visitAnnotation, visitAnnotation, visitParameterAnnotation, visitParameterAnnotation, visitSyntheticParameterAnnotationMethods 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, visitAfter, visitAnnotationDefault, visitAnnotationEntry, visitBootstrapMethods, visitConstantInvokeDynamic, visitConstantMethodHandle, visitConstantMethodType, visitConstantModule, visitConstantPackage, visitConstantPool, visitEnclosingMethod, visitingField, visitingMethod, visitInnerClasses, visitJavaClass, visitLineNumberTable, visitLocalVariableTable, visitMethodParameters, visitParameterAnnotationEntry, visitStackMap, visitStackMapEntryMethods 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, visit, visit, visitCodeException, visitConstantClass, visitConstantDouble, visitConstantFieldref, visitConstantFloat, visitConstantInteger, visitConstantInterfaceMethodref, visitConstantLong, visitConstantMethodref, visitConstantNameAndType, visitConstantString, visitConstantUtf8, visitConstantValue, visitDeprecated, visitExceptionTable, visitInnerClass, visitLineNumber, visitLocalVariable, visitLocalVariableTypeTable, visitSignature, visitSourceFile, visitSynthetic, visitUnknownMethods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface org.apache.bcel.classfile.Visitor
visitConstantDynamic, visitMethodParameter, visitModule, visitModuleExports, visitModuleMainClass, visitModuleOpens, visitModulePackages, visitModuleProvides, visitModuleRequires, visitNestHost, visitNestMembers, visitRecord, visitRecordComponent, visitStackMapType
-
Field Details
-
collectionClasses
-
collectionFactoryMethods
-
nonInformationalMethods
-
firstLocalRegister
private int firstLocalRegister
-
-
Constructor Details
-
WriteOnlyCollection
public WriteOnlyCollection(edu.umd.cs.findbugs.BugReporter bugReporter) constructs a WOC detector given the reporter to report bugs on- Parameters:
bugReporter- the sync of bug reports
-
-
Method Details
-
noParamsReturnType
-
visitMethod
public void visitMethod(org.apache.bcel.classfile.Method obj) overrides the visitor to see what how many register slots are taken by parameters.- Specified by:
visitMethodin interfaceorg.apache.bcel.classfile.Visitor- Overrides:
visitMethodin classedu.umd.cs.findbugs.visitclass.BetterVisitor- Parameters:
obj- the currently parsed method
-
sawOpcode
public void sawOpcode(int seen) overrides the visitor to look for PUTFIELDS of collections- Overrides:
sawOpcodein classMissingMethodsDetector- Parameters:
seen- the currently parsed opcode
-
makeFieldBugInstance
protected edu.umd.cs.findbugs.BugInstance makeFieldBugInstance()implements the MissingMethodsDetector to generate a Bug Instance when a bug is found around collections stored in fields- Specified by:
makeFieldBugInstancein classMissingMethodsDetector- Returns:
- the BugInstance
-
makeLocalBugInstance
protected edu.umd.cs.findbugs.BugInstance makeLocalBugInstance()implements the MissingMethodsDetector to generate a Bug Instance when a bug is found around collections stored in a local variable- Specified by:
makeLocalBugInstancein classMissingMethodsDetector- Returns:
- the BugInstance
-
doesObjectNeedToBeWatched
implements the MissingMethodsDetector to determine whether this class type is a collection- Specified by:
doesObjectNeedToBeWatchedin classMissingMethodsDetector- Parameters:
type- the class type to check- Returns:
- whether this class is a collection
-
doesStaticFactoryReturnNeedToBeWatched
protected boolean doesStaticFactoryReturnNeedToBeWatched(String clsName, String methodName, String signature) implements the MissingMethodsDetector to determine whether this factory-like method returns a collection- Specified by:
doesStaticFactoryReturnNeedToBeWatchedin classMissingMethodsDetector- Parameters:
clsName- the clsName the class name of the factorymethodName- the method name of the factorysignature- the signature of the factory method- Returns:
- whether this class is a collection
-
isMethodThatShouldBeCalled
determines if the method is returns information that could be used by the caller- Specified by:
isMethodThatShouldBeCalledin classMissingMethodsDetector- Parameters:
methodName- collection method name- Returns:
- true if the caller could use the return value to learn something about the collection
-