Class RuntimeExceptionDeclared

java.lang.Object
edu.umd.cs.findbugs.visitclass.BetterVisitor
edu.umd.cs.findbugs.visitclass.PreorderVisitor
com.mebigfatguy.fbcontrib.detect.RuntimeExceptionDeclared
All Implemented Interfaces:
edu.umd.cs.findbugs.Detector, edu.umd.cs.findbugs.Priorities, org.apache.bcel.classfile.Visitor

public class RuntimeExceptionDeclared extends edu.umd.cs.findbugs.visitclass.PreorderVisitor implements edu.umd.cs.findbugs.Detector
looks for methods that declare Runtime exceptions in their throws clause. While doing so is not illegal, it may represent a misunderstanding as to the exception in question. If a RuntimeException is declared, it implies that this exception type is expected to happen, which if true, should be handled in code, and not propagated.
  • Field Summary

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

    Fields inherited from interface edu.umd.cs.findbugs.Priorities

    EXP_PRIORITY, HIGH_PRIORITY, IGNORE_PRIORITY, LOW_PRIORITY, NORMAL_PRIORITY
  • Constructor Summary

    Constructors
    Constructor
    Description
    RuntimeExceptionDeclared(edu.umd.cs.findbugs.BugReporter bugReporter)
    constructs a DRE detector given the reporter to report bugs on
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    implementation of the detector, with null implementation
    void
    visitClassContext(edu.umd.cs.findbugs.ba.ClassContext classContext)
    overrides the visitor and accepts if the Exception class was loaded
    void
    visitMethod(org.apache.bcel.classfile.Method obj)
    overrides the visitor to find declared runtime exceptions

    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, visitAnnotation, visitAnnotationDefault, visitAnnotationEntry, visitBootstrapMethods, visitCode, visitConstantInvokeDynamic, visitConstantMethodHandle, visitConstantMethodType, visitConstantModule, visitConstantPackage, visitConstantPool, visitEnclosingMethod, visitingField, visitingMethod, visitInnerClasses, visitJavaClass, visitLineNumberTable, visitLocalVariableTable, visitMethodParameters, visitParameterAnnotation, 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, visit, visitCodeException, visitConstantClass, visitConstantDouble, visitConstantFieldref, visitConstantFloat, visitConstantInteger, visitConstantInterfaceMethodref, visitConstantLong, visitConstantMethodref, visitConstantNameAndType, visitConstantString, visitConstantUtf8, visitConstantValue, visitDeprecated, visitExceptionTable, visitField, 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

    • runtimeExceptionClass

      private static org.apache.bcel.classfile.JavaClass runtimeExceptionClass
    • bugReporter

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

      private final Set<String> runtimeExceptions
  • Constructor Details

    • RuntimeExceptionDeclared

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

    • visitClassContext

      public void visitClassContext(edu.umd.cs.findbugs.ba.ClassContext classContext)
      overrides the visitor and accepts if the Exception class was loaded
      Specified by:
      visitClassContext in interface edu.umd.cs.findbugs.Detector
      Parameters:
      classContext - the context object for the currently parsed class
    • visitMethod

      public void visitMethod(org.apache.bcel.classfile.Method obj)
      overrides the visitor to find declared runtime exceptions
      Specified by:
      visitMethod in interface org.apache.bcel.classfile.Visitor
      Overrides:
      visitMethod in class edu.umd.cs.findbugs.visitclass.BetterVisitor
      Parameters:
      obj - the method object of the currently parsed method
    • report

      public void report()
      implementation of the detector, with null implementation
      Specified by:
      report in interface edu.umd.cs.findbugs.Detector