Package com.mebigfatguy.fbcontrib.detect
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 -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate static org.apache.bcel.classfile.JavaClassprivate final edu.umd.cs.findbugs.BugReporterprivate Set<LostExceptionStackTrace.CatchInfo> private org.apache.bcel.classfile.CodeException[]private booleanprivate edu.umd.cs.findbugs.OpcodeStackprivate static org.apache.bcel.classfile.JavaClassFields inherited from class edu.umd.cs.findbugs.visitclass.DismantleBytecode
codeBytes, lineNumberTable, M_BR, M_CP, M_INT, M_PAD, M_R, M_UINTFields inherited from interface edu.umd.cs.findbugs.Priorities
EXP_PRIORITY, HIGH_PRIORITY, IGNORE_PRIORITY, LOW_PRIORITY, NORMAL_PRIORITY -
Constructor Summary
ConstructorsConstructorDescriptionLostExceptionStackTrace(edu.umd.cs.findbugs.BugReporter bugReporter) constructs a LEST detector given the reporter to report bugs on -
Method Summary
Modifier and TypeMethodDescriptionprivate voidaddCatchBlock(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 finishorg.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 targetbooleanisPossibleExBuilder(int excReg) returns whether the method called might be a method that builds an exception using the original exception.private static booleanisPre14Class(org.apache.bcel.classfile.JavaClass cls) returns whether the class in question was compiled with a jdk less than 1.4booleanprescreen(org.apache.bcel.classfile.Code code, org.apache.bcel.classfile.Method method) looks for methods that contain a catch block and an ATHROW opcodeprivate voidremoveIndeterminateHandlers(int pc) private voidremovePreviousHandlers(int pc) voidsawOpcode(int seen) implements the visitor to find throwing alternative exceptions from a catch block, without forwarding along the original exceptionprivate booleanupdateExceptionRegister(LostExceptionStackTrace.CatchInfo ci, int seen, int pc) looks to update the catchinfo block with the register used for the exception variable.voidvisitClassContext(edu.umd.cs.findbugs.ba.ClassContext classContext) implements the visitor to make sure the jdk is 1.4 or bettervoidvisitCode(org.apache.bcel.classfile.Code obj) implements the visitor to filter out methods that don't throw exceptionsMethods inherited from class edu.umd.cs.findbugs.BytecodeScanningDetector
getClassContext, report, shouldVisitCodeMethods 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, visitMethods inherited from class edu.umd.cs.findbugs.visitclass.AnnotationVisitor
getAnnotationParameterAsEnum, getAnnotationParameterAsString, getAnnotationParameterAsStringArray, visitAnnotation, visitAnnotation, visitParameterAnnotation, visitParameterAnnotation, visitSyntheticParameterAnnotationMethods 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, visitStackMapEntryMethods 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, visitUnknownMethods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods 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
-
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:
visitClassContextin interfaceedu.umd.cs.findbugs.Detector- Overrides:
visitClassContextin classedu.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 blockmethod- 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:
visitCodein interfaceorg.apache.bcel.classfile.Visitor- Overrides:
visitCodein classedu.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:
sawOpcodein classedu.umd.cs.findbugs.visitclass.DismantleBytecode
-
isPossibleExBuilder
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
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 pcseen- the opcode of the currently visited instructionpc- 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 pcfinish- the guessed end of the catch block
-