Class SillynessPotPourri

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.SillynessPotPourri
All Implemented Interfaces:
edu.umd.cs.findbugs.Detector, edu.umd.cs.findbugs.Priorities, org.apache.bcel.classfile.Visitor

@CustomUserValue public class SillynessPotPourri extends edu.umd.cs.findbugs.BytecodeScanningDetector
looks for silly bugs that are simple but do not fit into one large pattern.
  • Field Details

    • collectionInterfaces

      private static final Set<String> collectionInterfaces
    • oddMissingEqualsClasses

      private static final Set<String> oddMissingEqualsClasses
    • LITERAL

      private static final String LITERAL
      See Also:
    • APPEND_PATTERN

      private static final Pattern APPEND_PATTERN
    • calendarClass

      private static org.apache.bcel.classfile.JavaClass calendarClass
    • POSSIBLE_STATIC_FIELD_CLASSES

      private static final Set<String> POSSIBLE_STATIC_FIELD_CLASSES
    • methodsThatAreSillyOnStringLiterals

      private static Map<QMethod,Integer> methodsThatAreSillyOnStringLiterals
    • bugReporter

      private final edu.umd.cs.findbugs.BugReporter bugReporter
    • toStringClasses

      private final Set<String> toStringClasses
    • stack

      private edu.umd.cs.findbugs.OpcodeStack stack
    • lastPCs

      private int[] lastPCs
    • lastOpcode

      private int lastOpcode
    • lastReg

      private int lastReg
    • lastIfEqWasBoolean

      private boolean lastIfEqWasBoolean
    • lastLoadWasString

      private boolean lastLoadWasString
    • branchTargets

      private Map<Integer,BitSet> branchTargets
      branch targets, to a set of branch instructions
    • staticConstants

      private Set<String> staticConstants
    • trimLocations

    • possibleStatics

    • clsName

      private String clsName
    • isInterface

      private boolean isInterface
    • isCtor

      private boolean isCtor
  • Constructor Details

    • SillynessPotPourri

      public SillynessPotPourri(edu.umd.cs.findbugs.BugReporter bugReporter)
      constructs a SPP detector given the reporter to report bugs on
      Parameters:
      bugReporter - the sync of bug reports
  • Method Details

    • visitField

      public void visitField(org.apache.bcel.classfile.Field field)
      Specified by:
      visitField in interface org.apache.bcel.classfile.Visitor
      Overrides:
      visitField in class edu.umd.cs.findbugs.visitclass.BetterVisitor
    • visitClassContext

      public void visitClassContext(edu.umd.cs.findbugs.ba.ClassContext classContext)
      Specified by:
      visitClassContext in interface edu.umd.cs.findbugs.Detector
      Overrides:
      visitClassContext in class edu.umd.cs.findbugs.BytecodeScanningDetector
    • visitCode

      public void visitCode(org.apache.bcel.classfile.Code obj)
      implements the visitor to reset the opcode stack
      Specified by:
      visitCode in interface org.apache.bcel.classfile.Visitor
      Overrides:
      visitCode in class edu.umd.cs.findbugs.visitclass.PreorderVisitor
      Parameters:
      obj - the context object for the currently parsed Code
    • sawOpcode

      public void sawOpcode(int seen)
      implements the visitor to look for various silly bugs
      Overrides:
      sawOpcode in class edu.umd.cs.findbugs.visitclass.DismantleBytecode
      Parameters:
      seen - the opcode of the currently parsed instruction
    • checkImproperToCharArrayUse

      private void checkImproperToCharArrayUse()
    • sawIntConst

      @Nullable private SillynessPotPourri.SPPUserValue sawIntConst()
    • sawLoad

      private void sawLoad(int seen)
    • checkTrimDupStore

      private void checkTrimDupStore()
      determines whether this operation is storing the result of a trim() call, where the trimmed string was duplicated on the stack. If it was, it clears any trim uservalue that was left behind in the dupped stack object
    • checkStutterdAssignment

      private void checkStutterdAssignment(int seen, int reg)
    • checkImmutableUsageOfStringBuilder

      private void checkImmutableUsageOfStringBuilder(int reg)
    • checkCompareToNaNFloat

      private void checkCompareToNaNFloat()
    • checkCompareToNaNDouble

      private void checkCompareToNaNDouble()
    • checkApproximationsOfMathConstants

      private void checkApproximationsOfMathConstants()
    • checkForUselessTernaryReturn

      private void checkForUselessTernaryReturn()
    • checkEqualsStringBufferLength

      private void checkEqualsStringBufferLength()
    • checkNotEqualsStringBuilderLength

      private void checkNotEqualsStringBuilderLength()
    • checkNullAndInstanceOf

      private void checkNullAndInstanceOf()
    • checkSizeEquals0

      private void checkSizeEquals0()
    • checkForEmptyStringAndNullChecks

      private void checkForEmptyStringAndNullChecks(int seen)
    • checkPossibleStatic

      private void checkPossibleStatic()
    • isBranchByteCode

      private static boolean isBranchByteCode(int seen)
    • sawInvokeStatic

      private SillynessPotPourri.SPPUserValue sawInvokeStatic()
    • checkForArrayParameter

      private void checkForArrayParameter(edu.umd.cs.findbugs.OpcodeStack.Item item)
    • sawInvokeVirtual

      @Nullable private SillynessPotPourri.SPPUserValue sawInvokeVirtual() throws ClassNotFoundException
      Throws:
      ClassNotFoundException
    • bitSetSilliness

      private void bitSetSilliness(String methodName)
    • stringBufferSilliness

      @Nullable private SillynessPotPourri.SPPUserValue stringBufferSilliness(String methodName)
    • stringSilliness

      private SillynessPotPourri.SPPUserValue stringSilliness(String methodName, String signature)
    • checkForTrim

      private void checkForTrim(edu.umd.cs.findbugs.OpcodeStack.Item item)
    • equalsSilliness

      private void equalsSilliness(String className)
    • booleanSilliness

      private void booleanSilliness()
    • calendarBeforeAfterSilliness

      private void calendarBeforeAfterSilliness()
    • defaultToStringSilliness

      private void defaultToStringSilliness() throws ClassNotFoundException
      Throws:
      ClassNotFoundException
    • propertiesSilliness

      private void propertiesSilliness(String methodName)
    • sawInvokeInterface

      private SillynessPotPourri.SPPUserValue sawInvokeInterface()
    • checkThisParm

      private void checkThisParm()
      checks to see if the object that the method is being called on is also passed as a parameter. To rule out simple mathish like calls like a.mul(a); only check two plus parameter calls.
    • sawInvokeSpecial

      private void sawInvokeSpecial()
    • looksLikeStaticFieldValue

      private boolean looksLikeStaticFieldValue(String constant)
    • hasToString

      private boolean hasToString(org.apache.bcel.classfile.JavaClass cls) throws ClassNotFoundException
      Throws:
      ClassNotFoundException
    • getTrimUserValue

      @Nullable private SillynessPotPourri.SPPUserValue getTrimUserValue()
    • checkTrimLocations

      private void checkTrimLocations()
    • hasRuntimeAnnotation

      private boolean hasRuntimeAnnotation(org.apache.bcel.classfile.Field field)