Class BogusExceptionDeclaration

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

public class BogusExceptionDeclaration extends edu.umd.cs.findbugs.BytecodeScanningDetector
looks for constructors, private methods or static methods that declare that they throw specific checked exceptions, but that do not. This just causes callers of these methods to do extra work to handle an exception that will never be thrown. also looks for throws clauses where two exceptions declared to be thrown are related through inheritance.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    private final edu.umd.cs.findbugs.BugReporter
     
    private boolean
     
    private boolean
     
    private Set<String>
     
    private org.apache.bcel.classfile.JavaClass
     
    private static final boolean
     
    private static final String
     
    private org.apache.bcel.classfile.JavaClass
     
    private static final Set<String>
     
    private static final Set<FQMethod>
     
    private edu.umd.cs.findbugs.OpcodeStack
     

    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
    BogusExceptionDeclaration(edu.umd.cs.findbugs.BugReporter bugReporter)
     
  • Method Summary

    Modifier and Type
    Method
    Description
    private void
    clears all declared checked exceptions and throws an exception to stop opcode parsing
    private static boolean
    isAnonymousInnerCtor(org.apache.bcel.classfile.Method m, org.apache.bcel.classfile.JavaClass cls)
    checks to see if this method is a constructor of an instance based inner class, the handling of the Exception table for this method is odd, -- doesn't seem correct, in some cases.
    private void
    removes the declared checked exception, and if that was the last declared exception, stops opcode parsing by throwing exception
    private void
    removes this thrown exception the list of declared thrown exceptions, including all exceptions in this exception's hierarchy.
    void
    sawOpcode(int seen)
    implements the visitor to look for method calls that could throw the exceptions that are listed in the declaration.
    void
    visitClassContext(edu.umd.cs.findbugs.ba.ClassContext classContext)
    overrides the visitor to create the opcode stack
    void
    visitCode(org.apache.bcel.classfile.Code obj)
    implements the visitor to see if the method declares that it throws any checked exceptions.

    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, 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 Details

    • IGNORE_INHERITED_METHODS_PROPERTY

      private static final String IGNORE_INHERITED_METHODS_PROPERTY
      See Also:
    • SAFE_CLASSES

      private static final Set<String> SAFE_CLASSES
    • SAFE_EXCEPTION_METHODS

      private static final Set<FQMethod> SAFE_EXCEPTION_METHODS
    • IGNORE_INHERITED_METHODS

      private static final boolean IGNORE_INHERITED_METHODS
    • bugReporter

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

      private org.apache.bcel.classfile.JavaClass runtimeExceptionClass
    • exceptionClass

      private org.apache.bcel.classfile.JavaClass exceptionClass
    • stack

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

      private Set<String> declaredCheckedExceptions
    • classIsFinal

      private boolean classIsFinal
    • classIsAnonymous

      private boolean classIsAnonymous
  • Constructor Details

    • BogusExceptionDeclaration

      public BogusExceptionDeclaration(edu.umd.cs.findbugs.BugReporter bugReporter)
  • Method Details

    • visitClassContext

      public void visitClassContext(edu.umd.cs.findbugs.ba.ClassContext classContext)
      overrides the visitor to create the opcode stack
      Specified by:
      visitClassContext in interface edu.umd.cs.findbugs.Detector
      Overrides:
      visitClassContext in class edu.umd.cs.findbugs.BytecodeScanningDetector
      Parameters:
      classContext - the context object of the currently parsed class
    • visitCode

      public void visitCode(org.apache.bcel.classfile.Code obj)
      implements the visitor to see if the method declares that it throws any checked exceptions.
      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 of the currently parsed code block
    • isAnonymousInnerCtor

      private static boolean isAnonymousInnerCtor(org.apache.bcel.classfile.Method m, org.apache.bcel.classfile.JavaClass cls)
      checks to see if this method is a constructor of an instance based inner class, the handling of the Exception table for this method is odd, -- doesn't seem correct, in some cases. So just ignore these cases
      Parameters:
      m - the method to check
      cls - the cls that owns the method
      Returns:
      whether this method is a ctor of an instance based anonymous inner class
    • sawOpcode

      public void sawOpcode(int seen)
      implements the visitor to look for method calls that could throw the exceptions that are listed in the declaration.
      Overrides:
      sawOpcode in class edu.umd.cs.findbugs.visitclass.DismantleBytecode
    • removeThrownExceptionHierarchy

      private void removeThrownExceptionHierarchy(String thrownException)
      removes this thrown exception the list of declared thrown exceptions, including all exceptions in this exception's hierarchy. If an exception class is found that can't be loaded, then just clear the list of declared checked exceptions and get out.
      Parameters:
      thrownException - the exception and it's hierarchy to remove
    • removeException

      private void removeException(String clsName)
      removes the declared checked exception, and if that was the last declared exception, stops opcode parsing by throwing exception
      Parameters:
      clsName - the name of the exception to remove
    • clearExceptions

      private void clearExceptions()
      clears all declared checked exceptions and throws an exception to stop opcode parsing