idx
int64 0
41.2k
| question
stringlengths 83
4.15k
| target
stringlengths 5
715
|
|---|---|---|
3,100
|
public void visitClassContext ( ClassContext classContext ) { JavaClass cls = classContext . getJavaClass ( ) ; if ( cls . isClass ( ) && ( cls . getMajor ( ) >= JDK15_MAJOR ) ) { Map < String , Set < String > > methodInfo = new HashMap < > ( ) ; populateMethodInfo ( cls , methodInfo ) ; Method [ ] methods = cls . getMethods ( ) ; for ( Method m : methods ) { String name = m . getName ( ) ; String signature = m . getSignature ( ) ; Set < String > sigs = methodInfo . get ( name ) ; if ( sigs != null ) { for ( String sig : sigs ) { if ( confusingSignatures ( sig , signature ) ) { bugReporter . reportBug ( new BugInstance ( this , BugType . CAO_CONFUSING_AUTOBOXED_OVERLOADING . name ( ) , NORMAL_PRIORITY ) . addClass ( cls . getClassName ( ) ) . addString ( name + signature ) . addString ( name + sig ) ) ; } } } } } }
|
overrides the visitor to look for confusing signatures
|
3,101
|
private static boolean confusingSignatures ( String sig1 , String sig2 ) { if ( sig1 . equals ( sig2 ) ) { return false ; } List < String > type1 = SignatureUtils . getParameterSignatures ( sig1 ) ; List < String > type2 = SignatureUtils . getParameterSignatures ( sig2 ) ; if ( type1 . size ( ) != type2 . size ( ) ) { return false ; } boolean foundParmDiff = false ; for ( int i = 0 ; i < type1 . size ( ) ; i ++ ) { String typeOneSig = type1 . get ( i ) ; String typeTwoSig = type2 . get ( i ) ; if ( ! typeOneSig . equals ( typeTwoSig ) ) { if ( "Ljava/lang/Character;" . equals ( typeOneSig ) ) { if ( ! primitiveSigs . contains ( typeTwoSig ) ) { return false ; } } else if ( "Ljava/lang/Character;" . equals ( typeTwoSig ) ) { if ( ! primitiveSigs . contains ( typeOneSig ) ) { return false ; } } else { return false ; } foundParmDiff = true ; } } return foundParmDiff ; }
|
returns if one signature is a Character and the other is a primitive
|
3,102
|
private void populateMethodInfo ( JavaClass cls , Map < String , Set < String > > methodInfo ) { try { if ( Values . DOTTED_JAVA_LANG_OBJECT . equals ( cls . getClassName ( ) ) ) { return ; } Method [ ] methods = cls . getMethods ( ) ; for ( Method m : methods ) { String sig = m . getSignature ( ) ; if ( isPossiblyConfusingSignature ( sig ) ) { String name = m . getName ( ) ; Set < String > sigs = methodInfo . get ( name ) ; if ( sigs == null ) { sigs = new HashSet < > ( 3 ) ; methodInfo . put ( name , sigs ) ; } sigs . add ( m . getSignature ( ) ) ; } } populateMethodInfo ( cls . getSuperClass ( ) , methodInfo ) ; } catch ( ClassNotFoundException cnfe ) { bugReporter . reportMissingClass ( cnfe ) ; } }
|
fills out a set of method details for possibly confusing method signatures
|
3,103
|
private static boolean isPossiblyConfusingSignature ( String sig ) { List < String > types = SignatureUtils . getParameterSignatures ( sig ) ; for ( String typeSig : types ) { if ( primitiveSigs . contains ( typeSig ) || SignatureUtils . classToSignature ( Values . SLASHED_JAVA_LANG_CHARACTER ) . equals ( typeSig ) ) { return true ; } } return false ; }
|
returns whether a method signature has either a Character or primitive
|
3,104
|
public void visitCode ( Code obj ) { stack . resetForMethodEntry ( this ) ; toStringRegisters . clear ( ) ; super . visitCode ( obj ) ; }
|
overrides the visitor to resets the stack for this method .
|
3,105
|
public void sawOpcode ( int seen ) { String methodPackage = null ; try { stack . precomputation ( this ) ; if ( seen == Const . INVOKEVIRTUAL ) { methodPackage = processInvokeVirtual ( ) ; } else if ( OpcodeUtils . isAStore ( seen ) ) { if ( stack . getStackDepth ( ) > 0 ) { OpcodeStack . Item item = stack . getStackItem ( 0 ) ; Integer reg = Integer . valueOf ( RegisterUtils . getAStoreReg ( this , seen ) ) ; if ( item . getUserValue ( ) != null ) { XMethod xm = item . getReturnValueOf ( ) ; if ( xm != null ) { toStringRegisters . put ( reg , xm . getPackageName ( ) ) ; } else { toStringRegisters . remove ( reg ) ; } } else { toStringRegisters . remove ( reg ) ; } } } else if ( OpcodeUtils . isALoad ( seen ) ) { Integer reg = Integer . valueOf ( RegisterUtils . getAStoreReg ( this , seen ) ) ; methodPackage = toStringRegisters . get ( reg ) ; } } catch ( ClassNotFoundException cnfe ) { bugReporter . reportMissingClass ( cnfe ) ; } finally { TernaryPatcher . pre ( stack , seen ) ; stack . sawOpcode ( this , seen ) ; TernaryPatcher . post ( stack , seen ) ; if ( ( methodPackage != null ) && ( stack . getStackDepth ( ) > 0 ) ) { OpcodeStack . Item item = stack . getStackItem ( 0 ) ; item . setUserValue ( methodPackage ) ; } } }
|
overrides the visitor to look for suspicious operations on toString
|
3,106
|
public void visitCode ( Code obj ) { try { Method method = getMethod ( ) ; if ( method . isSynthetic ( ) ) { return ; } isBooleanMethod = Type . BOOLEAN . equals ( method . getReturnType ( ) ) ; if ( isBooleanMethod || prescreen ( method ) ) { catchHandlerPCs = collectExceptions ( obj . getExceptionTable ( ) ) ; if ( ! catchHandlerPCs . isEmpty ( ) ) { stack . resetForMethodEntry ( this ) ; catchInfos = new ArrayList < > ( ) ; lvt = method . getLocalVariableTable ( ) ; constrainingInfo = null ; hasValidFalseReturn = false ; catchFalseReturnPC = - 1 ; super . visitCode ( obj ) ; if ( ! hasValidFalseReturn && ( catchFalseReturnPC >= 0 ) && ! method . getName ( ) . startsWith ( "is" ) ) { bugReporter . reportBug ( new BugInstance ( this , BugType . EXS_EXCEPTION_SOFTENING_RETURN_FALSE . name ( ) , NORMAL_PRIORITY ) . addClass ( this ) . addMethod ( this ) . addSourceLine ( this , catchFalseReturnPC ) ) ; } } } } finally { catchInfos = null ; catchHandlerPCs = null ; lvt = null ; constrainingInfo = null ; } }
|
overrides the visitor to look for methods that catch checked exceptions and rethrow runtime exceptions
|
3,107
|
public void sawOpcode ( int seen ) { try { stack . precomputation ( this ) ; int pc = getPC ( ) ; CodeException ex = catchHandlerPCs . get ( Integer . valueOf ( pc ) ) ; if ( ex != null ) { int endPC ; if ( ( seen == Const . GOTO ) || ( seen == Const . GOTO_W ) ) { endPC = this . getBranchTarget ( ) ; } else { endPC = Integer . MAX_VALUE ; } ConstantPool pool = getConstantPool ( ) ; ConstantClass ccls = ( ConstantClass ) pool . getConstant ( ex . getCatchType ( ) ) ; String catchSig = ccls . getBytes ( pool ) ; CatchInfo ci = new CatchInfo ( ex . getHandlerPC ( ) , endPC , catchSig ) ; catchInfos . add ( ci ) ; } updateEndPCsOnCatchRegScope ( catchInfos , pc , seen ) ; removeFinishedCatchBlocks ( catchInfos , pc ) ; if ( seen == Const . ATHROW ) { processThrow ( ) ; } else if ( ( seen == Const . IRETURN ) && isBooleanMethod && ! hasValidFalseReturn && ( stack . getStackDepth ( ) > 0 ) ) { processBooleanReturn ( ) ; } } finally { stack . sawOpcode ( this , seen ) ; } }
|
overrides the visitor to find catch blocks that throw runtime exceptions
|
3,108
|
private static void removeFinishedCatchBlocks ( Iterable < CatchInfo > infos , int pc ) { Iterator < CatchInfo > it = infos . iterator ( ) ; while ( it . hasNext ( ) ) { if ( it . next ( ) . getFinish ( ) < pc ) { it . remove ( ) ; } } }
|
remove catchinfo blocks from the map where the handler end is before the current pc
|
3,109
|
private void updateEndPCsOnCatchRegScope ( List < CatchInfo > infos , int pc , int seen ) { if ( lvt != null ) { for ( CatchInfo ci : infos ) { if ( ( ci . getStart ( ) == pc ) && OpcodeUtils . isAStore ( seen ) ) { int exReg = RegisterUtils . getAStoreReg ( this , seen ) ; LocalVariable lv = lvt . getLocalVariable ( exReg , pc + 1 ) ; if ( lv != null ) { ci . setFinish ( lv . getStartPC ( ) + lv . getLength ( ) ) ; } break ; } } } }
|
reduces the end pc based on the optional LocalVariableTable s exception register scope
|
3,110
|
private static Set < String > findPossibleCatchSignatures ( List < CatchInfo > infos , int pc ) { Set < String > catchTypes = new HashSet < > ( 6 ) ; ListIterator < CatchInfo > it = infos . listIterator ( infos . size ( ) ) ; while ( it . hasPrevious ( ) ) { CatchInfo ci = it . previous ( ) ; if ( ( pc >= ci . getStart ( ) ) && ( pc < ci . getFinish ( ) ) ) { catchTypes . add ( ci . getSignature ( ) ) ; } else { break ; } } return catchTypes ; }
|
returns an array of catch types that the current pc is in
|
3,111
|
private Map < String , Set < String > > getConstrainingInfo ( JavaClass cls , Method m ) throws ClassNotFoundException { String methodName = m . getName ( ) ; String methodSig = m . getSignature ( ) ; { JavaClass [ ] infClasses = cls . getInterfaces ( ) ; for ( JavaClass infCls : infClasses ) { Method infMethod = findMethod ( infCls , methodName , methodSig ) ; if ( infMethod != null ) { return buildConstrainingInfo ( infCls , infMethod ) ; } Map < String , Set < String > > constrainingExs = getConstrainingInfo ( infCls , m ) ; if ( constrainingExs != null ) { return constrainingExs ; } } } { JavaClass superCls = cls . getSuperClass ( ) ; if ( superCls == null ) { return null ; } Method superMethod = findMethod ( superCls , methodName , methodSig ) ; if ( superMethod != null ) { return buildConstrainingInfo ( superCls , superMethod ) ; } return getConstrainingInfo ( superCls , m ) ; } }
|
finds the super class or interface that constrains the types of exceptions that can be thrown from the given method
|
3,112
|
private static Method findMethod ( JavaClass cls , String methodName , String methodSig ) { Method [ ] methods = cls . getMethods ( ) ; for ( Method method : methods ) { if ( method . getName ( ) . equals ( methodName ) && method . getSignature ( ) . equals ( methodSig ) ) { return method ; } } return null ; }
|
finds a method that matches the name and signature in the given class
|
3,113
|
private Map < String , Set < String > > buildConstrainingInfo ( JavaClass cls , Method m ) throws ClassNotFoundException { Map < String , Set < String > > constraintInfo = new HashMap < > ( ) ; Set < String > exs = new HashSet < > ( ) ; ExceptionTable et = m . getExceptionTable ( ) ; if ( et != null ) { int [ ] indexTable = et . getExceptionIndexTable ( ) ; ConstantPool pool = cls . getConstantPool ( ) ; for ( int index : indexTable ) { if ( index != 0 ) { ConstantClass ccls = ( ConstantClass ) pool . getConstant ( index ) ; String exName = ccls . getBytes ( pool ) ; JavaClass exClass = Repository . lookupClass ( exName ) ; if ( ! exClass . instanceOf ( runtimeClass ) ) { exs . add ( ccls . getBytes ( pool ) ) ; } } } } constraintInfo . put ( cls . getClassName ( ) , exs ) ; return constraintInfo ; }
|
returns exception names describing what exceptions are allowed to be thrown
|
3,114
|
public void visitCode ( Code obj ) { try { Method m = getMethod ( ) ; Type retType = m . getReturnType ( ) ; if ( "Ljava/lang/Boolean;" . equals ( retType . getSignature ( ) ) ) { stack . resetForMethodEntry ( this ) ; super . visitCode ( obj ) ; } } catch ( StopOpcodeParsingException e ) { } }
|
implements the visitor to filter out methods that don t return Boolean
|
3,115
|
public void sawOpcode ( int seen ) { try { stack . precomputation ( this ) ; if ( ( seen == Const . ARETURN ) && ( stack . getStackDepth ( ) > 0 ) ) { OpcodeStack . Item item = stack . getStackItem ( 0 ) ; if ( item . isNull ( ) ) { bugReporter . reportBug ( new BugInstance ( this , BugType . TBP_TRISTATE_BOOLEAN_PATTERN . name ( ) , NORMAL_PRIORITY ) . addClass ( this ) . addMethod ( this ) . addSourceLine ( this ) ) ; throw new StopOpcodeParsingException ( ) ; } } } finally { stack . sawOpcode ( this , seen ) ; } }
|
implements the visitor to look for null returns
|
3,116
|
public void visitClassContext ( ClassContext clsContext ) { try { if ( ( collectionCls == null ) || ( setCls == null ) || ( mapCls == null ) ) { return ; } stack = new OpcodeStack ( ) ; super . visitClassContext ( clsContext ) ; } finally { stack = null ; } }
|
implement the visitor to set up the opcode stack and make sure that collection set and map classes could be loaded .
|
3,117
|
public void sawOpcode ( int seen ) { try { stack . precomputation ( this ) ; if ( ( seen == Const . INVOKEVIRTUAL ) || ( seen == Const . INVOKEINTERFACE ) ) { String clsName = getClassConstantOperand ( ) ; String methodName = getNameConstantOperand ( ) ; String signature = getSigConstantOperand ( ) ; if ( "add" . equals ( methodName ) && SignatureBuilder . SIG_OBJECT_TO_BOOLEAN . equals ( signature ) && isImplementationOf ( clsName , setCls ) ) { if ( stack . getStackDepth ( ) > 1 ) { OpcodeStack . Item item = stack . getStackItem ( 0 ) ; JavaClass entryCls = item . getJavaClass ( ) ; if ( isImplementationOf ( entryCls , collectionCls ) ) { bugReporter . reportBug ( new BugInstance ( this , BugType . DSOC_DUBIOUS_SET_OF_COLLECTIONS . name ( ) , NORMAL_PRIORITY ) . addClass ( this ) . addMethod ( this ) . addSourceLine ( this ) ) ; } } } else if ( "put" . equals ( methodName ) && SignatureBuilder . SIG_TWO_OBJECTS_TO_OBJECT . equals ( signature ) && isImplementationOf ( clsName , setCls ) && ( stack . getStackDepth ( ) > 2 ) ) { OpcodeStack . Item item = stack . getStackItem ( 1 ) ; JavaClass entryCls = item . getJavaClass ( ) ; if ( isImplementationOf ( entryCls , collectionCls ) ) { bugReporter . reportBug ( new BugInstance ( this , BugType . DSOC_DUBIOUS_SET_OF_COLLECTIONS . name ( ) , NORMAL_PRIORITY ) . addClass ( this ) . addMethod ( this ) . addSourceLine ( this ) ) ; } } } } catch ( ClassNotFoundException cnfe ) { bugReporter . reportMissingClass ( cnfe ) ; } finally { stack . sawOpcode ( this , seen ) ; } }
|
implements the visitor look for adds to sets or puts to maps where the element to be added is a collection .
|
3,118
|
private boolean lookupSwitchOnString ( ) { if ( stack . getStackDepth ( ) > 1 ) { OpcodeStack . Item item = stack . getStackItem ( 1 ) ; String stringRef = ( String ) item . getUserValue ( ) ; if ( stringRef == null ) { return false ; } if ( ! lookupSwitches . isEmpty ( ) ) { LookupDetails details = lookupSwitches . get ( lookupSwitches . size ( ) - 1 ) ; return stringRef . equals ( details . getStringReference ( ) ) ; } } return true ; }
|
looks to see if the string used in a equals or compareTo is the same as that of a switch statement s switch on string .
|
3,119
|
public void visitMethod ( Method obj ) { stack . resetForMethodEntry ( this ) ; jdbcLocals . clear ( ) ; int [ ] parmRegs = RegisterUtils . getParameterRegisters ( obj ) ; Type [ ] argTypes = obj . getArgumentTypes ( ) ; for ( int t = 0 ; t < argTypes . length ; t ++ ) { String sig = argTypes [ t ] . getSignature ( ) ; if ( isJDBCClass ( sig ) ) { jdbcLocals . put ( Integer . valueOf ( parmRegs [ t ] ) , Integer . valueOf ( RegisterUtils . getLocalVariableEndRange ( obj . getLocalVariableTable ( ) , parmRegs [ t ] , 0 ) ) ) ; } } }
|
implement the visitor to reset the opcode stack and set of locals that are jdbc objects
|
3,120
|
private static boolean fieldHasRuntimeVisibleAnnotation ( Field f ) { AnnotationEntry [ ] annotations = f . getAnnotationEntries ( ) ; if ( annotations != null ) { for ( AnnotationEntry annotation : annotations ) { if ( annotation . isRuntimeVisible ( ) ) { return true ; } } } return false ; }
|
looks to see the field has a runtime visible annotation if it does it might be autowired or some other mechanism attached that makes them less interesting for a toString call .
|
3,121
|
private void checkIDEGeneratedParmNames ( JavaClass cls ) { for ( Method m : cls . getMethods ( ) ) { if ( isIDEGeneratedMethodWithCode ( m ) ) { bugReporter . reportBug ( new BugInstance ( this , BugType . IMC_IMMATURE_CLASS_IDE_GENERATED_PARAMETER_NAMES . name ( ) , NORMAL_PRIORITY ) . addClass ( cls ) . addMethod ( cls , m ) ) ; return ; } } }
|
looks for methods that have it s parameters all follow the form arg0 arg1 arg2 or parm0 parm1 parm2 etc where the method actually has code in it
|
3,122
|
public void visitClassContext ( ClassContext classContext ) { try { ifStatements = new HashSet < > ( ) ; super . visitClassContext ( classContext ) ; } finally { ifStatements = null ; } }
|
implements the visitor to allocate and clear the ifStatements set
|
3,123
|
public void visitClassContext ( final ClassContext classContext ) { try { JavaClass cls = classContext . getJavaClass ( ) ; if ( ! cls . isFinal ( ) ) { stack = new OpcodeStack ( ) ; methodToCalledMethods = new HashMap < > ( ) ; super . visitClassContext ( classContext ) ; if ( ! methodToCalledMethods . isEmpty ( ) ) { reportChainedMethods ( ) ; } } } finally { stack = null ; methodToCalledMethods = null ; } }
|
implements the visitor to set up the stack and methodToCalledmethods map reports calls to public non final methods from methods called from constructors .
|
3,124
|
public void visitClassContext ( ClassContext classContext ) { try { stack = new OpcodeStack ( ) ; changedAttributes = new HashMap < > ( ) ; savedAttributes = new HashMap < > ( ) ; super . visitClassContext ( classContext ) ; } finally { stack = null ; changedAttributes = null ; savedAttributes = null ; } }
|
implements the visitor to setup the opcode stack and attribute maps
|
3,125
|
public void visitCode ( Code obj ) { stack . resetForMethodEntry ( this ) ; changedAttributes . clear ( ) ; savedAttributes . clear ( ) ; super . visitCode ( obj ) ; for ( Integer pc : changedAttributes . values ( ) ) { bugReporter . reportBug ( new BugInstance ( this , BugType . SCSS_SUSPICIOUS_CLUSTERED_SESSION_SUPPORT . name ( ) , NORMAL_PRIORITY ) . addClass ( this ) . addMethod ( this ) . addSourceLine ( this , pc . intValue ( ) ) ) ; } }
|
implements the visitor to report on attributes that have changed without a setAttribute being called on them
|
3,126
|
public void visitMethod ( final Method obj ) { methodName = obj . getName ( ) ; if ( Values . STATIC_INITIALIZER . equals ( methodName ) || Values . CONSTRUCTOR . equals ( methodName ) ) { return ; } List < String > parms = SignatureUtils . getParameterSignatures ( obj . getSignature ( ) ) ; if ( ! parms . isEmpty ( ) ) { boolean isStatic = obj . isStatic ( ) ; isAbstract = obj . isAbstract ( ) ; firstLocalReg = isStatic ? 0 : 1 ; for ( String parmSig : parms ) { firstLocalReg += SignatureUtils . getSignatureSize ( parmSig ) ; } sourceLines = getSourceLines ( obj ) ; } }
|
overrides the visitor capture source lines for the method
|
3,127
|
private String [ ] getSourceLines ( Method obj ) { if ( srcInited ) { return sourceLines ; } try { srcLineAnnotation = SourceLineAnnotation . forEntireMethod ( getClassContext ( ) . getJavaClass ( ) , obj ) ; if ( srcLineAnnotation != null ) { SourceFinder sourceFinder = AnalysisContext . currentAnalysisContext ( ) . getSourceFinder ( ) ; SourceFile sourceFile = sourceFinder . findSourceFile ( srcLineAnnotation . getPackageName ( ) , srcLineAnnotation . getSourceFile ( ) ) ; try ( BufferedReader sourceReader = new BufferedReader ( new InputStreamReader ( sourceFile . getInputStream ( ) , StandardCharsets . UTF_8 ) ) ) { List < String > lines = new ArrayList < > ( 100 ) ; String line ; while ( ( line = sourceReader . readLine ( ) ) != null ) { lines . add ( line ) ; } sourceLines = lines . toArray ( new String [ 0 ] ) ; } } } catch ( IOException ioe ) { } srcInited = true ; return sourceLines ; }
|
reads the sourcefile based on the source line annotation for the method
|
3,128
|
public void visitCode ( final Code obj ) { if ( sourceLines == null ) { return ; } if ( isAbstract ) { return ; } if ( Values . STATIC_INITIALIZER . equals ( methodName ) || Values . CONSTRUCTOR . equals ( methodName ) ) { return ; } int methodStart = srcLineAnnotation . getStartLine ( ) - 2 ; int methodLine = methodStart ; String line ; while ( ( methodLine >= 0 ) && ( methodLine < sourceLines . length ) ) { line = sourceLines [ methodLine ] ; if ( line . indexOf ( methodName ) >= 0 ) { break ; } methodLine -- ; } if ( methodLine < 0 ) { return ; } for ( int i = methodLine ; i <= methodStart ; i ++ ) { if ( ( i < 0 ) || ( i >= sourceLines . length ) ) { return ; } line = sourceLines [ i ] ; if ( line . indexOf ( "final" ) >= 0 ) { return ; } } changedParms = new BitSet ( ) ; super . visitCode ( obj ) ; BugInstance bi = null ; for ( int i = 0 ; i < firstLocalReg ; i ++ ) { if ( changedParms . get ( i ) ) { changedParms . clear ( i ) ; continue ; } String parmName = getRegisterName ( obj , i ) ; if ( bi == null ) { bi = new BugInstance ( this , BugType . FP_FINAL_PARAMETERS . name ( ) , LOW_PRIORITY ) . addClass ( this ) . addMethod ( this ) . addSourceLine ( this , 0 ) ; bugReporter . reportBug ( bi ) ; } bi . addString ( parmName ) ; } changedParms = null ; }
|
overrides the visitor to find the source lines for the method header to find non final parameters
|
3,129
|
public void sawOpcode ( final int seen ) { if ( OpcodeUtils . isAStore ( seen ) ) { changedParms . set ( RegisterUtils . getAStoreReg ( this , seen ) ) ; } }
|
overrides the visitor to find local variable reference stores to store them as changed
|
3,130
|
private static String getRegisterName ( final Code obj , final int reg ) { LocalVariableTable lvt = obj . getLocalVariableTable ( ) ; if ( lvt != null ) { LocalVariable lv = lvt . getLocalVariable ( reg , 0 ) ; if ( lv != null ) { return lv . getName ( ) ; } } return String . valueOf ( reg ) ; }
|
returns the variable name of the specified register slot
|
3,131
|
public void visitClassContext ( ClassContext classContext ) { try { stack = new OpcodeStack ( ) ; registerConstants = new HashMap < > ( ) ; overloadedMethods = collectOverloadedMethods ( classContext . getJavaClass ( ) ) ; super . visitClassContext ( classContext ) ; } finally { stack = null ; registerConstants = null ; overloadedMethods = null ; } }
|
implements the visitor to collect all methods that are overloads . These methods should be ignored as you may differentiate Const based on parameter type or value .
|
3,132
|
public void visitCode ( Code obj ) { Method m = getMethod ( ) ; if ( overloadedMethods . contains ( m ) ) { return ; } int aFlags = m . getAccessFlags ( ) ; if ( ( ( ( aFlags & Const . ACC_PRIVATE ) != 0 ) || ( ( aFlags & Const . ACC_STATIC ) != 0 ) ) && ( ( aFlags & Const . ACC_SYNTHETIC ) == 0 ) && ( ! m . getSignature ( ) . endsWith ( ")Z" ) ) ) { stack . resetForMethodEntry ( this ) ; returnRegister = Values . NEGATIVE_ONE ; returnConstant = null ; registerConstants . clear ( ) ; returnPC = - 1 ; try { super . visitCode ( obj ) ; if ( ( returnConstant != null ) ) { BugInstance bi = new BugInstance ( this , BugType . MRC_METHOD_RETURNS_CONSTANT . name ( ) , ( ( aFlags & Const . ACC_PRIVATE ) != 0 ) ? NORMAL_PRIORITY : LOW_PRIORITY ) . addClass ( this ) . addMethod ( this ) ; if ( returnPC >= 0 ) { bi . addSourceLine ( this , returnPC ) ; } bi . addString ( returnConstant . toString ( ) ) ; bugReporter . reportBug ( bi ) ; } } catch ( StopOpcodeParsingException e ) { } } }
|
implements the visitor to reset the stack and proceed for private methods
|
3,133
|
public void visitMethod ( Method obj ) { firstLocalRegister = SignatureUtils . getFirstRegisterSlot ( obj ) ; super . visitMethod ( obj ) ; }
|
overrides the visitor to see what how many register slots are taken by parameters .
|
3,134
|
public void sawOpcode ( int seen ) { if ( seen == Const . PUTFIELD ) { OpcodeStack stack = getStack ( ) ; if ( stack . getStackDepth ( ) > 0 ) { int reg = stack . getStackItem ( 0 ) . getRegisterNumber ( ) ; if ( ( reg >= 0 ) && ( reg < firstLocalRegister ) ) { clearSpecialField ( getNameConstantOperand ( ) ) ; } } } super . sawOpcode ( seen ) ; }
|
overrides the visitor to look for PUTFIELDS of collections
|
3,135
|
protected boolean doesStaticFactoryReturnNeedToBeWatched ( String clsName , String methodName , String signature ) { return collectionFactoryMethods . contains ( new FQMethod ( clsName , methodName , signature ) ) ; }
|
implements the MissingMethodsDetector to determine whether this factory - like method returns a collection
|
3,136
|
public void visitClassContext ( ClassContext classContext ) { JavaClass cls = classContext . getJavaClass ( ) ; cls . accept ( this ) ; }
|
implements the visitor to accept the class for visiting
|
3,137
|
public void visitMethod ( Method obj ) { Attribute [ ] attributes = obj . getAttributes ( ) ; for ( Attribute a : attributes ) { if ( "Signature" . equals ( a . getName ( ) ) ) { TemplateSignature ts = parseSignatureAttribute ( ( Signature ) a ) ; if ( ts != null ) { for ( TemplateItem templateParm : ts . templateParameters ) { if ( ! ts . signature . contains ( Values . SIG_GENERIC_TEMPLATE + templateParm . templateType + Values . SIG_QUALIFIED_CLASS_SUFFIX_CHAR ) && ! isTemplateParent ( templateParm . templateType , ts . templateParameters ) ) { bugReporter . reportBug ( new BugInstance ( this , BugType . UMTP_UNBOUND_METHOD_TEMPLATE_PARAMETER . name ( ) , NORMAL_PRIORITY ) . addClass ( this ) . addMethod ( this ) . addString ( "Template Parameter: " + templateParm . templateType ) ) ; return ; } } } return ; } } }
|
implements the visitor to find methods that declare template parameters that are not bound to any parameter .
|
3,138
|
private boolean isTemplateParent ( String templateType , TemplateItem ... items ) { for ( TemplateItem item : items ) { if ( templateType . equals ( item . templateExtension ) ) { return true ; } } return false ; }
|
looks to see if this templateType is a parent of another template type
|
3,139
|
private static TemplateSignature parseSignatureAttribute ( Signature signatureAttribute ) { Matcher m = TEMPLATED_SIGNATURE . matcher ( signatureAttribute . getSignature ( ) ) ; if ( ! m . matches ( ) ) { return null ; } TemplateSignature ts = new TemplateSignature ( ) ; ts . signature = m . group ( 2 ) ; m = TEMPLATE . matcher ( m . group ( 1 ) ) ; List < TemplateItem > templates = new ArrayList < > ( 4 ) ; while ( m . find ( ) ) { templates . add ( new TemplateItem ( m . group ( 1 ) , m . group ( 2 ) ) ) ; } ts . templateParameters = templates . toArray ( new TemplateItem [ 0 ] ) ; return ts ; }
|
builds a template signature object based on the signature attribute of the method
|
3,140
|
public void visitClassContext ( ClassContext classContext ) { try { stack = new OpcodeStack ( ) ; mapBugs = new ArrayList < > ( ) ; setBugs = new ArrayList < > ( ) ; hasMapComparator = false ; hasSetComparator = false ; super . visitClassContext ( classContext ) ; if ( ! hasMapComparator ) { for ( BugInstance bi : mapBugs ) { bugReporter . reportBug ( bi ) ; } } if ( ! hasSetComparator ) { for ( BugInstance bi : setBugs ) { bugReporter . reportBug ( bi ) ; } } } finally { stack = null ; mapBugs = null ; setBugs = null ; } }
|
implement the visitor to report bugs if no Tree comparators were found
|
3,141
|
public void sawOpcode ( int seen ) { try { stack . precomputation ( this ) ; if ( seen == Const . INVOKEINTERFACE ) { processInvokeInterface ( ) ; } else if ( seen == Const . INVOKESPECIAL ) { processInvokeSpecial ( ) ; } } finally { stack . sawOpcode ( this , seen ) ; } }
|
implements the visitor to find accesses to maps sets and lists using arrays
|
3,142
|
public void visitMethod ( final Method obj ) { if ( obj . isSynthetic ( ) ) { return ; } ExceptionTable et = obj . getExceptionTable ( ) ; if ( et != null ) { String [ ] exNames = et . getExceptionNames ( ) ; Set < String > methodRTExceptions = new HashSet < > ( 6 ) ; int priority = LOW_PRIORITY ; boolean foundRuntime = false ; for ( String ex : exNames ) { boolean isRuntime = false ; if ( runtimeExceptions . contains ( ex ) ) { isRuntime = true ; } else { try { JavaClass exClass = Repository . lookupClass ( ex ) ; if ( exClass . instanceOf ( runtimeExceptionClass ) ) { runtimeExceptions . add ( ex ) ; if ( ex . startsWith ( "java.lang." ) ) { priority = NORMAL_PRIORITY ; } isRuntime = true ; } } catch ( ClassNotFoundException cnfe ) { bugReporter . reportMissingClass ( cnfe ) ; } } if ( isRuntime ) { foundRuntime = true ; methodRTExceptions . add ( ex ) ; } } if ( foundRuntime ) { BugInstance bug = new BugInstance ( this , BugType . DRE_DECLARED_RUNTIME_EXCEPTION . name ( ) , priority ) . addClass ( this ) . addMethod ( this ) ; for ( String ex : methodRTExceptions ) { bug . add ( new StringAnnotation ( ex ) ) ; } bugReporter . reportBug ( bug ) ; } } }
|
overrides the visitor to find declared runtime exceptions
|
3,143
|
public static void post ( OpcodeStack stack , int opcode ) { if ( ! sawGOTO || ( opcode == Const . GOTO ) || ( opcode == Const . GOTO_W ) ) { return ; } int depth = stack . getStackDepth ( ) ; for ( int i = 0 ; i < depth && i < userValues . size ( ) ; i ++ ) { OpcodeStack . Item item = stack . getStackItem ( i ) ; if ( item . getUserValue ( ) == null ) { item . setUserValue ( userValues . get ( i ) ) ; } } userValues . clear ( ) ; sawGOTO = false ; }
|
called after the execution of the parent OpcodeStack . sawOpcode to restore the user values after the GOTO or GOTO_W s mergeJumps were processed
|
3,144
|
public void visitCode ( Code obj ) { try { userValues = new HashMap < > ( ) ; super . visitCode ( obj ) ; } finally { userValues = null ; } }
|
implements the visitor to reset the uservalues
|
3,145
|
public void visitClassContext ( ClassContext context ) { try { JavaClass cls = context . getJavaClass ( ) ; if ( ! cls . isEnum ( ) && ( cls . getMajor ( ) >= Const . MAJOR_1_5 ) ) { Method [ ] methods = cls . getMethods ( ) ; for ( Method m : methods ) { if ( Values . CONSTRUCTOR . equals ( m . getName ( ) ) && ! m . isPrivate ( ) ) { return ; } } firstEnumPC = 0 ; enumCount = 0 ; enumConstNames = new HashSet < String > ( 10 ) ; super . visitClassContext ( context ) ; } } finally { enumConstNames = null ; } }
|
implements the visitor to look for classes compiled with 1 . 5 or better that have all constructors that are private
|
3,146
|
public void visitField ( Field obj ) { if ( obj . isStatic ( ) && obj . isPublic ( ) && obj . isFinal ( ) ) { JavaClass cls = getClassContext ( ) . getJavaClass ( ) ; if ( ! obj . isEnum ( ) ) { String fieldClass = obj . getSignature ( ) ; if ( fieldClass . startsWith ( Values . SIG_QUALIFIED_CLASS_PREFIX ) ) { fieldClass = SignatureUtils . trimSignature ( fieldClass ) ; String clsClass = cls . getClassName ( ) ; if ( fieldClass . equals ( clsClass ) ) { enumConstNames . add ( obj . getName ( ) ) ; super . visitField ( obj ) ; } } } } }
|
implements the visitor to look for fields that are public static final and are the same type as the owning class . it collects these object names for later
|
3,147
|
public void visitCode ( Code obj ) { if ( Values . STATIC_INITIALIZER . equals ( getMethod ( ) . getName ( ) ) ) { state = State . SAW_NOTHING ; super . visitCode ( obj ) ; } }
|
implements the visitor to look for static initializers to find enum generation
|
3,148
|
public void sawOpcode ( int seen ) { if ( state == State . SAW_NOTHING ) { if ( seen == Const . INVOKESPECIAL ) { state = State . SAW_INVOKESPECIAL ; } } else if ( state == State . SAW_INVOKESPECIAL ) { handleInvokeSpecialState ( seen ) ; } }
|
implements the visitor to find allocations of TypesafeEnum Const
|
3,149
|
public void visitClassContext ( ClassContext classContext ) { try { JavaClass cls = classContext . getJavaClass ( ) ; constrainingMethods = buildConstrainingMethods ( cls ) ; AnnotationEntry [ ] annotations = cls . getAnnotationEntries ( ) ; classHasAnnotation = ! CollectionUtils . isEmpty ( annotations ) ; stack = new OpcodeStack ( ) ; selfCallTree = new HashMap < > ( ) ; super . visitClassContext ( classContext ) ; performModifyStateClosure ( classContext . getJavaClass ( ) ) ; } finally { stack = null ; selfCallTree = null ; curMethod = null ; constrainingMethods = null ; } }
|
implements the visitor to collect statistics on this class
|
3,150
|
private boolean isFirstUse ( int reg ) { LocalVariableTable lvt = getMethod ( ) . getLocalVariableTable ( ) ; if ( lvt == null ) { return true ; } LocalVariable lv = lvt . getLocalVariable ( reg , getPC ( ) ) ; return lv == null ; }
|
looks to see if this register has already in scope or whether is a new assignment . return true if it s a new assignment . If you can t tell return true anyway . might want to change .
|
3,151
|
public void visitClassContext ( ClassContext clsContext ) { try { JavaClass cls = clsContext . getJavaClass ( ) ; String superName = cls . getSuperclassName ( ) ; if ( ! Values . DOTTED_JAVA_LANG_OBJECT . equals ( superName ) ) { this . classContext = clsContext ; superclassCode = new HashMap < > ( ) ; JavaClass superCls = cls . getSuperClass ( ) ; childPoolGen = new ConstantPoolGen ( cls . getConstantPool ( ) ) ; parentPoolGen = new ConstantPoolGen ( superCls . getConstantPool ( ) ) ; Method [ ] methods = superCls . getMethods ( ) ; for ( Method m : methods ) { String methodName = m . getName ( ) ; if ( m . isPublic ( ) && ! m . isAbstract ( ) && ! m . isSynthetic ( ) && ! Values . CONSTRUCTOR . equals ( methodName ) && ! Values . STATIC_INITIALIZER . equals ( methodName ) ) { String methodInfo = methodName + ':' + m . getSignature ( ) ; superclassCode . put ( methodInfo , new CodeInfo ( m . getCode ( ) , m . getAccessFlags ( ) ) ) ; } } cls . accept ( this ) ; } } catch ( ClassNotFoundException cnfe ) { bugReporter . reportMissingClass ( cnfe ) ; } finally { superclassCode = null ; this . classContext = null ; childPoolGen = null ; parentPoolGen = null ; } }
|
overrides the visitor to accept classes derived from non java . lang . Object classes .
|
3,152
|
public void visitCode ( Code obj ) { try { Method m = getMethod ( ) ; if ( ( ! m . isPublic ( ) && ! m . isProtected ( ) ) || m . isAbstract ( ) || m . isSynthetic ( ) ) { return ; } CodeInfo superCode = superclassCode . remove ( curMethodInfo ) ; if ( superCode != null ) { if ( sameAccess ( getMethod ( ) . getAccessFlags ( ) , superCode . getAccess ( ) ) && codeEquals ( obj , superCode . getCode ( ) ) ) { bugReporter . reportBug ( new BugInstance ( this , BugType . COM_COPIED_OVERRIDDEN_METHOD . name ( ) , NORMAL_PRIORITY ) . addClass ( this ) . addMethod ( this ) . addSourceLine ( classContext , this , getPC ( ) ) ) ; return ; } if ( ( getMethod ( ) . getAccessFlags ( ) & Const . ACC_SYNCHRONIZED ) != ( superCode . getAccess ( ) & Const . ACC_SYNCHRONIZED ) ) { return ; } parmTypes = getMethod ( ) . getArgumentTypes ( ) ; nextParmIndex = 0 ; nextParmOffset = getMethod ( ) . isStatic ( ) ? 0 : 1 ; sawAload0 = nextParmOffset == 0 ; sawParentCall = false ; super . visitCode ( obj ) ; } } catch ( StopOpcodeParsingException e ) { } }
|
overrides the visitor to find code blocks of methods that are the same as its parents
|
3,153
|
public void sawOpcode ( int seen ) { if ( ! sawAload0 ) { if ( seen == Const . ALOAD_0 ) { sawAload0 = true ; } else { throw new StopOpcodeParsingException ( ) ; } } else if ( nextParmIndex < parmTypes . length ) { if ( isExpectedParmInstruction ( seen , nextParmOffset , parmTypes [ nextParmIndex ] ) ) { nextParmOffset += SignatureUtils . getSignatureSize ( parmTypes [ nextParmIndex ] . getSignature ( ) ) ; nextParmIndex ++ ; } else { throw new StopOpcodeParsingException ( ) ; } } else if ( ! sawParentCall ) { if ( ( seen == Const . INVOKESPECIAL ) && getNameConstantOperand ( ) . equals ( getMethod ( ) . getName ( ) ) && getSigConstantOperand ( ) . equals ( getMethod ( ) . getSignature ( ) ) ) { sawParentCall = true ; } else { throw new StopOpcodeParsingException ( ) ; } } else { int expectedInstruction = getExpectedReturnInstruction ( getMethod ( ) . getReturnType ( ) ) ; if ( ( seen == expectedInstruction ) && ( getNextPC ( ) == getCode ( ) . getCode ( ) . length ) ) { bugReporter . reportBug ( new BugInstance ( this , BugType . COM_PARENT_DELEGATED_CALL . name ( ) , NORMAL_PRIORITY ) . addClass ( this ) . addMethod ( this ) . addSourceLine ( this ) ) ; } else { throw new StopOpcodeParsingException ( ) ; } } }
|
overrides the visitor to look for an exact call to the parent class s method using this methods parm .
|
3,154
|
private static boolean sameAccess ( int parentAccess , int childAccess ) { return ( ( parentAccess & ( Const . ACC_PUBLIC | Const . ACC_PROTECTED ) ) == ( childAccess & ( Const . ACC_PUBLIC | Const . ACC_PROTECTED ) ) ) ; }
|
determines if two access flags contain the same access modifiers
|
3,155
|
public void visitMethod ( Method obj ) { Code c = obj . getCode ( ) ; if ( c != null ) { byte [ ] opcodes = c . getCode ( ) ; if ( opcodes != null ) { trPCPos = opcodes . length - 1 ; if ( ! obj . getSignature ( ) . endsWith ( Values . SIG_VOID ) ) { trPCPos -= 1 ; } trPCPos -= TAILRECURSIONFUDGE ; possibleTailRecursion = true ; isStatic = obj . isStatic ( ) ; stack . resetForMethodEntry ( this ) ; super . visitMethod ( obj ) ; } } }
|
implements the visitor to figure the pc where the method call must occur depending on whether the method returns a value or not .
|
3,156
|
public void sawOpcode ( int seen ) { try { stack . precomputation ( this ) ; if ( seen == Const . INVOKEVIRTUAL ) { checkForTailRecursion ( ) ; } } finally { stack . sawOpcode ( this , seen ) ; } }
|
implements the visitor to find methods that employ tail recursion
|
3,157
|
public void sawOpcode ( int seen ) { if ( seen == Const . INVOKEVIRTUAL ) { String className = getClassConstantOperand ( ) ; String methodName = getNameConstantOperand ( ) ; String methodSig = getSigConstantOperand ( ) ; FQMethod methodInfo = new FQMethod ( className , methodName , methodSig ) ; if ( oldMethods . contains ( methodInfo ) ) { bugReporter . reportBug ( new BugInstance ( this , BugType . NCMU_NON_COLLECTION_METHOD_USE . name ( ) , NORMAL_PRIORITY ) . addClass ( this ) . addMethod ( this ) . addSourceLine ( this ) ) ; } } }
|
implements the visitor to look for method calls that are one of the old pre - collections1 . 2 set of methods
|
3,158
|
public void visitClassContext ( ClassContext classContext ) { try { stack = new OpcodeStack ( ) ; nodeCreations = new HashMap < > ( ) ; nodeStores = new HashMap < > ( ) ; super . visitClassContext ( classContext ) ; } finally { stack = null ; nodeCreations = null ; nodeStores = null ; } }
|
implements the visitor to create and clear the stack node creations and store maps
|
3,159
|
public void visitCode ( Code obj ) { stack . resetForMethodEntry ( this ) ; nodeCreations . clear ( ) ; nodeStores . clear ( ) ; super . visitCode ( obj ) ; BitSet reportedPCs = new BitSet ( ) ; for ( Integer pc : nodeCreations . values ( ) ) { if ( ! reportedPCs . get ( pc . intValue ( ) ) ) { bugReporter . reportBug ( new BugInstance ( this , BugType . ODN_ORPHANED_DOM_NODE . name ( ) , NORMAL_PRIORITY ) . addClass ( this ) . addMethod ( this ) . addSourceLine ( this , pc . intValue ( ) ) ) ; reportedPCs . set ( pc . intValue ( ) ) ; } } for ( Integer pc : nodeStores . values ( ) ) { if ( ! reportedPCs . get ( pc . intValue ( ) ) ) { bugReporter . reportBug ( new BugInstance ( this , BugType . ODN_ORPHANED_DOM_NODE . name ( ) , NORMAL_PRIORITY ) . addClass ( this ) . addMethod ( this ) . addSourceLine ( this , pc . intValue ( ) ) ) ; reportedPCs . set ( pc . intValue ( ) ) ; } } }
|
implements the visitor to clear the opcode stack for the next code
|
3,160
|
private Integer findDOMNodeCreationPoint ( int index ) { if ( stack . getStackDepth ( ) <= index ) { return null ; } return nodeCreations . remove ( stack . getStackItem ( index ) ) ; }
|
returns the pc where this DOM Node was created or null if this isn t a DOM node that was created
|
3,161
|
public void visitClassContext ( ClassContext classContext ) { try { JavaClass cls = classContext . getJavaClass ( ) ; if ( cls . isAbstract ( ) ) { interfaceMethods = collectInterfaceMethods ( cls ) ; super . visitClassContext ( classContext ) ; } } catch ( ClassNotFoundException cnfe ) { bugReporter . reportMissingClass ( cnfe ) ; } finally { interfaceMethods = null ; } }
|
overrides the visitor to check for abstract classes .
|
3,162
|
public void visitCode ( Code obj ) { if ( Values . CONSTRUCTOR . equals ( methodName ) || Values . STATIC_INITIALIZER . equals ( methodName ) ) { return ; } Method m = getMethod ( ) ; if ( m . isSynthetic ( ) ) { return ; } if ( ! interfaceMethods . contains ( new QMethod ( methodName , m . getSignature ( ) ) ) ) { super . visitCode ( obj ) ; } }
|
overrides the visitor to filter out constructors .
|
3,163
|
public void sawOpcode ( int seen ) { try { switch ( state ) { case SAW_NOTHING : if ( seen == Const . RETURN ) { bugReporter . reportBug ( new BugInstance ( this , BugType . ACEM_ABSTRACT_CLASS_EMPTY_METHODS . name ( ) , NORMAL_PRIORITY ) . addClass ( this ) . addMethod ( this ) . addSourceLine ( this ) ) ; state = State . SAW_DONE ; } else if ( seen == Const . NEW ) { String newClass = getClassConstantOperand ( ) ; JavaClass exCls = Repository . lookupClass ( newClass ) ; if ( ( exceptionClass != null ) && exCls . instanceOf ( exceptionClass ) ) { state = State . SAW_NEW ; } else { state = State . SAW_DONE ; } } else { state = State . SAW_DONE ; } break ; case SAW_NEW : if ( seen == Const . DUP ) { state = State . SAW_DUP ; } else { state = State . SAW_DONE ; } break ; case SAW_DUP : if ( ( ( seen == Const . LDC ) || ( seen == Const . LDC_W ) ) && ( getConstantRefOperand ( ) instanceof ConstantString ) ) { state = State . SAW_LDC ; } else { state = State . SAW_DONE ; } break ; case SAW_LDC : if ( ( seen == Const . INVOKESPECIAL ) && Values . CONSTRUCTOR . equals ( getNameConstantOperand ( ) ) ) { state = State . SAW_INVOKESPECIAL ; } else { state = State . SAW_DONE ; } break ; case SAW_INVOKESPECIAL : if ( seen == Const . ATHROW ) { bugReporter . reportBug ( new BugInstance ( this , BugType . ACEM_ABSTRACT_CLASS_EMPTY_METHODS . name ( ) , NORMAL_PRIORITY ) . addClass ( this ) . addMethod ( this ) . addSourceLine ( this ) ) ; } state = State . SAW_DONE ; break ; case SAW_DONE : break ; } } catch ( ClassNotFoundException cnfe ) { bugReporter . reportMissingClass ( cnfe ) ; state = State . SAW_DONE ; } }
|
overrides the visitor to look for empty methods or simple exception throwers .
|
3,164
|
private boolean prescreen ( Method method ) { BitSet bytecodeSet = getClassContext ( ) . getBytecodeSet ( method ) ; return ( bytecodeSet != null ) && bytecodeSet . intersects ( arrayLoadOps ) ; }
|
looks for methods that contain array load opcodes
|
3,165
|
private static boolean similarArrayInstructions ( int load , int store ) { return ( ( load == Const . AALOAD ) && ( store == Const . AASTORE ) ) || ( ( load == Const . IALOAD ) && ( store == Const . IASTORE ) ) || ( ( load == Const . DALOAD ) && ( store == Const . DASTORE ) ) || ( ( load == Const . LALOAD ) && ( store == Const . LASTORE ) ) || ( ( load == Const . FALOAD ) && ( store == Const . FASTORE ) ) || ( ( load == Const . BALOAD ) && ( store == Const . BASTORE ) ) || ( ( load == Const . CALOAD ) && ( store == Const . CASTORE ) ) || ( ( load == Const . SALOAD ) && ( store == Const . SASTORE ) ) ; }
|
looks to see if a load and store operation are working on the same type of array
|
3,166
|
public void visitCode ( Code obj ) { try { possibleParmRegs . clear ( ) ; Method m = getMethod ( ) ; String methodSignature = m . getSignature ( ) ; String retSignature = SignatureUtils . getReturnSignature ( methodSignature ) ; JavaClass returnClass = null ; int [ ] parmRegs = null ; if ( retSignature . startsWith ( Values . SIG_QUALIFIED_CLASS_PREFIX ) && ! knownImmutables . contains ( retSignature ) ) { List < String > parmTypes = SignatureUtils . getParameterSignatures ( methodSignature ) ; for ( int p = 0 ; p < parmTypes . size ( ) ; p ++ ) { String parmSignature = parmTypes . get ( p ) ; if ( parmSignature . startsWith ( Values . SIG_QUALIFIED_CLASS_PREFIX ) && ! knownImmutables . contains ( parmSignature ) ) { if ( returnClass == null ) { returnClass = Repository . lookupClass ( SignatureUtils . trimSignature ( retSignature ) ) ; parmRegs = RegisterUtils . getParameterRegisters ( m ) ; } if ( parmRegs != null ) { JavaClass parmClass = Repository . lookupClass ( SignatureUtils . stripSignature ( parmSignature ) ) ; if ( parmClass . instanceOf ( returnClass ) ) { possibleParmRegs . put ( Integer . valueOf ( parmRegs [ p ] ) , new ParmUsage ( ) ) ; } } } } if ( ! possibleParmRegs . isEmpty ( ) ) { try { stack . resetForMethodEntry ( this ) ; super . visitCode ( obj ) ; for ( ParmUsage pu : possibleParmRegs . values ( ) ) { if ( ( pu . returnPC >= 0 ) && ( pu . alteredPC >= 0 ) && ( pu . returnPC > pu . alteredPC ) ) { bugReporter . reportBug ( new BugInstance ( this , BugType . CFS_CONFUSING_FUNCTION_SEMANTICS . name ( ) , NORMAL_PRIORITY ) . addClass ( this ) . addMethod ( this ) . addSourceLine ( this , pu . returnPC ) . addSourceLine ( this , pu . alteredPC ) ) ; } } } catch ( StopOpcodeParsingException e ) { } } } } catch ( ClassNotFoundException cnfe ) { bugReporter . reportMissingClass ( cnfe ) ; } }
|
implements the visitor to look for any non - immutable typed parameters are assignable to the return type . If found the method is parsed .
|
3,167
|
public static boolean isListSetMap ( String clsName ) throws ClassNotFoundException { JavaClass cls = Repository . lookupClass ( clsName ) ; return ( cls . implementationOf ( LIST_CLASS ) || cls . implementationOf ( SET_CLASS ) || cls . implementationOf ( MAP_CLASS ) ) ; }
|
determines if the current class name is derived from List Set or Map
|
3,168
|
private boolean prescreen ( Method method ) { BitSet bytecodeSet = getClassContext ( ) . getBytecodeSet ( method ) ; return ( bytecodeSet != null ) && ( bytecodeSet . get ( Const . CHECKCAST ) ) ; }
|
looks for methods that contain a checkcast instruction
|
3,169
|
public void sawOpcode ( int seen ) { try { stack . precomputation ( this ) ; if ( ( seen == Const . CHECKCAST ) && ( stack . getStackDepth ( ) > 0 ) ) { OpcodeStack . Item item = stack . getStackItem ( 0 ) ; if ( item . getRegisterNumber ( ) == 1 ) { String thisCls = getClassName ( ) ; String equalsCls = getClassConstantOperand ( ) ; if ( ! thisCls . equals ( equalsCls ) ) { JavaClass thisJavaClass = getClassContext ( ) . getJavaClass ( ) ; JavaClass equalsJavaClass = Repository . lookupClass ( equalsCls ) ; boolean inheritance = thisJavaClass . instanceOf ( equalsJavaClass ) || equalsJavaClass . instanceOf ( thisJavaClass ) ; BugInstance bug = new BugInstance ( this , BugType . NSE_NON_SYMMETRIC_EQUALS . name ( ) , inheritance ? LOW_PRIORITY : NORMAL_PRIORITY ) . addClass ( this ) . addMethod ( this ) . addSourceLine ( this ) . addString ( equalsCls ) ; Map < String , BugInstance > bugs = possibleBugs . get ( thisCls ) ; if ( bugs == null ) { bugs = new HashMap < > ( ) ; possibleBugs . put ( thisCls , bugs ) ; } bugs . put ( equalsCls , bug ) ; } } } } catch ( ClassNotFoundException cnfe ) { bugReporter . reportMissingClass ( cnfe ) ; } finally { stack . sawOpcode ( this , seen ) ; } }
|
implements the visitor to look for checkcasts of the parameter to other types and enter instances in a map for further processing in doReport .
|
3,170
|
public void report ( ) { for ( Map . Entry < String , Map < String , BugInstance > > thisEntry : possibleBugs . entrySet ( ) ) { Map < String , BugInstance > equalsClassesMap = thisEntry . getValue ( ) ; for ( Map . Entry < String , BugInstance > equalsEntry : equalsClassesMap . entrySet ( ) ) { String equalsCls = equalsEntry . getKey ( ) ; Map < String , BugInstance > reverseEqualsClassMap = possibleBugs . get ( equalsCls ) ; if ( reverseEqualsClassMap == null ) { bugReporter . reportBug ( equalsClassesMap . values ( ) . iterator ( ) . next ( ) ) ; break ; } if ( ! reverseEqualsClassMap . containsKey ( thisEntry . getKey ( ) ) ) { bugReporter . reportBug ( equalsClassesMap . values ( ) . iterator ( ) . next ( ) ) ; break ; } } } possibleBugs . clear ( ) ; }
|
reports all the collected issues from the parse of this class
|
3,171
|
public void visitClassContext ( ClassContext classContext ) { try { ignoreRegs = new BitSet ( ) ; tryBlocks = new BitSet ( ) ; catchHandlers = new BitSet ( ) ; switchTargets = new BitSet ( ) ; monitorSyncPCs = new ArrayList < > ( 5 ) ; stack = new OpcodeStack ( ) ; super . visitClassContext ( classContext ) ; } finally { ignoreRegs = null ; tryBlocks = null ; catchHandlers = null ; switchTargets = null ; monitorSyncPCs = null ; stack = null ; } }
|
implements the visitor to create and the clear the register to location map
|
3,172
|
public void visitCode ( Code obj ) { try { ignoreRegs . clear ( ) ; Method method = getMethod ( ) ; if ( ! method . isStatic ( ) ) { ignoreRegs . set ( 0 ) ; } int [ ] parmRegs = RegisterUtils . getParameterRegisters ( method ) ; for ( int parm : parmRegs ) { ignoreRegs . set ( parm ) ; } rootScopeBlock = new ScopeBlock ( 0 , obj . getLength ( ) ) ; tryBlocks . clear ( ) ; catchHandlers . clear ( ) ; CodeException [ ] exceptions = obj . getExceptionTable ( ) ; if ( exceptions != null ) { for ( CodeException ex : exceptions ) { tryBlocks . set ( ex . getStartPC ( ) ) ; catchHandlers . set ( ex . getHandlerPC ( ) ) ; } } switchTargets . clear ( ) ; stack . resetForMethodEntry ( this ) ; dontReport = false ; sawDup = false ; sawNull = false ; super . visitCode ( obj ) ; if ( ! dontReport ) { rootScopeBlock . findBugs ( new HashSet < Integer > ( ) ) ; } } finally { rootScopeBlock = null ; } }
|
implements the visitor to reset the register to location map
|
3,173
|
public void sawOpcode ( int seen ) { UserObject uo = null ; try { stack . precomputation ( this ) ; int pc = getPC ( ) ; if ( tryBlocks . get ( pc ) ) { ScopeBlock sb = new ScopeBlock ( pc , findCatchHandlerFor ( pc ) ) ; sb . setTry ( ) ; rootScopeBlock . addChild ( sb ) ; } if ( OpcodeUtils . isStore ( seen ) ) { sawStore ( seen , pc ) ; } else if ( OpcodeUtils . isLoad ( seen ) ) { sawLoad ( seen , pc ) ; } else if ( ( seen == Const . INVOKEVIRTUAL ) || ( seen == Const . INVOKEINTERFACE ) ) { uo = sawInstanceCall ( pc ) ; } else if ( ( seen == Const . INVOKESTATIC ) || ( seen == Const . INVOKESPECIAL ) ) { uo = sawStaticCall ( ) ; } else if ( ( ( seen >= Const . IFEQ ) && ( seen <= Const . GOTO ) ) || ( seen == Const . IFNULL ) || ( seen == Const . IFNONNULL ) || ( seen == Const . GOTO_W ) ) { sawBranch ( seen , pc ) ; } else if ( seen == Const . GETFIELD ) { uo = sawGetField ( ) ; } else if ( seen == Const . PUTFIELD ) { sawPutField ( pc ) ; } else if ( seen == Const . IINC ) { sawIINC ( pc ) ; } else if ( ( seen == Const . TABLESWITCH ) || ( seen == Const . LOOKUPSWITCH ) ) { sawSwitch ( pc ) ; } else if ( seen == Const . MONITORENTER ) { sawMonitorEnter ( pc ) ; } else if ( seen == Const . MONITOREXIT ) { sawMonitorExit ( pc ) ; } sawDup = seen == Const . DUP ; sawNull = seen == Const . ACONST_NULL ; } finally { TernaryPatcher . pre ( stack , seen ) ; stack . sawOpcode ( this , seen ) ; TernaryPatcher . post ( stack , seen ) ; if ( ( uo != null ) && ( stack . getStackDepth ( ) > 0 ) ) { OpcodeStack . Item item = stack . getStackItem ( 0 ) ; item . setUserValue ( uo ) ; } } }
|
implements the visitor to look for variables assigned below the scope in which they are used .
|
3,174
|
private void sawStore ( int seen , int pc ) { int reg = RegisterUtils . getStoreReg ( this , seen ) ; if ( catchHandlers . get ( pc ) ) { ignoreRegs . set ( reg ) ; ScopeBlock catchSB = findScopeBlock ( rootScopeBlock , pc + 1 ) ; if ( ( catchSB != null ) && ( catchSB . getStart ( ) < pc ) ) { ScopeBlock sb = new ScopeBlock ( pc , catchSB . getFinish ( ) ) ; catchSB . setFinish ( getPC ( ) - 1 ) ; rootScopeBlock . addChild ( sb ) ; } } else if ( ! monitorSyncPCs . isEmpty ( ) ) { ignoreRegs . set ( reg ) ; } else if ( sawNull ) { ignoreRegs . set ( reg ) ; } else if ( isRiskyStoreClass ( reg ) ) { ignoreRegs . set ( reg ) ; } if ( ! ignoreRegs . get ( reg ) ) { ScopeBlock sb = findScopeBlock ( rootScopeBlock , pc ) ; if ( sb != null ) { UserObject assoc = null ; if ( stack . getStackDepth ( ) > 0 ) { OpcodeStack . Item srcItm = stack . getStackItem ( 0 ) ; assoc = ( UserObject ) srcItm . getUserValue ( ) ; if ( assoc == null ) { if ( srcItm . getRegisterNumber ( ) >= 0 ) { assoc = new UserObject ( srcItm . getRegisterNumber ( ) ) ; } } } if ( ( assoc != null ) && assoc . isRisky ) { ignoreRegs . set ( reg ) ; } else { sb . addStore ( reg , pc , assoc ) ; if ( sawDup ) { sb . addLoad ( reg , pc ) ; } } } else { ignoreRegs . set ( reg ) ; } } ScopeBlock sb = findScopeBlock ( rootScopeBlock , pc ) ; if ( sb != null ) { sb . markFieldAssociatedWrites ( reg ) ; } }
|
processes a register store by updating the appropriate scope block to mark this register as being stored in the block
|
3,175
|
private void sawIINC ( int pc ) { int reg = getRegisterOperand ( ) ; if ( ! ignoreRegs . get ( reg ) ) { ScopeBlock sb = findScopeBlock ( rootScopeBlock , pc ) ; if ( sb != null ) { sb . addLoad ( reg , pc ) ; } else { ignoreRegs . set ( reg ) ; } } if ( catchHandlers . get ( pc ) ) { ignoreRegs . set ( reg ) ; } else if ( ! monitorSyncPCs . isEmpty ( ) ) { ignoreRegs . set ( reg ) ; } else if ( sawNull ) { ignoreRegs . set ( reg ) ; } if ( ! ignoreRegs . get ( reg ) ) { ScopeBlock sb = findScopeBlock ( rootScopeBlock , pc ) ; if ( sb != null ) { sb . addStore ( reg , pc , null ) ; if ( sawDup ) { sb . addLoad ( reg , pc ) ; } } else { ignoreRegs . set ( reg ) ; } } }
|
processes a register IINC by updating the appropriate scope block to mark this register as being stored in the block
|
3,176
|
private void sawLoad ( int seen , int pc ) { int reg = RegisterUtils . getLoadReg ( this , seen ) ; if ( ! ignoreRegs . get ( reg ) ) { ScopeBlock sb = findScopeBlock ( rootScopeBlock , pc ) ; if ( sb != null ) { sb . addLoad ( reg , pc ) ; } else { ignoreRegs . set ( reg ) ; } } }
|
processes a register store by updating the appropriate scope block to mark this register as being read in the block
|
3,177
|
private void sawBranch ( int seen , int pc ) { int target = getBranchTarget ( ) ; if ( target > pc ) { if ( ( seen == Const . GOTO ) || ( seen == Const . GOTO_W ) ) { int nextPC = getNextPC ( ) ; if ( ! switchTargets . get ( nextPC ) ) { ScopeBlock sb = findScopeBlockWithTarget ( rootScopeBlock , pc , nextPC ) ; if ( sb == null ) { sb = new ScopeBlock ( pc , target ) ; sb . setLoop ( ) ; sb . setGoto ( ) ; rootScopeBlock . addChild ( sb ) ; } else { sb = new ScopeBlock ( nextPC , target ) ; sb . setGoto ( ) ; rootScopeBlock . addChild ( sb ) ; } } } else { ScopeBlock sb = findScopeBlockWithTarget ( rootScopeBlock , pc , target ) ; if ( ( sb != null ) && ! sb . isLoop ( ) && ! sb . isCase ( ) && ! sb . hasChildren ( ) ) { if ( sb . isGoto ( ) ) { ScopeBlock parent = sb . getParent ( ) ; sb . pushUpLoadStores ( ) ; if ( parent != null ) { parent . removeChild ( sb ) ; } sb = new ScopeBlock ( pc , target ) ; rootScopeBlock . addChild ( sb ) ; } else { sb . pushUpLoadStores ( ) ; sb . setStart ( pc ) ; } } else { sb = new ScopeBlock ( pc , target ) ; rootScopeBlock . addChild ( sb ) ; } } } else { ScopeBlock sb = findScopeBlock ( rootScopeBlock , pc ) ; if ( sb != null ) { ScopeBlock parentSB = sb . getParent ( ) ; while ( parentSB != null ) { if ( parentSB . getStart ( ) >= target ) { sb = parentSB ; parentSB = parentSB . getParent ( ) ; } else { break ; } } if ( sb . getStart ( ) > target ) { ScopeBlock previous = findPreviousSiblingScopeBlock ( sb ) ; if ( ( previous != null ) && ( previous . getStart ( ) >= target ) ) { sb = previous ; } } sb . setLoop ( ) ; } } }
|
creates a scope block to describe this branch location .
|
3,178
|
private void sawSwitch ( int pc ) { int [ ] offsets = getSwitchOffsets ( ) ; List < Integer > targets = new ArrayList < > ( offsets . length ) ; for ( int offset : offsets ) { targets . add ( Integer . valueOf ( offset + pc ) ) ; } Integer defOffset = Integer . valueOf ( getDefaultSwitchOffset ( ) + pc ) ; if ( ! targets . contains ( defOffset ) ) { targets . add ( defOffset ) ; } Collections . sort ( targets ) ; Integer lastTarget = targets . get ( 0 ) ; for ( int i = 1 ; i < targets . size ( ) ; i ++ ) { Integer nextTarget = targets . get ( i ) ; ScopeBlock sb = new ScopeBlock ( lastTarget . intValue ( ) , nextTarget . intValue ( ) ) ; sb . setCase ( ) ; rootScopeBlock . addChild ( sb ) ; lastTarget = nextTarget ; } for ( Integer target : targets ) { switchTargets . set ( target . intValue ( ) ) ; } }
|
creates a new scope block for each case statement
|
3,179
|
private UserObject sawStaticCall ( ) { if ( getSigConstantOperand ( ) . endsWith ( Values . SIG_VOID ) ) { return null ; } return new UserObject ( isRiskyMethodCall ( ) ) ; }
|
processes a static call or initializer by checking to see if the call is risky and returning a OpcodeStack item user value saying so .
|
3,180
|
private void sawMonitorEnter ( int pc ) { monitorSyncPCs . add ( Integer . valueOf ( pc ) ) ; ScopeBlock sb = new ScopeBlock ( pc , Integer . MAX_VALUE ) ; sb . setSync ( ) ; rootScopeBlock . addChild ( sb ) ; }
|
processes a monitor enter call to create a scope block
|
3,181
|
private void sawMonitorExit ( int pc ) { if ( ! monitorSyncPCs . isEmpty ( ) ) { ScopeBlock sb = findSynchronizedScopeBlock ( rootScopeBlock , monitorSyncPCs . get ( 0 ) . intValue ( ) ) ; if ( sb != null ) { sb . setFinish ( pc ) ; } monitorSyncPCs . remove ( monitorSyncPCs . size ( ) - 1 ) ; } }
|
processes a monitor exit to set the end of the already created scope block
|
3,182
|
private Comparable < ? > getCallingObject ( ) { String sig = getSigConstantOperand ( ) ; if ( Values . SIG_VOID . equals ( SignatureUtils . getReturnSignature ( sig ) ) ) { return null ; } int numParameters = SignatureUtils . getNumParameters ( sig ) ; if ( stack . getStackDepth ( ) <= numParameters ) { return null ; } OpcodeStack . Item caller = stack . getStackItem ( numParameters ) ; UserObject uo = ( UserObject ) caller . getUserValue ( ) ; if ( ( uo != null ) && ( uo . caller != null ) ) { return uo . caller ; } int reg = caller . getRegisterNumber ( ) ; if ( reg >= 0 ) { return Integer . valueOf ( reg ) ; } XField f = caller . getXField ( ) ; if ( f != null ) { return f . getName ( ) ; } return null ; }
|
returns either a register number of a field reference of the object that a method is being called on or null if it can t be determined .
|
3,183
|
private ScopeBlock findScopeBlock ( ScopeBlock sb , int pc ) { if ( ( pc <= sb . getStart ( ) ) || ( pc >= sb . getFinish ( ) ) ) { return null ; } List < ScopeBlock > children = sb . getChildren ( ) ; if ( children != null ) { for ( ScopeBlock child : children ) { ScopeBlock foundSb = findScopeBlock ( child , pc ) ; if ( foundSb != null ) { return foundSb ; } } } return sb ; }
|
returns the scope block in which this register was assigned by traversing the scope block tree
|
3,184
|
private ScopeBlock findScopeBlockWithTarget ( ScopeBlock sb , int start , int target ) { ScopeBlock parentBlock = null ; int finishLocation = sb . getFinish ( ) ; if ( ( sb . getStart ( ) < start ) && ( finishLocation >= start ) && ( ( finishLocation <= target ) || ( sb . isGoto ( ) && ! sb . isLoop ( ) ) ) ) { parentBlock = sb ; } List < ScopeBlock > children = sb . getChildren ( ) ; if ( children != null ) { for ( ScopeBlock child : children ) { ScopeBlock targetBlock = findScopeBlockWithTarget ( child , start , target ) ; if ( targetBlock != null ) { return targetBlock ; } } } return parentBlock ; }
|
returns an existing scope block that has the same target as the one looked for
|
3,185
|
private ScopeBlock findPreviousSiblingScopeBlock ( ScopeBlock sb ) { ScopeBlock parent = sb . getParent ( ) ; if ( parent == null ) { return null ; } List < ScopeBlock > children = parent . getChildren ( ) ; if ( children == null ) { return null ; } ScopeBlock lastSibling = null ; for ( ScopeBlock sibling : children ) { if ( sibling . equals ( sb ) ) { return lastSibling ; } lastSibling = sibling ; } return null ; }
|
looks for the ScopeBlock has the same parent as this given one but precedes it in the list .
|
3,186
|
private ScopeBlock findSynchronizedScopeBlock ( ScopeBlock sb , int monitorEnterPC ) { ScopeBlock monitorBlock = sb ; if ( sb . hasChildren ( ) ) { for ( ScopeBlock child : sb . getChildren ( ) ) { if ( child . isSync ( ) && ( child . getStart ( ) > monitorBlock . getStart ( ) ) ) { monitorBlock = child ; monitorBlock = findSynchronizedScopeBlock ( monitorBlock , monitorEnterPC ) ; } } } return monitorBlock ; }
|
finds the scope block that is the active synchronized block
|
3,187
|
private int findCatchHandlerFor ( int pc ) { CodeException [ ] exceptions = getMethod ( ) . getCode ( ) . getExceptionTable ( ) ; if ( exceptions != null ) { for ( CodeException ex : exceptions ) { if ( ex . getStartPC ( ) == pc ) { return ex . getHandlerPC ( ) ; } } } return - 1 ; }
|
returns the catch handler for a given try block
|
3,188
|
public void visitClassContext ( ClassContext classContext ) { if ( cloneableClass == null ) { return ; } try { JavaClass cls = classContext . getJavaClass ( ) ; if ( cls . implementationOf ( cloneableClass ) ) { stack = new OpcodeStack ( ) ; super . visitClassContext ( classContext ) ; } } catch ( ClassNotFoundException cnfe ) { bugReporter . reportMissingClass ( cnfe ) ; } finally { stack = null ; } }
|
override the visitor to look for classes that implement Cloneable
|
3,189
|
public void visitCode ( Code obj ) { Method m = getMethod ( ) ; if ( ! m . isStatic ( ) && "clone" . equals ( m . getName ( ) ) && SIG_VOID_TO_OBJECT . equals ( m . getSignature ( ) ) ) { super . visitCode ( obj ) ; } }
|
override the visitor to only continue for the clone method
|
3,190
|
public void sawOpcode ( int seen ) { boolean srcField = false ; try { stack . precomputation ( this ) ; switch ( seen ) { case Const . ALOAD_0 : srcField = true ; break ; case Const . DUP : if ( stack . getStackDepth ( ) > 0 ) { OpcodeStack . Item item = stack . getStackItem ( 0 ) ; if ( item . getUserValue ( ) != null ) { srcField = true ; } } break ; case Const . GETFIELD : if ( stack . getStackDepth ( ) > 0 ) { OpcodeStack . Item item = stack . getStackItem ( 0 ) ; if ( item . getRegisterNumber ( ) == 0 ) { srcField = true ; } } break ; case Const . PUTFIELD : if ( stack . getStackDepth ( ) >= 2 ) { OpcodeStack . Item item = stack . getStackItem ( 1 ) ; if ( ( item . getRegisterNumber ( ) == 0 ) || ( item . getUserValue ( ) != null ) ) { bugReporter . reportBug ( new BugInstance ( this , BugType . SCA_SUSPICIOUS_CLONE_ALGORITHM . name ( ) , NORMAL_PRIORITY ) . addClass ( this ) . addMethod ( this ) . addSourceLine ( this ) ) ; } } break ; case Const . INVOKEINTERFACE : case Const . INVOKEVIRTUAL : String sig = getSigConstantOperand ( ) ; int numArgs = SignatureUtils . getNumParameters ( sig ) ; if ( stack . getStackDepth ( ) > numArgs ) { OpcodeStack . Item item = stack . getStackItem ( numArgs ) ; if ( ( item . getRegisterNumber ( ) == 0 ) || ( item . getUserValue ( ) != null ) ) { String name = getNameConstantOperand ( ) ; Integer priority = changingMethods . get ( name ) ; if ( priority != null ) { bugReporter . reportBug ( new BugInstance ( this , BugType . SCA_SUSPICIOUS_CLONE_ALGORITHM . name ( ) , priority . intValue ( ) ) . addClass ( this ) . addMethod ( this ) . addSourceLine ( this ) ) ; } } } break ; default : break ; } } finally { TernaryPatcher . pre ( stack , seen ) ; stack . sawOpcode ( this , seen ) ; TernaryPatcher . post ( stack , seen ) ; if ( srcField && ( stack . getStackDepth ( ) > 0 ) ) { OpcodeStack . Item item = stack . getStackItem ( 0 ) ; item . setUserValue ( Boolean . TRUE ) ; } } }
|
override the visitor to look for stores to member fields of the source object on a clone
|
3,191
|
public void visitClassContext ( ClassContext classContext ) { try { queryLocations = new ArrayList < > ( ) ; loops = new ArrayList < > ( ) ; super . visitClassContext ( classContext ) ; } finally { queryLocations = null ; loops = null ; } }
|
implements the visitor to create and clear the query locations and loops collections
|
3,192
|
public void visitCode ( Code obj ) { queryLocations . clear ( ) ; loops . clear ( ) ; super . visitCode ( obj ) ; for ( Integer qLoc : queryLocations ) { for ( LoopLocation lLoc : loops ) { if ( lLoc . isInLoop ( qLoc . intValue ( ) ) ) { bugReporter . reportBug ( new BugInstance ( this , BugType . SIL_SQL_IN_LOOP . name ( ) , NORMAL_PRIORITY ) . addClass ( this ) . addMethod ( this ) . addSourceLine ( this , qLoc . intValue ( ) ) ) ; break ; } } } }
|
implements the visitor to clear the collections and report the query locations that are in loops
|
3,193
|
public void sawOpcode ( int seen ) { if ( seen == Const . INVOKEINTERFACE ) { String clsName = getClassConstantOperand ( ) ; String methodName = getNameConstantOperand ( ) ; if ( queryClasses . contains ( clsName ) && queryMethods . contains ( methodName ) ) { queryLocations . add ( Integer . valueOf ( getPC ( ) ) ) ; } } else if ( OpcodeUtils . isBranch ( seen ) ) { int branchTarget = getBranchTarget ( ) ; int pc = getPC ( ) ; if ( branchTarget < pc ) { loops . add ( new LoopLocation ( branchTarget , pc ) ) ; } } }
|
implements the visitor to collect positions of queries and loops
|
3,194
|
public void visitCode ( Code obj ) { Method m = getMethod ( ) ; if ( prescreen ( m ) ) { stack . resetForMethodEntry ( this ) ; popStack . clear ( ) ; super . visitCode ( obj ) ; } }
|
implement the visitor to reset the stack
|
3,195
|
private void processMethodCall ( ) { int numParams = SignatureUtils . getNumParameters ( getSigConstantOperand ( ) ) ; int depth = stack . getStackDepth ( ) ; for ( int i = 0 ; i < numParams ; i ++ ) { if ( depth > i ) { OpcodeStack . Item item = stack . getStackItem ( i ) ; XField xf = item . getXField ( ) ; if ( xf != null ) { removeField ( item ) ; } } else { return ; } } }
|
parses all the parameters of a called method and removes any of the parameters that are maps currently being looked at for this detector
|
3,196
|
public void visitCode ( Code obj ) { state = State . SAW_NOTHING ; lvt = obj . getLocalVariableTable ( ) ; if ( ( lvt != null ) && prescreen ( getMethod ( ) ) ) { super . visitCode ( obj ) ; } }
|
implements the visitor to set the state on entry of the code block to SAW_NOTHING and to see if there is a local variable table
|
3,197
|
public void sawOpcode ( int seen ) { switch ( state ) { case SAW_NOTHING : if ( seen == Const . CHECKCAST ) { castClass = getClassConstantOperand ( ) ; state = State . SAW_CHECKCAST ; } else if ( seen == Const . INVOKEINTERFACE ) { String clsName = getClassConstantOperand ( ) ; String methodName = getNameConstantOperand ( ) ; if ( "java/util/Iterator" . equals ( clsName ) && "next" . equals ( methodName ) ) { state = State . SAW_NEXT ; } } break ; case SAW_CHECKCAST : if ( OpcodeUtils . isAStore ( seen ) ) { int reg = RegisterUtils . getAStoreReg ( this , seen ) ; LocalVariable lv = lvt . getLocalVariable ( reg , getNextPC ( ) ) ; if ( lv != null ) { String sig = lv . getSignature ( ) ; if ( sig . startsWith ( Values . SIG_QUALIFIED_CLASS_PREFIX ) ) { sig = SignatureUtils . trimSignature ( sig ) ; } if ( ! sig . equals ( castClass ) ) { bugReporter . reportBug ( new BugInstance ( this , BugType . OC_OVERZEALOUS_CASTING . name ( ) , NORMAL_PRIORITY ) . addClass ( this ) . addMethod ( this ) . addSourceLine ( this ) ) ; } } } else if ( seen == Const . PUTFIELD ) { FieldAnnotation f = FieldAnnotation . fromReferencedField ( this ) ; String sig = f . getFieldSignature ( ) ; if ( sig . startsWith ( Values . SIG_QUALIFIED_CLASS_PREFIX ) ) { sig = SignatureUtils . trimSignature ( sig ) ; } if ( ! Values . SLASHED_JAVA_LANG_OBJECT . equals ( sig ) && ! sig . equals ( castClass ) ) { bugReporter . reportBug ( new BugInstance ( this , BugType . OC_OVERZEALOUS_CASTING . name ( ) , NORMAL_PRIORITY ) . addClass ( this ) . addMethod ( this ) . addSourceLine ( this ) ) ; } } state = State . SAW_NOTHING ; break ; case SAW_NEXT : default : state = State . SAW_NOTHING ; break ; } }
|
implements the visitor to look for a checkcast followed by a astore where the types of the objects are different .
|
3,198
|
public static void clearAssumptions ( Map < Integer , Integer > assumptionTill , int pc ) { Iterator < Integer > it = assumptionTill . values ( ) . iterator ( ) ; while ( it . hasNext ( ) ) { if ( it . next ( ) . intValue ( ) <= pc ) { it . remove ( ) ; } } }
|
the map is keyed by register and value by when an assumption holds to a byte offset if we have passed when the assumption holds clear the item from the map
|
3,199
|
public void clearBranchTargets ( int pc ) { Iterator < Integer > it = branchTargets . iterator ( ) ; while ( it . hasNext ( ) ) { int target = it . next ( ) . intValue ( ) ; if ( target <= pc ) { it . remove ( ) ; } } }
|
remove branch targets that have been passed
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.