idx
int64
0
165k
question
stringlengths
73
5.81k
target
stringlengths
5
918
126,700
public void visitClassContext ( final ClassContext classContext ) { try { stack = new OpcodeStack ( ) ; memberCollections = new HashMap < > ( ) ; memberSourceLineAnnotations = new HashMap < > ( ) ; super . visitClassContext ( classContext ) ; } finally { stack = null ; memberCollections = null ; memberSourceLineAnnotat...
implements the visitor to create and destroy the stack and member collections
126,701
public void visitCode ( final Code obj ) { try { localCollections = new HashMap < > ( ) ; localScopeEnds = new HashMap < > ( ) ; localSourceLineAnnotations = new HashMap < > ( ) ; stack . resetForMethodEntry ( this ) ; super . visitCode ( obj ) ; } finally { localCollections = null ; localScopeEnds = null ; localSource...
implements the visitor to reset the opcode stack and clear the various collections
126,702
public void sawOpcode ( final int seen ) { try { stack . precomputation ( this ) ; BitSet regs = localScopeEnds . remove ( Integer . valueOf ( getPC ( ) ) ) ; if ( regs != null ) { int i = regs . nextSetBit ( 0 ) ; while ( i >= 0 ) { localCollections . remove ( i ) ; localSourceLineAnnotations . remove ( i ) ; i = regs...
implements the visitor to look for collection method calls that put objects into the collection that are unrelated by anything besides java . lang . Objecct
126,703
private void mergeItem ( final Set < String > supers , final Set < SourceLineAnnotation > sla , final OpcodeStack . Item addItm ) throws ClassNotFoundException { if ( supers . isEmpty ( ) ) { return ; } Set < String > s = new HashSet < > ( ) ; addNewItem ( s , addItm ) ; if ( s . isEmpty ( ) ) { return ; } intersection...
intersects the set of possible superclass that this collection might have seen before with this one . If we find that there is no commonality between superclasses report it as a bug .
126,704
public void visitClassContext ( ClassContext classContext ) { try { JavaClass cls = classContext . getJavaClass ( ) ; if ( isSingleton ( cls ) ) { syncBlockBranchResetValues = new HashMap < > ( ) ; stack = new OpcodeStack ( ) ; super . visitClassContext ( classContext ) ; } } finally { syncBlockBranchResetValues = null...
implements the visitor to look for classes that are singletons
126,705
public void visitCode ( Code obj ) { Method m = getMethod ( ) ; if ( isIgnorableMethod ( m ) ) { return ; } stack . resetForMethodEntry ( this ) ; syncBlockBranchResetValues . clear ( ) ; syncBlockCount = 0 ; super . visitCode ( obj ) ; }
implements the visitor to look for methods that could possibly be normal methods where a field is written to
126,706
public void sawOpcode ( int seen ) { boolean sawResource = false ; try { stack . precomputation ( this ) ; if ( seen == Const . INVOKEVIRTUAL ) { sawResource = processInvokeVirtual ( ) ; } else if ( seen == Const . INVOKESPECIAL ) { sawResource = processInvokeSpecial ( ) ; } } finally { stack . sawOpcode ( this , seen ...
overrides the visitor to look conflated use of resources and files
126,707
public void visitClassContext ( ClassContext classContext ) { try { stack = new OpcodeStack ( ) ; localMethodCalls = new HashMap < > ( ) ; fieldMethodCalls = new HashMap < > ( ) ; staticMethodCalls = new HashMap < > ( ) ; branchTargets = new BitSet ( ) ; super . visitClassContext ( classContext ) ; } finally { stack = ...
implements the visitor to create and clear the stack method call maps and branch targets
126,708
private static int getBugPriority ( String methodName , MethodInfo mi ) { if ( Values . STATIC_INITIALIZER . equals ( methodName ) ) { return LOW_PRIORITY ; } if ( ( mi . getNumBytes ( ) >= highByteCountLimit ) || ( mi . getNumMethodCalls ( ) >= highMethodCallLimit ) ) { return HIGH_PRIORITY ; } if ( ( mi . getNumBytes...
returns the bug priority based on metrics about the method
126,709
private static boolean isRiskyName ( String className , String methodName ) { if ( riskyClassNames . contains ( className ) ) { return true ; } String qualifiedMethodName = className + '.' + methodName ; if ( riskyMethodNameContents . contains ( qualifiedMethodName ) ) { return true ; } for ( String riskyName : riskyMe...
returns true if the class or method name contains a pattern that is considered likely to be this modifying
126,710
private int getLineNumber ( int pc ) { LineNumberTable lnt = getMethod ( ) . getLineNumberTable ( ) ; if ( lnt == null ) { return pc ; } LineNumber [ ] lns = lnt . getLineNumberTable ( ) ; if ( lns == null ) { return pc ; } if ( pc > lns [ lns . length - 1 ] . getStartPC ( ) ) { return lns [ lns . length - 1 ] . getLin...
returns the source line number for the pc or just the pc if the line number table doesn t exist
126,711
public void visitClassContext ( ClassContext classContext ) { if ( cloneClass == null ) { return ; } try { cls = classContext . getJavaClass ( ) ; if ( cls . implementationOf ( cloneClass ) ) { clsName = cls . getClassName ( ) ; stack = new OpcodeStack ( ) ; super . visitClassContext ( classContext ) ; } } catch ( Clas...
overrides the visitor to check for classes that implement Cloneable .
126,712
public void sawOpcode ( int seen ) { try { if ( ( seen == Const . ATHROW ) && ( stack . getStackDepth ( ) > 0 ) ) { OpcodeStack . Item item = stack . getStackItem ( 0 ) ; if ( "Ljava/lang/CloneNotSupportedException;" . equals ( item . getSignature ( ) ) ) { throwsCNFE = true ; } } } finally { stack . sawOpcode ( this ,...
overrides the visitor to look for a CloneNotSupported being thrown
126,713
public void visitCode ( Code obj ) { try { lnTable = obj . getLineNumberTable ( ) ; if ( lnTable != null ) { state = State . SEEN_NOTHING ; invokePC = - 1 ; returnType = null ; super . visitCode ( obj ) ; } } finally { lnTable = null ; } }
overrides the interface to collect the line number table and reset state
126,714
public void sawOpcode ( int seen ) { switch ( state ) { case SEEN_NOTHING : if ( ( seen == Const . INVOKEINTERFACE ) || ( seen == Const . INVOKEVIRTUAL ) ) { String sig = getSigConstantOperand ( ) ; String returnSig = SignatureUtils . getReturnSignature ( sig ) ; if ( returnSig . startsWith ( Values . SIG_QUALIFIED_CLA...
overrides the interface to find accesses of static variables off of an instance immediately fetched from a method call .
126,715
public void visitClassContext ( final ClassContext context ) { try { classContext = context ; classContext . getJavaClass ( ) . accept ( this ) ; } finally { classContext = null ; } }
overrides the visitor to store the class context
126,716
public void visitMethod ( final Method obj ) { try { if ( obj . isSynthetic ( ) ) { return ; } Code code = obj . getCode ( ) ; if ( code == null ) { return ; } if ( code . getCode ( ) . length < ( 2 * reportLimit ) ) { return ; } BitSet exceptionNodeTargets = new BitSet ( ) ; CFG cfg = classContext . getCFG ( obj ) ; i...
overrides the visitor to navigate the basic block list to count branches
126,717
public void visitCode ( Code obj ) { Method m = getMethod ( ) ; if ( m . isSynthetic ( ) ) { return ; } isPublic = m . isPublic ( ) ; stack . resetForMethodEntry ( this ) ; super . visitCode ( obj ) ; }
implements the visitor to reset the opcode stack Note that the synthetic check is done in both visitMethod and visitCode as visitMethod is not a proper listener stopping method . We don t want to report issues reported in visitMethod if it is synthetic but we also don t want it to get into sawOpcode so that is why it i...
126,718
private void catalogClass ( JavaClass clz ) { transactionalMethods = new HashMap < > ( ) ; isEntity = false ; hasId = false ; hasGeneratedValue = false ; hasEagerOneToMany = false ; hasHCEquals = false ; for ( AnnotationEntry entry : clz . getAnnotationEntries ( ) ) { if ( "Ljavax/persistence/Entity;" . equals ( entry ...
parses the current class for spring - tx and jpa annotations as well as hashCode and equals methods .
126,719
private void catalogFieldOrMethod ( FieldOrMethod fm ) { for ( AnnotationEntry entry : fm . getAnnotationEntries ( ) ) { String type = entry . getAnnotationType ( ) ; switch ( type ) { case "Lorg/springframework/transaction/annotation/Transactional;" : if ( fm instanceof Method ) { boolean isWrite = true ; for ( Elemen...
parses a field or method for spring - tx or jpa annotations
126,720
private Set < JavaClass > getDeclaredExceptions ( Method method ) throws ClassNotFoundException { ExceptionTable et = method . getExceptionTable ( ) ; if ( ( et == null ) || ( et . getLength ( ) == 0 ) ) { return Collections . < JavaClass > emptySet ( ) ; } Set < JavaClass > exceptions = new HashSet < > ( ) ; for ( Str...
retrieves the set of non - runtime exceptions that are declared to be thrown by the method
126,721
public void visitCode ( Code obj ) { Method m = getMethod ( ) ; if ( prescreen ( m ) ) { if ( m . isSynchronized ( ) ) { syncPC = 0 ; } else { syncPC = - 1 ; } isStatic = m . isStatic ( ) ; unsafeAliases . clear ( ) ; unsafeAliases . set ( 0 ) ; branchInfo . clear ( ) ; unsafeCallOccurred = false ; stack . resetForMeth...
implement the visitor to reset the sync count the stack and gather some information
126,722
public void sawOpcode ( int seen ) { try { stack . precomputation ( this ) ; if ( unsafeCallOccurred && OpcodeUtils . isAStore ( seen ) ) { int storeReg = RegisterUtils . getAStoreReg ( this , seen ) ; if ( storeReg >= 0 ) { unsafeAliases . set ( storeReg ) ; } } if ( ( seen == Const . INVOKEVIRTUAL ) || ( seen == Cons...
implement the visitor to find bloated sync blocks . This implementation only checks the outer most block
126,723
public void visitClassContext ( ClassContext classContext ) { currentClass = classContext . getJavaClass ( ) ; if ( currentClass . getMajor ( ) >= Const . MAJOR_1_8 ) { try { stack = new OpcodeStack ( ) ; activeStackOps = new ArrayDeque < > ( ) ; super . visitClassContext ( classContext ) ; } finally { activeStackOps =...
implements the visitor to filter out pre - 1 . 8 classes for 1 . 8 + classes it creates the opcode stack and active stack ops
126,724
public void visitCode ( Code obj ) { stack . resetForMethodEntry ( this ) ; activeStackOps . clear ( ) ; super . visitCode ( obj ) ; }
implements the visitor clear the stacks
126,725
private boolean isTrivialStackOps ( ) { int invokeCount = 0 ; for ( ActiveStackOp op : activeStackOps ) { if ( INVOKE_OPS . get ( op . getOpcode ( ) ) ) { invokeCount ++ ; } } if ( invokeCount == 1 ) { FQMethod method = activeStackOps . getLast ( ) . getMethod ( ) ; if ( method == null ) { return false ; } if ( "valueO...
returns whether the set of operations that contributed to the current stack form are trivial or not specifically boxing a primitive value or appending to strings or such .
126,726
private Method getLambdaMethod ( String methodName ) { for ( Method method : currentClass . getMethods ( ) ) { if ( methodName . equals ( method . getName ( ) ) ) { return method ; } } return null ; }
finds the bootstrap method for a lambda ( invokedynamic call . As findbugs doesn t support bcel 6 have to cheat a little here .
126,727
public void visitClassContext ( ClassContext classContext ) { JavaClass cls = classContext . getJavaClass ( ) ; clsVersion = cls . getMajor ( ) ; super . visitClassContext ( classContext ) ; }
overrides the visitor to make sure this is a modern class better than 1 . 4
126,728
public void sawOpcode ( int seen ) { stack . precomputation ( this ) ; switch ( seen ) { case Const . INVOKESTATIC : { String className = getClassConstantOperand ( ) ; for ( Backports backport : BACKPORTS ) { if ( className . startsWith ( backport . getPathPrefix ( ) ) ) { if ( clsVersion >= backport . getMinimumJDK ( ...
overrides the visitor to look for method calls to the emory backport concurrent library or threeten bp library when the now built - in versions are available
126,729
private void reportBug ( Library library ) { bugReporter . reportBug ( new BugInstance ( this , BugType . BRPI_BACKPORT_REUSE_PUBLIC_IDENTIFIERS . name ( ) , NORMAL_PRIORITY ) . addClass ( this ) . addMethod ( this ) . addSourceLine ( this ) . addString ( library . name ( ) ) ) ; }
issues a new bug at this location
126,730
public void visitClassContext ( ClassContext classContext ) { try { stack = new OpcodeStack ( ) ; nameOfThisClass = SignatureUtils . getNonAnonymousPortion ( classContext . getJavaClass ( ) . getClassName ( ) ) ; formatterLoggers = new HashSet < > ( ) ; super . visitClassContext ( classContext ) ; } finally { formatter...
implements the visitor to discover what the class name is if it is a normal class or the owning class if the class is an anonymous class .
126,731
@ SuppressWarnings ( "unchecked" ) private void checkForProblemsWithLoggerMethods ( ) throws ClassNotFoundException { String callingClsName = getClassConstantOperand ( ) ; if ( ! ( callingClsName . endsWith ( "Log" ) || ( callingClsName . endsWith ( "Logger" ) ) ) || ( stack . getStackDepth ( ) == 0 ) ) { return ; } St...
looks for a variety of logging issues with log statements
126,732
@ SuppressWarnings ( "unchecked" ) private int getVarArgsParmCount ( String signature ) { if ( SignatureBuilder . SIG_STRING_AND_OBJECT_TO_VOID . equals ( signature ) ) { return 1 ; } if ( SIG_STRING_AND_TWO_OBJECTS_TO_VOID . equals ( signature ) ) { return 2 ; } OpcodeStack . Item item = stack . getStackItem ( 0 ) ; L...
returns the number of parameters slf4j or log4j2 is expecting to inject into the format string
126,733
@ SuppressWarnings ( "unchecked" ) private boolean hasExceptionOnStack ( ) { try { for ( int i = 0 ; i < ( stack . getStackDepth ( ) - 1 ) ; i ++ ) { OpcodeStack . Item item = stack . getStackItem ( i ) ; String sig = item . getSignature ( ) ; if ( sig . startsWith ( Values . SIG_QUALIFIED_CLASS_PREFIX ) ) { String nam...
returns whether an exception object is on the stack slf4j will find this and not include it in the parm list so i we find one just don t report
126,734
public void visitClassContext ( final ClassContext classContext ) { JavaClass cls = classContext . getJavaClass ( ) ; Field [ ] flds = cls . getFields ( ) ; for ( Field f : flds ) { String sig = f . getSignature ( ) ; if ( sig . startsWith ( Values . SIG_QUALIFIED_CLASS_PREFIX ) ) { if ( sig . startsWith ( "Ljava/util/...
overrides the visitor to accept classes that define List based fields
126,735
public void visitCode ( final Code obj ) { try { stack . resetForMethodEntry ( this ) ; super . visitCode ( obj ) ; } catch ( StopOpcodeParsingException e ) { } }
overrides the visitor to reset the opcode stack object
126,736
public void sawOpcode ( final int seen ) { try { stack . precomputation ( this ) ; if ( seen == Const . INVOKEINTERFACE ) { processInvokeInterface ( ) ; } else if ( seen == Const . INVOKEVIRTUAL ) { processInvokeVirtual ( ) ; } else if ( ( seen == Const . ARETURN ) && ( stack . getStackDepth ( ) > 0 ) ) { OpcodeStack ....
overrides the visitor to record all method calls on List fields . If a method is not a set based method remove it from further consideration
126,737
private static XField getFieldFromStack ( final OpcodeStack stk , final String signature ) { int parmCount = SignatureUtils . getNumParameters ( signature ) ; if ( stk . getStackDepth ( ) > parmCount ) { OpcodeStack . Item itm = stk . getStackItem ( parmCount ) ; return itm . getXField ( ) ; } return null ; }
return the field object that the current method was called on by finding the reference down in the stack based on the number of parameters
126,738
private void reportBugs ( ) { int major = getClassContext ( ) . getJavaClass ( ) . getMajor ( ) ; for ( Map . Entry < String , FieldInfo > entry : fieldsReported . entrySet ( ) ) { String field = entry . getKey ( ) ; FieldInfo fi = entry . getValue ( ) ; int cnt = fi . getSetCount ( ) ; if ( cnt > 0 ) { FieldAnnotation...
implements the detector by reporting all remaining fields that only have set based access
126,739
private FieldAnnotation getFieldAnnotation ( final String fieldName ) { JavaClass cls = getClassContext ( ) . getJavaClass ( ) ; Field [ ] fields = cls . getFields ( ) ; for ( Field f : fields ) { if ( f . getName ( ) . equals ( fieldName ) ) { return new FieldAnnotation ( cls . getClassName ( ) , fieldName , f . getSi...
builds a field annotation by finding the field in the classes field list
126,740
public void sawOpcode ( int seen ) { try { stack . precomputation ( this ) ; if ( seen == Const . INVOKEVIRTUAL ) { String clsName = getClassConstantOperand ( ) ; if ( "java/util/Properties" . equals ( clsName ) ) { String methodName = getNameConstantOperand ( ) ; if ( "put" . equals ( methodName ) ) { String sig = get...
implements the visitor to look for calls to java . utils . Properties . put where the value is a non String . Reports both cases where if it is a string at a lower lever .
126,741
public void visitClassContext ( ClassContext classContext ) { try { if ( ( runtimeExceptionClass != null ) && ( exceptionClass != null ) ) { stack = new OpcodeStack ( ) ; declaredCheckedExceptions = new HashSet < > ( 6 ) ; JavaClass cls = classContext . getJavaClass ( ) ; classIsFinal = cls . isFinal ( ) ; classIsAnony...
overrides the visitor to create the opcode stack
126,742
public void visitCode ( Code obj ) { Method method = getMethod ( ) ; if ( method . isSynthetic ( ) ) { return ; } declaredCheckedExceptions . clear ( ) ; stack . resetForMethodEntry ( this ) ; ExceptionTable et = method . getExceptionTable ( ) ; if ( et != null ) { if ( classIsFinal || classIsAnonymous || method . isSt...
implements the visitor to see if the method declares that it throws any checked exceptions .
126,743
public void sawOpcode ( int seen ) { try { stack . precomputation ( this ) ; if ( OpcodeUtils . isStandardInvoke ( seen ) ) { String clsName = getClassConstantOperand ( ) ; if ( ! safeClasses . contains ( clsName ) ) { try { JavaClass cls = Repository . lookupClass ( clsName ) ; Method [ ] methods = cls . getMethods ( ...
implements the visitor to look for method calls that could throw the exceptions that are listed in the declaration .
126,744
private void removeThrownExceptionHierarchy ( String thrownException ) { try { if ( Values . DOTTED_JAVA_LANG_EXCEPTION . equals ( thrownException ) || Values . DOTTED_JAVA_LANG_THROWABLE . equals ( thrownException ) ) { clearExceptions ( ) ; } else { removeException ( thrownException ) ; JavaClass exCls = Repository ....
removes this thrown exception the list of declared thrown exceptions including all exceptions in this exception s hierarchy . If an exception class is found that can t be loaded then just clear the list of declared checked exceptions and get out .
126,745
public void visitClassContext ( ClassContext classContext ) { try { JavaClass cls = classContext . getJavaClass ( ) ; if ( ( serializableClass != null ) && cls . implementationOf ( serializableClass ) ) { super . visitClassContext ( classContext ) ; } } catch ( ClassNotFoundException cnfe ) { bugReporter . reportMissin...
overrides the method to check for Serializable
126,746
public void visitCode ( Code obj ) { String nameAndSignature = getMethod ( ) . getName ( ) + getMethod ( ) . getSignature ( ) ; if ( SignatureBuilder . SIG_READ_OBJECT . equals ( nameAndSignature ) ) { inReadObject = true ; inWriteObject = false ; } else if ( SIG_WRITE_OBJECT . equals ( nameAndSignature ) ) { inReadObj...
overrides the method to check for either readObject or writeObject methods and if so reset the stack
126,747
public void visitClassContext ( ClassContext clsContext ) { try { stack = new OpcodeStack ( ) ; clsVersion = clsContext . getJavaClass ( ) . getMajor ( ) ; unendedZLIBs = new HashMap < > ( ) ; super . visitClassContext ( clsContext ) ; } finally { unendedZLIBs = null ; stack = null ; } }
implements the visitor to create and tear down the opcode stack
126,748
public void visitMethod ( Method obj ) { methodSignatureIsConstrained = false ; String methodName = obj . getName ( ) ; if ( ! Values . CONSTRUCTOR . equals ( methodName ) && ! Values . STATIC_INITIALIZER . equals ( methodName ) ) { String methodSig = obj . getSignature ( ) ; methodSignatureIsConstrained = methodIsSpec...
implements the visitor to look to see if this method is constrained by a superclass or interface .
126,749
public void visitCode ( final Code obj ) { try { if ( methodSignatureIsConstrained ) { return ; } if ( obj . getCode ( ) == null ) { return ; } Method m = getMethod ( ) ; if ( m . isSynthetic ( ) ) { return ; } if ( m . getName ( ) . startsWith ( "access$" ) ) { return ; } methodIsStatic = m . isStatic ( ) ; parmCount ...
implements the visitor to collect information about the parameters of a this method
126,750
private static boolean methodIsSpecial ( String methodName , String methodSig ) { return SignatureBuilder . SIG_READ_OBJECT . equals ( methodName + methodSig ) ; }
determines whether the method is a baked in special method of the jdk
126,751
private boolean methodHasSyntheticTwin ( String methodName , String methodSig ) { for ( Method m : cls . getMethods ( ) ) { if ( m . isSynthetic ( ) && m . getName ( ) . equals ( methodName ) && ! m . getSignature ( ) . equals ( methodSig ) ) { return true ; } } return false ; }
returns whether this method has an equivalent method that is synthetic which implies this method is constrained by some Generified interface . We could compare parameters but that is a bunch of work that probably doesn t make this test any more precise so just return true if method name and synthetic is found .
126,752
private void reportBugs ( ) { Iterator < Map . Entry < Integer , Map < JavaClass , List < MethodInfo > > > > it = parameterDefiners . entrySet ( ) . iterator ( ) ; while ( it . hasNext ( ) ) { try { Map . Entry < Integer , Map < JavaClass , List < MethodInfo > > > entry = it . next ( ) ; Integer reg = entry . getKey ( ...
implements the post processing steps to report the remaining unremoved parameter definers ie those that can be defined more abstractly .
126,753
private boolean hasOverloadedMethod ( ) { Method thisMethod = getMethod ( ) ; String name = thisMethod . getName ( ) ; String sig = thisMethod . getSignature ( ) ; int numArgs = SignatureUtils . getNumParameters ( sig ) ; for ( Method m : cls . getMethods ( ) ) { if ( m . getName ( ) . equals ( name ) ) { if ( ! m . ge...
looks to see if this method has an overloaded method in actuality this isn t precise and returns true for methods that are named the same and have same number of args This will miss some cases but in practicality doesn t matter .
126,754
private boolean buildParameterDefiners ( ) throws ClassNotFoundException { Method m = getMethod ( ) ; Type [ ] parms = m . getArgumentTypes ( ) ; if ( parms . length == 0 ) { return false ; } ParameterAnnotationEntry [ ] annotations = m . getParameterAnnotationEntries ( ) ; boolean hasPossiblyOverlyConcreteParm = false...
builds a map of method information for each method of each interface that each parameter implements of this method
126,755
private static Map < JavaClass , List < MethodInfo > > getClassDefiners ( final JavaClass cls ) throws ClassNotFoundException { Map < JavaClass , List < MethodInfo > > definers = new HashMap < > ( ) ; for ( JavaClass ci : cls . getAllInterfaces ( ) ) { if ( cls . equals ( ci ) || ! cls . isPublic ( ) || "java.lang.Comp...
returns a map of method information for each public method for each interface this class implements
126,756
private static List < MethodInfo > getPublicMethodInfos ( final JavaClass cls ) { List < MethodInfo > methodInfos = new ArrayList < > ( ) ; Method [ ] methods = cls . getMethods ( ) ; for ( Method m : methods ) { if ( ( m . getAccessFlags ( ) & ( Const . ACC_PUBLIC | Const . ACC_PROTECTED ) ) != 0 ) { ExceptionTable et...
returns a list of method information of all public or protected methods in this class
126,757
private void removeUselessDefiners ( final int reg ) { Map < JavaClass , List < MethodInfo > > definers = parameterDefiners . get ( Integer . valueOf ( reg ) ) ; if ( CollectionUtils . isEmpty ( definers ) ) { return ; } String methodSig = getSigConstantOperand ( ) ; String methodName = getNameConstantOperand ( ) ; Met...
parses through the interface that may define a parameter defined by reg and look to see if we can rule it out because a method is called on the object that can t be satisfied by the interface if so remove that candidate interface .
126,758
private boolean isaConversionClass ( JavaClass conversionCls ) { for ( AnnotationEntry entry : conversionCls . getAnnotationEntries ( ) ) { if ( CONVERSION_ANNOTATIONS . contains ( entry . getAnnotationType ( ) ) ) { return true ; } if ( CONVERSION_SUPER_CLASSES . contains ( conversionCls . getSuperclassName ( ) ) ) { ...
returns whether this class is used to convert types of some sort such that you don t want to suggest reducing the class specified to be more generic
126,759
public void visitClassContext ( ClassContext classContext ) { try { stack = new OpcodeStack ( ) ; possibleForLoops = new HashSet < > ( ) ; super . visitClassContext ( classContext ) ; } finally { stack = null ; possibleForLoops = null ; } }
overrides the interface to create and clear the stack and loops tracker
126,760
private boolean prescreen ( Method method ) { BitSet bytecodeSet = getClassContext ( ) . getBytecodeSet ( method ) ; return ( bytecodeSet != null ) && ( bytecodeSet . get ( Const . IINC ) ) && ( bytecodeSet . get ( Const . GOTO ) || bytecodeSet . get ( Const . GOTO_W ) ) ; }
looks for methods that contain a IINC and GOTO or GOTO_W opcodes
126,761
public void visitCode ( final Code obj ) { Method m = getMethod ( ) ; if ( prescreen ( m ) ) { sawListSize = false ; stack . resetForMethodEntry ( this ) ; state = State . SAW_NOTHING ; stage = Stage . FIND_LOOP_STAGE ; super . visitCode ( obj ) ; if ( sawListSize && ! possibleForLoops . isEmpty ( ) ) { stack . resetFo...
overrides the visitor to reset the opcode stack
126,762
public void sawOpcode ( final int seen ) { if ( stage == Stage . FIND_LOOP_STAGE ) { sawOpcodeLoop ( seen ) ; } else { sawOpcodeBug ( seen ) ; } }
overrides the visitor to find list indexed iterating
126,763
private void sawOpcodeLoop ( final int seen ) { try { stack . mergeJumps ( this ) ; switch ( state ) { case SAW_NOTHING : if ( ( seen == Const . IINC ) && ( getIntConstant ( ) == 1 ) ) { loopReg = getRegisterOperand ( ) ; state = State . SAW_IINC ; } break ; case SAW_IINC : if ( ( seen == Const . GOTO ) || ( seen == Co...
the first pass of the method opcode to collet for loops information
126,764
public void visitClassContext ( ClassContext classContext ) { try { JavaClass cls = classContext . getJavaClass ( ) ; JavaClass [ ] superClasses = cls . getSuperClasses ( ) ; for ( JavaClass superCls : superClasses ) { if ( tagClasses . contains ( superCls . getClassName ( ) ) ) { attributes = getAttributes ( cls ) ; i...
implements the visitor to look for classes that extend the TagSupport or BodyTagSupport class
126,765
private static Map < QMethod , String > getAttributes ( JavaClass cls ) { Map < QMethod , String > atts = new HashMap < > ( ) ; Method [ ] methods = cls . getMethods ( ) ; for ( Method m : methods ) { String name = m . getName ( ) ; if ( name . startsWith ( "set" ) && m . isPublic ( ) && ! m . isStatic ( ) ) { String s...
collect all possible attributes given the name of methods available .
126,766
public void visitCode ( Code obj ) { Method m = getMethod ( ) ; if ( ! Values . CONSTRUCTOR . equals ( m . getName ( ) ) ) { super . visitCode ( obj ) ; } }
implements the visitor to
126,767
public void sawOpcode ( int seen ) { if ( seen == Const . PUTFIELD ) { QMethod methodInfo = new QMethod ( getMethodName ( ) , getMethodSig ( ) ) ; Map < Map . Entry < String , String > , SourceLineAnnotation > fields = methodWrites . get ( methodInfo ) ; if ( fields == null ) { fields = new HashMap < > ( ) ; methodWrit...
implements the visitor to record storing of fields and where they occur
126,768
private void reportBugs ( ) { for ( Map . Entry < QMethod , String > attEntry : attributes . entrySet ( ) ) { QMethod methodInfo = attEntry . getKey ( ) ; String attType = attEntry . getValue ( ) ; Map < Map . Entry < String , String > , SourceLineAnnotation > fields = methodWrites . get ( methodInfo ) ; if ( ( fields ...
generates all the bug reports for attributes that are not recycleable
126,769
public void visitClassContext ( ClassContext classContext ) { try { JavaClass cls = classContext . getJavaClass ( ) ; if ( cls . isAbstract ( ) || cls . isInterface ( ) ) { return ; } if ( Values . DOTTED_JAVA_LANG_OBJECT . equals ( cls . getSuperclassName ( ) ) ) { return ; } JavaClass [ ] infs = cls . getInterfaces (...
looks for classes that implement interfaces but don t provide those methods
126,770
private void filterSuperInterfaceMethods ( JavaClass inf , Set < QMethod > infMethods , JavaClass cls ) { try { if ( infMethods . isEmpty ( ) ) { return ; } JavaClass [ ] superInfs = inf . getInterfaces ( ) ; for ( JavaClass superInf : superInfs ) { if ( cls . implementationOf ( superInf ) ) { Set < QMethod > superInfM...
removes methods found in an interface when a super interface having the same methods is implemented in a parent . While this is somewhat hinky we ll allow it .
126,771
public void visitCode ( Code obj ) { try { userValues = new HashMap < > ( ) ; loops = new HashMap < > ( ) ; isInstanceMethod = ! getMethod ( ) . isStatic ( ) ; super . visitCode ( obj ) ; } finally { userValues = null ; loops = null ; } }
implements the visitor to reset the userValues and loops
126,772
private String isFieldCollection ( OpcodeStack . Item item ) throws ClassNotFoundException { Comparable < ? > aliasReg = ( Comparable < ? > ) item . getUserValue ( ) ; if ( aliasReg instanceof String ) { return ( String ) aliasReg ; } XField field = item . getXField ( ) ; if ( field == null ) { return null ; } JavaClas...
determines if the stack item refers to a collection that is stored in a field
126,773
public String getDisplay ( HashSet < String > s , String a , String b ) { if ( s . contains ( a ) ) { s . add ( b ) ; } else { s . add ( a + b ) ; } StringBuilder sb = new StringBuilder ( ) ; Iterator < String > it = s . iterator ( ) ; while ( it . hasNext ( ) ) { sb . append ( it . next ( ) ) ; } return sb . toString ...
tag OCP hashset could be Set instead
126,774
public String max ( List < String > s ) { String max = "" ; for ( String p : s ) { if ( p . length ( ) > max . length ( ) ) { max = p ; } } return max ; }
List should be declared as Collection where possible
126,775
public void parse ( DefaultHandler dh , File f ) throws SAXException , ParserConfigurationException , IOException { SAXParserFactory spf = SAXParserFactory . newInstance ( ) ; SAXParser sp = spf . newSAXParser ( ) ; XMLReader xr = sp . getXMLReader ( ) ; xr . setContentHandler ( dh ) ; xr . parse ( new InputSource ( ne...
tag OCP dh could be a ContentHandler instead
126,776
public static void httpComponentWithTryFalseNegative ( HttpPut request , String auth ) { auth = auth + "password" ; try { request . addHeader ( "Authorization" , Base64 . encodeBase64String ( auth . getBytes ( "UTF-8" ) ) ) ; } catch ( UnsupportedEncodingException e ) { logger . fatal ( "There was a problem encoding " ...
should tag OCP request - > HTTPMessage but doesnt
126,777
public int compare ( GregorianCalendar c1 , GregorianCalendar c2 ) { if ( c2 . getGregorianChange ( ) == null ) { return ( int ) ( c1 . getTime ( ) . getTime ( ) - c2 . getTime ( ) . getTime ( ) ) ; } else { return 0 ; } }
this method is really suspect but will ignore this case
126,778
public void visitClassContext ( final ClassContext context ) { try { stack = new OpcodeStack ( ) ; super . visitClassContext ( context ) ; } finally { stack = null ; } }
overrides the visitor to create and clear the opcode stack
126,779
private boolean prescreen ( Method obj ) { BitSet bytecodeSet = getClassContext ( ) . getBytecodeSet ( obj ) ; return ( bytecodeSet != null ) && ( ( bytecodeSet . get ( Const . LDC ) || ( bytecodeSet . get ( Const . LDC_W ) ) ) ) ; }
looks for methods that contain a LDC opcode
126,780
public void visitCode ( Code obj ) { if ( prescreen ( getMethod ( ) ) ) { stack . resetForMethodEntry ( this ) ; super . visitCode ( obj ) ; } }
prescreens the method and reset the stack
126,781
public void sawOpcode ( int seen ) { try { stack . precomputation ( this ) ; if ( ( seen == Const . INVOKEVIRTUAL ) || ( seen == Const . INVOKEINTERFACE ) ) { FQMethod key = new FQMethod ( getClassConstantOperand ( ) , getNameConstantOperand ( ) , getSigConstantOperand ( ) ) ; Object posObject = characterMethods . get ...
implements the visitor to look for method calls that pass a constant string as a parameter when the string is only one character long and there is an alternate method passing a character .
126,782
private UCPMUserValue callHasInline ( int seen ) { if ( seen != Const . INVOKEVIRTUAL ) { return null ; } String sig = getSigConstantOperand ( ) ; String returnSig = SignatureUtils . getReturnSignature ( sig ) ; if ( Values . SIG_JAVA_UTIL_STRINGBUILDER . equals ( returnSig ) || Values . SIG_JAVA_UTIL_STRINGBUFFER . eq...
checks to see if the current opcode is an INVOKEVIRTUAL call that has a INLINE userValue on the caller and a return value . If so return it .
126,783
public void visitClassContext ( ClassContext classContext ) { try { refClasses = new HashSet < > ( ) ; refClasses . add ( classContext . getJavaClass ( ) . getClassName ( ) ) ; state = State . COLLECT ; super . visitClassContext ( classContext ) ; state = State . SEEN_NOTHING ; super . visitClassContext ( classContext ...
overrides the visitor to collect all class references
126,784
public void sawOpcode ( int seen ) { switch ( state ) { case COLLECT : if ( ( seen == Const . INVOKESTATIC ) || ( seen == Const . INVOKEVIRTUAL ) || ( seen == Const . INVOKEINTERFACE ) || ( seen == Const . INVOKESPECIAL ) ) { refClasses . add ( getClassConstantOperand ( ) ) ; String signature = getSigConstantOperand ( ...
overrides the visitor to find class loading that is non obfuscation proof
126,785
private void addType ( Type t ) { String signature = t . getSignature ( ) ; if ( signature . startsWith ( Values . SIG_QUALIFIED_CLASS_PREFIX ) ) { refClasses . add ( SignatureUtils . trimSignature ( signature ) ) ; } }
add the type string represented by the type to the refClasses set if it is a reference
126,786
public void sawOpcode ( int seen ) { try { stack . precomputation ( this ) ; if ( seen == Const . INVOKEVIRTUAL ) { String clsName = getClassConstantOperand ( ) ; if ( "java/io/ObjectOutputStream" . equals ( clsName ) ) { String name = getNameConstantOperand ( ) ; if ( "writeObject" . equals ( name ) && ( stack . getSt...
implements the visitor to look for serialization of an object that is an non - static inner class .
126,787
public void visitClassContext ( ClassContext classContext ) { try { JavaClass cls = classContext . getJavaClass ( ) ; if ( cls . getMajor ( ) >= Const . MAJOR_1_4 ) { stack = new OpcodeStack ( ) ; regValueType = new HashMap < Integer , State > ( ) ; super . visitClassContext ( classContext ) ; } } finally { stack = nul...
implements the visitor to make sure the class is at least java 1 . 4 and to reset the opcode stack
126,788
public void visitClassContext ( ClassContext classContext ) { try { clsContext = classContext ; JavaClass cls = classContext . getJavaClass ( ) ; if ( cls . isInterface ( ) ) return ; superClasses = cls . getSuperClasses ( ) ; cls . accept ( this ) ; } catch ( ClassNotFoundException cnfe ) { bugReporter . reportMissing...
implements the detector to collect the super classes
126,789
public void visitMethod ( Method obj ) { if ( ! obj . isAbstract ( ) ) return ; String methodName = obj . getName ( ) ; String methodSig = obj . getSignature ( ) ; outer : for ( JavaClass cls : superClasses ) { Method [ ] methods = cls . getMethods ( ) ; for ( Method m : methods ) { if ( m . isPrivate ( ) || m . isAbst...
overrides the visitor to find abstract methods that override concrete ones
126,790
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 . getM...
overrides the visitor to look for confusing signatures
126,791
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 ( ) ) { ...
returns if one signature is a Character and the other is a primitive
126,792
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 ( isPossiblyConf...
fills out a set of method details for possibly confusing method signatures
126,793
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 ) ) {...
returns whether a method signature has either a Character or primitive
126,794
public void visitCode ( Code obj ) { stack . resetForMethodEntry ( this ) ; toStringRegisters . clear ( ) ; super . visitCode ( obj ) ; }
overrides the visitor to resets the stack for this method .
126,795
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 . getStackIt...
overrides the visitor to look for suspicious operations on toString
126,796
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 ( !...
overrides the visitor to look for methods that catch checked exceptions and rethrow runtime exceptions
126,797
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 = ...
overrides the visitor to find catch blocks that throw runtime exceptions
126,798
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
126,799
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 ( e...
reduces the end pc based on the optional LocalVariableTable s exception register scope