Package com.mebigfatguy.fbcontrib.detect
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
FieldsModifier and TypeFieldDescriptionprivate final edu.umd.cs.findbugs.BugReporterprivate booleanprivate booleanprivate org.apache.bcel.classfile.JavaClassprivate static final booleanprivate static final Stringprivate org.apache.bcel.classfile.JavaClassprivate edu.umd.cs.findbugs.OpcodeStackFields 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
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprivate voidclears all declared checked exceptions and throws an exception to stop opcode parsingprivate static booleanisAnonymousInnerCtor(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 voidremoveException(String clsName) removes the declared checked exception, and if that was the last declared exception, stops opcode parsing by throwing exceptionprivate voidremoveThrownExceptionHierarchy(String thrownException) removes this thrown exception the list of declared thrown exceptions, including all exceptions in this exception's hierarchy.voidsawOpcode(int seen) implements the visitor to look for method calls that could throw the exceptions that are listed in the declaration.voidvisitClassContext(edu.umd.cs.findbugs.ba.ClassContext classContext) overrides the visitor to create the opcode stackvoidvisitCode(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, 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
-
IGNORE_INHERITED_METHODS_PROPERTY
- See Also:
-
SAFE_CLASSES
-
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
-
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:
visitClassContextin interfaceedu.umd.cs.findbugs.Detector- Overrides:
visitClassContextin classedu.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:
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
-
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 checkcls- 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:
sawOpcodein classedu.umd.cs.findbugs.visitclass.DismantleBytecode
-
removeThrownExceptionHierarchy
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
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
-