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

@CustomUserValue public class WriteOnlyCollection extends MissingMethodsDetector
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

    Fields
    Modifier and Type
    Field
    Description
    private static final Set<String>
     
    private static final Set<FQMethod>
     
    private int
     
    private static final Set<String>
     

    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
    WriteOnlyCollection(edu.umd.cs.findbugs.BugReporter bugReporter)
    constructs a WOC detector given the reporter to report bugs on
  • Method Summary

    Modifier and Type
    Method
    Description
    protected boolean
    implements the MissingMethodsDetector to determine whether this class type is a collection
    protected boolean
    doesStaticFactoryReturnNeedToBeWatched(String clsName, String methodName, String signature)
    implements the MissingMethodsDetector to determine whether this factory-like method returns a collection
    protected boolean
    determines if the method is returns information that could be used by the caller
    protected edu.umd.cs.findbugs.BugInstance
    implements the MissingMethodsDetector to generate a Bug Instance when a bug is found around collections stored in fields
    protected edu.umd.cs.findbugs.BugInstance
    implements the MissingMethodsDetector to generate a Bug Instance when a bug is found around collections stored in a local variable
    private static String
     
    void
    sawOpcode(int seen)
    overrides the visitor to look for PUTFIELDS of collections
    void
    visitMethod(org.apache.bcel.classfile.Method obj)
    overrides the visitor to see what how many register slots are taken by parameters.

    Methods inherited from class edu.umd.cs.findbugs.BytecodeScanningDetector

    getClassContext, report, shouldVisitCode

    Methods 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, 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, 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, visit, visit, visitCodeException, visitConstantClass, visitConstantDouble, visitConstantFieldref, visitConstantFloat, visitConstantInteger, visitConstantInterfaceMethodref, visitConstantLong, visitConstantMethodref, visitConstantNameAndType, visitConstantString, visitConstantUtf8, visitConstantValue, visitDeprecated, visitExceptionTable, visitInnerClass, visitLineNumber, visitLocalVariable, visitLocalVariableTypeTable, 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 Details

    • collectionClasses

      private static final Set<String> collectionClasses
    • collectionFactoryMethods

      private static final Set<FQMethod> collectionFactoryMethods
    • nonInformationalMethods

      private static final Set<String> 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

      private static String noParamsReturnType(Class<?> type)
    • 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:
      visitMethod in interface org.apache.bcel.classfile.Visitor
      Overrides:
      visitMethod in class edu.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:
      sawOpcode in class MissingMethodsDetector
      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:
      makeFieldBugInstance in class MissingMethodsDetector
      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:
      makeLocalBugInstance in class MissingMethodsDetector
      Returns:
      the BugInstance
    • doesObjectNeedToBeWatched

      protected boolean doesObjectNeedToBeWatched(@DottedClassName String type)
      implements the MissingMethodsDetector to determine whether this class type is a collection
      Specified by:
      doesObjectNeedToBeWatched in class MissingMethodsDetector
      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:
      doesStaticFactoryReturnNeedToBeWatched in class MissingMethodsDetector
      Parameters:
      clsName - the clsName the class name of the factory
      methodName - the method name of the factory
      signature - the signature of the factory method
      Returns:
      whether this class is a collection
    • isMethodThatShouldBeCalled

      protected boolean isMethodThatShouldBeCalled(String methodName)
      determines if the method is returns information that could be used by the caller
      Specified by:
      isMethodThatShouldBeCalled in class MissingMethodsDetector
      Parameters:
      methodName - collection method name
      Returns:
      true if the caller could use the return value to learn something about the collection