Class LostExceptionStackTrace

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

@CustomUserValue public class LostExceptionStackTrace extends edu.umd.cs.findbugs.BytecodeScanningDetector
looks for methods that catch exceptions, and rethrow another exception without encapsulating the original exception within it. Doing this loses the stack history, and where the original problem occurred. This makes finding and fixing errors difficult.
  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Class
    Description
    private static class 
     
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    private static org.apache.bcel.classfile.JavaClass
     
    private final edu.umd.cs.findbugs.BugReporter
     
     
    private org.apache.bcel.classfile.CodeException[]
     
     
    private boolean
     
    private edu.umd.cs.findbugs.OpcodeStack
     
    private static org.apache.bcel.classfile.JavaClass
     

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

    Modifier and Type
    Method
    Description
    private void
    addCatchBlock(int start, int finish)
    add a catch block info record for the catch block that is guessed to be in the range of start to finish
    org.apache.bcel.classfile.CodeException[]
    collectExceptions(org.apache.bcel.classfile.CodeException... exs)
    collects all the valid exception objects (ones where start and finish are before the target
    boolean
    isPossibleExBuilder(int excReg)
    returns whether the method called might be a method that builds an exception using the original exception.
    private static boolean
    isPre14Class(org.apache.bcel.classfile.JavaClass cls)
    returns whether the class in question was compiled with a jdk less than 1.4
    boolean
    prescreen(org.apache.bcel.classfile.Code code, org.apache.bcel.classfile.Method method)
    looks for methods that contain a catch block and an ATHROW opcode
    private void
     
    private void
     
    void
    sawOpcode(int seen)
    implements the visitor to find throwing alternative exceptions from a catch block, without forwarding along the original exception
    private boolean
    looks to update the catchinfo block with the register used for the exception variable.
    void
    visitClassContext(edu.umd.cs.findbugs.ba.ClassContext classContext)
    implements the visitor to make sure the jdk is 1.4 or better
    void
    visitCode(org.apache.bcel.classfile.Code obj)
    implements the visitor to filter out methods that don't throw 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

    • throwableClass

      private static org.apache.bcel.classfile.JavaClass throwableClass
    • assertionClass

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

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

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

      private org.apache.bcel.classfile.CodeException[] exceptions
    • catchInfos

    • exReg

      private Map<Integer,Boolean> exReg
    • lastWasExitPoint

      private boolean lastWasExitPoint
  • Constructor Details

    • LostExceptionStackTrace

      public LostExceptionStackTrace(edu.umd.cs.findbugs.BugReporter bugReporter)
      constructs a LEST 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)
      implements the visitor to make sure the jdk is 1.4 or better
      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
    • prescreen

      public boolean prescreen(org.apache.bcel.classfile.Code code, org.apache.bcel.classfile.Method method)
      looks for methods that contain a catch block and an ATHROW opcode
      Parameters:
      code - the context object of the current code block
      method - the context object of the current method
      Returns:
      if the class throws exceptions
    • visitCode

      public void visitCode(org.apache.bcel.classfile.Code obj)
      implements the visitor to filter out methods that don't throw 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
    • collectExceptions

      public org.apache.bcel.classfile.CodeException[] collectExceptions(org.apache.bcel.classfile.CodeException... exs)
      collects all the valid exception objects (ones where start and finish are before the target
      Parameters:
      exs - the exceptions from the class file
      Returns:
      the filtered exceptions
    • sawOpcode

      public void sawOpcode(int seen)
      implements the visitor to find throwing alternative exceptions from a catch block, without forwarding along the original exception
      Overrides:
      sawOpcode in class edu.umd.cs.findbugs.visitclass.DismantleBytecode
    • isPossibleExBuilder

      public boolean isPossibleExBuilder(int excReg) throws ClassNotFoundException
      returns whether the method called might be a method that builds an exception using the original exception. It does so by looking to see if the method returns an exception, and if one of the parameters is the original exception
      Parameters:
      excReg - the register of the original exception caught
      Returns:
      whether this method call could be an exception builder method
      Throws:
      ClassNotFoundException - if the class of the return type can't be found
    • isPre14Class

      private static boolean isPre14Class(org.apache.bcel.classfile.JavaClass cls)
      returns whether the class in question was compiled with a jdk less than 1.4
      Parameters:
      cls - the class to check
      Returns:
      whether the class is compiled with a jdk less than 1.4
    • removePreviousHandlers

      private void removePreviousHandlers(int pc)
    • removeIndeterminateHandlers

      private void removeIndeterminateHandlers(int pc)
    • updateExceptionRegister

      private boolean updateExceptionRegister(LostExceptionStackTrace.CatchInfo ci, int seen, int pc)
      looks to update the catchinfo block with the register used for the exception variable. If their is a local variable table, but the local variable can't be found return false, signifying an empty catch block.
      Parameters:
      ci - the catchinfo record for the catch starting at this pc
      seen - the opcode of the currently visited instruction
      pc - the current pc
      Returns:
      whether the catch block is empty
    • addCatchBlock

      private void addCatchBlock(int start, int finish)
      add a catch block info record for the catch block that is guessed to be in the range of start to finish
      Parameters:
      start - the handler pc
      finish - the guessed end of the catch block