@ Override public void visitCode ( Code obj ) { Method method = getMethod ( ) ; if ( method . isSynthetic ( ) ) { return ; } declaredCheckedExceptions . clear ( ) ; stack . resetForMethodEntry ( this ) ; ExceptionTable et = method . getExceptionTable ( ) ; if ( et != null ) { if ( classIsFinal || classIsAnonymous || method . isStatic ( ) || method . isPrivate ( ) || method . isFinal ( ) || ( ( Values . CONSTRUCTOR . equals ( method . getName ( ) ) && ! isAnonymousInnerCtor ( method , getThisClass ( ) ) ) ) ) { String [ ] exNames = et . getExceptionNames ( ) ; for ( String exName : exNames ) { try { JavaClass exCls = Repository . lookupClass ( exName ) ; if ( ! exCls . instanceOf ( runtimeExceptionClass ) ) { declaredCheckedExceptions . add ( exName ) ; } } catch ( ClassNotFoundException cnfe ) { bugReporter . reportMissingClass ( cnfe ) ; } } if ( ! declaredCheckedExceptions . isEmpty ( ) ) { try { super . visitCode ( obj ) ; if ( ! declaredCheckedExceptions . isEmpty ( ) ) { BugInstance bi = new BugInstance ( this , BugType . BED_BOGUS_EXCEPTION_DECLARATION . name ( ) , NORMAL_PRIORITY ) . addClass ( this ) . addMethod ( this ) . addSourceLine ( this , 0 ) ; for ( String ex : declaredCheckedExceptions ) { bi . addString ( ex . replaceAll ( "/" , "." ) ) ; } bugReporter . reportBug ( bi ) ; } } catch ( StopOpcodeParsingException e ) { // no exceptions left } } } String [ ] exNames = et . getExceptionNames ( ) ; for ( int i = 0 ; i < ( exNames . length - 1 ) ; i ++ ) { try { JavaClass exCls1 = Repository . lookupClass ( exNames [ i ] ) ; for ( int j = i + 1 ; j < exNames . length ; j ++ ) { JavaClass exCls2 = Repository . lookupClass ( exNames [ j ] ) ; JavaClass childEx ; JavaClass parentEx ; if ( exCls1 . instanceOf ( exCls2 ) ) { childEx = exCls1 ; parentEx = exCls2 ; } else if ( exCls2 . instanceOf ( exCls1 ) ) { childEx = exCls2 ; parentEx = exCls1 ; } else { continue ; } if ( ! parentEx . equals ( exceptionClass ) ) { bugReporter . reportBug ( new BugInstance ( this , BugType . BED_HIERARCHICAL_EXCEPTION_DECLARATION . name ( ) , NORMAL_PRIORITY ) . addClass ( this ) . addMethod ( this ) . addString ( childEx . getClassName ( ) + " derives from " + parentEx . getClassName ( ) ) ) ; return ; } } } catch ( ClassNotFoundException cnfe ) { bugReporter . reportMissingClass ( cnfe ) ; } } } }
implements the visitor to see if the method declares that it throws any checked exceptions .