idx
int64
0
165k
question
stringlengths
73
5.81k
target
stringlengths
5
918
126,800
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...
returns an array of catch types that the current pc is in
126,801
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 = findM...
finds the super class or interface that constrains the types of exceptions that can be thrown from the given method
126,802
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
126,803
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 [ ] indexTa...
returns exception names describing what exceptions are allowed to be thrown
126,804
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
126,805
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_PATTE...
implements the visitor to look for null returns
126,806
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 .
126,807
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" . equal...
implements the visitor look for adds to sets or puts to maps where the element to be added is a collection .
126,808
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 . ge...
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 .
126,809
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 ( ) ;...
implement the visitor to reset the opcode stack and set of locals that are jdbc objects
126,810
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 .
126,811
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 ( ...
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
126,812
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
126,813
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 ( ) ) {...
implements the visitor to set up the stack and methodToCalledmethods map reports calls to public non final methods from methods called from constructors .
126,814
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
126,815
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_SUPPO...
implements the visitor to report on attributes that have changed without a setAttribute being called on them
126,816
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 ( ) ...
overrides the visitor capture source lines for the method
126,817
private String [ ] getSourceLines ( Method obj ) { if ( srcInited ) { return sourceLines ; } try { srcLineAnnotation = SourceLineAnnotation . forEntireMethod ( getClassContext ( ) . getJavaClass ( ) , obj ) ; if ( srcLineAnnotation != null ) { SourceFinder sourceFinder = AnalysisContext . currentAnalysisContext ( ) . g...
reads the sourcefile based on the source line annotation for the method
126,818
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 = methodSt...
overrides the visitor to find the source lines for the method header to find non final parameters
126,819
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
126,820
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
126,821
public void visitClassContext ( ClassContext classContext ) { try { stack = new OpcodeStack ( ) ; registerConstants = new HashMap < > ( ) ; overloadedMethods = collectOverloadedMethods ( classContext . getJavaClass ( ) ) ; super . visitClassContext ( classContext ) ; } finally { stack = null ; registerConstants = 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 .
126,822
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 . getSignatu...
implements the visitor to reset the stack and proceed for private methods
126,823
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 .
126,824
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 ( ) ) ; } } } s...
overrides the visitor to look for PUTFIELDS of collections
126,825
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
126,826
public void visitClassContext ( ClassContext classContext ) { JavaClass cls = classContext . getJavaClass ( ) ; cls . accept ( this ) ; }
implements the visitor to accept the class for visiting
126,827
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 . templateParam...
implements the visitor to find methods that declare template parameters that are not bound to any parameter .
126,828
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
126,829
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 ...
builds a template signature object based on the signature attribute of the method
126,830
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 : mapB...
implement the visitor to report bugs if no Tree comparators were found
126,831
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
126,832
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 ...
overrides the visitor to find declared runtime exceptions
126,833
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 (...
called after the execution of the parent OpcodeStack . sawOpcode to restore the user values after the GOTO or GOTO_W s mergeJumps were processed
126,834
public void visitCode ( Code obj ) { try { userValues = new HashMap < > ( ) ; super . visitCode ( obj ) ; } finally { userValues = null ; } }
implements the visitor to reset the uservalues
126,835
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 . ...
implements the visitor to look for classes compiled with 1 . 5 or better that have all constructors that are private
126,836
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 ) ) { fieldCl...
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
126,837
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
126,838
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
126,839
public void visitClassContext ( ClassContext classContext ) { try { JavaClass cls = classContext . getJavaClass ( ) ; constrainingMethods = buildConstrainingMethods ( cls ) ; AnnotationEntry [ ] annotations = cls . getAnnotationEntries ( ) ; classHasAnnotation = ! CollectionUtils . isEmpty ( annotations ) ; stack = new...
implements the visitor to collect statistics on this class
126,840
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 .
126,841
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 superC...
overrides the visitor to accept classes derived from non java . lang . Object classes .
126,842
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 ( ) . getAccessFl...
overrides the visitor to find code blocks of methods that are the same as its parents
126,843
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...
overrides the visitor to look for an exact call to the parent class s method using this methods parm .
126,844
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
126,845
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 ; possibleTailRecursio...
implements the visitor to figure the pc where the method call must occur depending on whether the method returns a value or not .
126,846
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
126,847
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 . conta...
implements the visitor to look for method calls that are one of the old pre - collections1 . 2 set of methods
126,848
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
126,849
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 ...
implements the visitor to clear the opcode stack for the next code
126,850
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
126,851
public void visitClassContext ( ClassContext classContext ) { try { JavaClass cls = classContext . getJavaClass ( ) ; if ( cls . isAbstract ( ) ) { interfaceMethods = collectInterfaceMethods ( cls ) ; super . visitClassContext ( classContext ) ; } } catch ( ClassNotFoundException cnfe ) { bugReporter . reportMissingCla...
overrides the visitor to check for abstract classes .
126,852
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 ( ) ) ) ) { sup...
overrides the visitor to filter out constructors .
126,853
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 = Sta...
overrides the visitor to look for empty methods or simple exception throwers .
126,854
private boolean prescreen ( Method method ) { BitSet bytecodeSet = getClassContext ( ) . getBytecodeSet ( method ) ; return ( bytecodeSet != null ) && bytecodeSet . intersects ( arrayLoadOps ) ; }
looks for methods that contain array load opcodes
126,855
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 ...
looks to see if a load and store operation are working on the same type of array
126,856
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 ( V...
implements the visitor to look for any non - immutable typed parameters are assignable to the return type . If found the method is parsed .
126,857
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
126,858
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
126,859
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 = getClassConsta...
implements the visitor to look for checkcasts of the parameter to other types and enter instances in a map for further processing in doReport .
126,860
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 = equa...
reports all the collected issues from the parse of this class
126,861
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...
implements the visitor to create and the clear the register to location map
126,862
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 ScopeBloc...
implements the visitor to reset the register to location map
126,863
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 ) ) { saw...
implements the visitor to look for variables assigned below the scope in which they are used .
126,864
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 Scope...
processes a register store by updating the appropriate scope block to mark this register as being stored in the block
126,865
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 ...
processes a register IINC by updating the appropriate scope block to mark this register as being stored in the block
126,866
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
126,867
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 ( s...
creates a scope block to describe this branch location .
126,868
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 ( ! targe...
creates a new scope block for each case statement
126,869
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 .
126,870
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
126,871
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
126,872
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 ; }...
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 .
126,873
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 ) ; i...
returns the scope block in which this register was assigned by traversing the scope block tree
126,874
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 ( ) ) ) ) { parentB...
returns an existing scope block that has the same target as the one looked for
126,875
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 ) ...
looks for the ScopeBlock has the same parent as this given one but precedes it in the list .
126,876
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 ...
finds the scope block that is the active synchronized block
126,877
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
126,878
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 ( ClassNotFoundExceptio...
override the visitor to look for classes that implement Cloneable
126,879
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
126,880
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...
override the visitor to look for stores to member fields of the source object on a clone
126,881
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
126,882
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 . na...
implements the visitor to clear the collections and report the query locations that are in loops
126,883
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 ( ) ) ) ; ...
implements the visitor to collect positions of queries and loops
126,884
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
126,885
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 !...
parses all the parameters of a called method and removes any of the parameters that are maps currently being looked at for this detector
126,886
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
126,887
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 = getNameConstantOperan...
implements the visitor to look for a checkcast followed by a astore where the types of the objects are different .
126,888
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
126,889
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
126,890
public void sawOpcode ( int seen ) { try { stack . precomputation ( this ) ; if ( seen == Const . INVOKEINTERFACE ) { KeyType type = isKeyAccessMethod ( seen ) ; if ( type != null ) { int numParms = SignatureUtils . getNumParameters ( getSigConstantOperand ( ) ) ; if ( stack . getStackDepth ( ) >= numParms ) { OpcodeSt...
implements the visitor to look for calls to HttpServletRequest . getParameter and collect what the name of the key is .
126,891
public void report ( ) { for ( Map . Entry < KeyType , Map < String , Map < String , List < SourceInfo > > > > entry : parmInfo . entrySet ( ) ) { KeyType type = entry . getKey ( ) ; Map < String , Map < String , List < SourceInfo > > > typeMap = entry . getValue ( ) ; for ( Map < String , List < SourceInfo > > parmCas...
implements the visitor to look for the collected parm names and look for duplicates that are different in casing only .
126,892
public void visitClassContext ( ClassContext classContext ) { try { branchTargets = new BitSet ( ) ; catchTargets = new BitSet ( ) ; stack = new OpcodeStack ( ) ; super . visitClassContext ( classContext ) ; } finally { branchTargets = null ; catchTargets = null ; stack = null ; } }
implements the visitor to create and clear the branchTargets
126,893
public void visitCode ( Code obj ) { Method m = getMethod ( ) ; String sig = m . getSignature ( ) ; if ( ! Values . SIG_VOID . equals ( SignatureUtils . getReturnSignature ( sig ) ) ) { state = State . SEEN_NOTHING ; branchTargets . clear ( ) ; CodeException [ ] ces = obj . getExceptionTable ( ) ; catchTargets . clear ...
implements the visitor to make sure method returns a value and then clears the targets
126,894
public void sawOpcode ( int seen ) { int lhsReg = - 1 ; try { stack . precomputation ( this ) ; switch ( state ) { case SEEN_NOTHING : if ( ! catchTargets . get ( getPC ( ) ) && lookForStore ( seen ) && ( stack . getStackDepth ( ) >= 1 ) ) { OpcodeStack . Item item = stack . getStackItem ( 0 ) ; Integer reg = ( Integer...
implements the visitor to look for store of registers immediately before returns of that register
126,895
private boolean lookForStore ( int seen ) { if ( ! OpcodeUtils . isStore ( seen ) ) { return false ; } storeReg = RegisterUtils . getStoreReg ( this , seen ) ; return true ; }
checks if the current opcode is a store if so saves the register
126,896
private boolean lookForLoad ( int seen ) { int loadReg ; if ( ! OpcodeUtils . isLoad ( seen ) ) { return false ; } loadReg = RegisterUtils . getLoadReg ( this , seen ) ; return ( storeReg == loadReg ) ; }
looks for a load of the register that was just stored
126,897
public void visitCode ( Code obj ) { try { String signature = SignatureUtils . getReturnSignature ( getMethod ( ) . getSignature ( ) ) ; if ( signature . startsWith ( Values . SIG_QUALIFIED_CLASS_PREFIX ) && CollectionUtils . isListSetMap ( SignatureUtils . stripSignature ( signature ) ) ) { stack . resetForMethodEntry...
overrides the visitor to reset the stack for the new method then checks if the immutability field is set to immutable and if so reports it
126,898
public void sawOpcode ( int seen ) { ImmutabilityType seenImmutable = null ; try { stack . precomputation ( this ) ; switch ( seen ) { case Const . INVOKESTATIC : { String className = getClassConstantOperand ( ) ; String methodName = getNameConstantOperand ( ) ; if ( IMMUTABLE_PRODUCING_METHODS . contains ( className +...
overrides the visitor to look for calls to static methods that are known to return immutable collections It records those variables and documents if what the method returns is one of those objects .
126,899
private boolean isJavaXExternal ( String className ) { if ( ! className . startsWith ( "javax/" ) ) { return false ; } if ( className . startsWith ( "javax/xml/" ) ) { return true ; } int lastSlashPos = className . lastIndexOf ( '/' ) ; String packageName = className . substring ( 0 , lastSlashPos ) ; ZipEntry ze = jdk...
checks to see if this class is a javax . xxxx . Foo class if so looks to see if the package is at least in the jdk if a whole new package comes into javax in rt . jar this will be missed . Need a better solution here .