Mass-rename MethodAccess -> MethodCall

This commit is contained in:
Chris Smowton
2023-10-24 10:30:26 +01:00
committed by GitHub
parent a10731c591
commit f552a15aae
404 changed files with 1147 additions and 1138 deletions

View File

@@ -13,7 +13,7 @@
import java
import semmle.code.java.security.RandomQuery
from MethodAccess ma, Method abs, Method nextIntOrLong, RandomDataSource nma
from MethodCall ma, Method abs, Method nextIntOrLong, RandomDataSource nma
where
ma.getMethod() = abs and
abs.hasName("abs") and

View File

@@ -17,8 +17,8 @@ import semmle.code.java.Collections
predicate isDefinitelyPositive(Expr e) {
isDefinitelyPositive(e) or
e.(IntegerLiteral).getIntValue() >= 0 or
e.(MethodAccess).getMethod() instanceof CollectionSizeMethod or
e.(MethodAccess).getMethod() instanceof StringLengthMethod or
e.(MethodCall).getMethod() instanceof CollectionSizeMethod or
e.(MethodCall).getMethod() instanceof StringLengthMethod or
e.(FieldAccess).getField() instanceof ArrayLengthField
}

View File

@@ -18,7 +18,7 @@ class ContainerMutator extends Method {
}
}
class ContainerMutation extends MethodAccess {
class ContainerMutation extends MethodCall {
ContainerMutation() {
this instanceof CollectionMutation or
this instanceof MapMutation

View File

@@ -95,7 +95,7 @@ predicate containerAccess(string package, string type, int p, string signature,
i = 0
}
class MismatchedContainerAccess extends MethodAccess {
class MismatchedContainerAccess extends MethodCall {
MismatchedContainerAccess() {
exists(string package, string type, int i |
containerAccess(package, type, _, this.getCallee().getSignature(), i)

View File

@@ -13,10 +13,10 @@
import java
class SpecialCollectionCreation extends MethodAccess {
class SpecialCollectionCreation extends MethodCall {
SpecialCollectionCreation() {
exists(Method m, RefType rt |
m = this.(MethodAccess).getCallee() and rt = m.getDeclaringType()
m = this.(MethodCall).getCallee() and rt = m.getDeclaringType()
|
rt.hasQualifiedName("java.util", "Arrays") and m.hasName("asList")
or
@@ -46,7 +46,7 @@ predicate containsSpecialCollection(Expr e, SpecialCollectionCreation origin) {
}
predicate iterOfSpecialCollection(Expr e, SpecialCollectionCreation origin) {
exists(MethodAccess ma | ma = e |
exists(MethodCall ma | ma = e |
containsSpecialCollection(ma.getQualifier(), origin) and
ma.getCallee().hasName("iterator")
)
@@ -67,7 +67,7 @@ predicate iterOfSpecialCollection(Expr e, SpecialCollectionCreation origin) {
)
}
from MethodAccess remove, SpecialCollectionCreation scc
from MethodCall remove, SpecialCollectionCreation scc
where
remove.getCallee().hasName("remove") and
iterOfSpecialCollection(remove.getQualifier(), scc)

View File

@@ -32,12 +32,12 @@ where
v instanceof LocalVariableDecl and exists(ReturnStmt ret | ret.getResult() = va)
or
// ...or a call to a query method on `v`.
exists(MethodAccess ma | va = ma.getQualifier() |
exists(MethodCall ma | va = ma.getQualifier() |
ma.getMethod() instanceof ContainerQueryMethod
)
) and
// There is at least one call to a query method.
exists(MethodAccess ma | v.getAnAccess() = ma.getQualifier() |
exists(MethodCall ma | v.getAnAccess() = ma.getQualifier() |
ma.getMethod() instanceof ContainerQueryMethod
) and
// Also, any value that `v` is initialized to is a fresh container,

View File

@@ -65,7 +65,7 @@ predicate containerModification(string package, string type, int p, string signa
i = 0
}
class MismatchedContainerModification extends MethodAccess {
class MismatchedContainerModification extends MethodCall {
MismatchedContainerModification() {
exists(string package, string type, int i |
containerModification(package, type, _, this.getCallee().getSignature(), i)

View File

@@ -46,7 +46,7 @@ predicate checksReferenceEquality(EqualsMethod em) {
// Check whether `em` delegates to another method checking reference equality.
// More precisely, we check whether the body of `em` is of the form `return super.equals(o);`,
// where `o` is the (only) parameter of `em`, and the invoked method is a reference equality check.
exists(SuperMethodAccess sup |
exists(SuperMethodCall sup |
sup = em.getBody().(SingletonBlock).getStmt().(ReturnStmt).getResult() and
sup.getArgument(0) = em.getParameter(0).getAnAccess() and
checksReferenceEquality(sup.getCallee())

View File

@@ -13,7 +13,7 @@ class RefiningEquals extends EqualsMethod {
// For each return statement `ret` in this method, ...
forall(ReturnStmt ret | ret.getEnclosingCallable() = this |
// ... there is a `super` access that ...
exists(MethodAccess sup, SuperAccess qual |
exists(MethodCall sup, SuperAccess qual |
// ... is of the form `super.something`, but not `A.super.something` ...
qual = sup.getQualifier() and
not exists(qual.getQualifier()) and

View File

@@ -12,7 +12,7 @@
import java
from MethodAccess ma, Array recvtype, Method m
from MethodCall ma, Array recvtype, Method m
where
recvtype = ma.getQualifier().getType() and
m = ma.getMethod() and

View File

@@ -38,7 +38,7 @@ predicate usedInHash(RefType t, Expr e) {
exists(RefType s |
s.getName().matches("%Hash%") and not s.getSourceDeclaration().getName() = "IdentityHashMap"
|
exists(MethodAccess ma |
exists(MethodCall ma |
ma.getQualifier().getType() = s and
ma.getArgument(0).getType() = t and
e = ma and

View File

@@ -13,7 +13,7 @@
import java
/** A call to an `equals` method. */
class EqualsCall extends MethodAccess {
class EqualsCall extends MethodCall {
EqualsCall() { this.getMethod() instanceof EqualsMethod }
/**
@@ -22,7 +22,7 @@ class EqualsCall extends MethodAccess {
*/
predicate whitelisted() {
// Allow tests and assertions to verify that `equals` methods return `false`.
this.getParent*().(MethodAccess).getMethod().getName().matches("assert%") or
this.getParent*().(MethodCall).getMethod().getName().matches("assert%") or
this.getEnclosingStmt() instanceof AssertStmt
}

View File

@@ -32,7 +32,7 @@ predicate hasTypeTest(Variable v) {
or
any(ClassExpr c).getExpr() = v.getAnAccess()
or
exists(MethodAccess ma |
exists(MethodCall ma |
ma.getMethod().getName() = "getClass" and
ma.getQualifier() = v.getAnAccess()
)
@@ -71,7 +71,7 @@ where
not hasTypeTest(p) and
// If the parameter is passed to a method for which we don't have the source
// we assume it's ok
not exists(MethodAccess ma |
not exists(MethodCall ma |
not exists(ma.getMethod().getBody()) and
ma.getAnArgument() = p.getAnAccess()
)

View File

@@ -30,7 +30,7 @@ class ReferenceEqualityTestOnObject extends ReferenceEqualityTest {
from ReferenceEqualityTestOnObject scw
where
not exists(Variable left, Variable right, MethodAccess equals |
not exists(Variable left, Variable right, MethodCall equals |
left = scw.getLeftOperand().(VarAccess).getVariable() and
right = scw.getRightOperand().(VarAccess).getVariable() and
scw.getEnclosingCallable() = equals.getEnclosingCallable() and

View File

@@ -21,7 +21,7 @@ class StringValue extends Expr {
exists(Method intern |
intern.getDeclaringType() instanceof TypeString and
intern.hasName("intern") and
this.(MethodAccess).getMethod() = intern
this.(MethodCall).getMethod() = intern
)
or
// Ternary conditional operator.
@@ -35,7 +35,7 @@ class StringValue extends Expr {
variableValuesInterned(this.(VarAccess).getVariable())
or
// Method accesses whose results are all interned.
forex(ReturnStmt rs | rs.getEnclosingCallable() = this.(MethodAccess).getMethod() |
forex(ReturnStmt rs | rs.getEnclosingCallable() = this.(MethodCall).getMethod() |
rs.getResult().(StringValue).isInterned()
)
}

View File

@@ -23,8 +23,8 @@ class SleepMethod extends Method {
}
}
class SleepMethodAccess extends MethodAccess {
SleepMethodAccess() { this.getMethod() instanceof SleepMethod }
class SleepMethodCall extends MethodCall {
SleepMethodCall() { this.getMethod() instanceof SleepMethod }
}
class WaitMethod extends Method {
@@ -48,7 +48,7 @@ class CommunicationMethod extends Method {
predicate callsCommunicationMethod(Method source) {
source instanceof CommunicationMethod
or
exists(MethodAccess a, Method overridingMethod, Method target |
exists(MethodCall a, Method overridingMethod, Method target |
callsCommunicationMethod(overridingMethod) and
overridingMethod.overridesOrInstantiates*(target) and
target = a.getMethod() and
@@ -57,13 +57,13 @@ predicate callsCommunicationMethod(Method source) {
}
class DangerStmt extends Stmt {
DangerStmt() { exists(SleepMethodAccess sleep | sleep.getEnclosingStmt() = this) }
DangerStmt() { exists(SleepMethodCall sleep | sleep.getEnclosingStmt() = this) }
}
from WhileStmt s, DangerStmt d
where
d.getEnclosingStmt+() = s and
not exists(MethodAccess call | callsCommunicationMethod(call.getMethod()) |
not exists(MethodCall call | callsCommunicationMethod(call.getMethod()) |
call.getEnclosingStmt().getEnclosingStmt*() = s
)
select d, "Prefer wait/notify or java.util.concurrent to communicate between threads."

View File

@@ -26,7 +26,7 @@ class ConditionInterface extends Interface {
ConditionInterface() { this.hasQualifiedName("java.util.concurrent.locks", "Condition") }
}
from MethodAccess ma, ConditionInterface condition
from MethodCall ma, ConditionInterface condition
where
ma.getMethod() instanceof WaitMethod and
ma.getQualifier().getType().(RefType).hasSupertype*(condition)

View File

@@ -22,7 +22,7 @@ class RunMethod extends Method {
}
}
from MethodAccess m, RunMethod run
from MethodCall m, RunMethod run
where
m.getMethod() = run and
not m.getEnclosingCallable() instanceof RunMethod

View File

@@ -19,7 +19,7 @@ where
(f.isPublic() or f.isProtected()) and
dateFormat.hasQualifiedName("java.text", "DateFormat") and
f.getType().(RefType).hasSupertype*(dateFormat) and
exists(MethodAccess m | m.getQualifier().(VarAccess).getVariable() = f)
exists(MethodCall m | m.getQualifier().(VarAccess).getVariable() = f)
select f,
"Found static field of type " + f.getType().getName() + " in " + f.getDeclaringType().getName() +
"."

View File

@@ -24,8 +24,8 @@ predicate whitelistedMethod(Method m) {
class SideEffect extends Expr {
SideEffect() {
this instanceof MethodAccess and
not whitelistedMethod(this.(MethodAccess).getMethod())
this instanceof MethodCall and
not whitelistedMethod(this.(MethodCall).getMethod())
or
this.(Assignment).getDest() instanceof FieldAccess
}

View File

@@ -23,14 +23,14 @@ predicate withinInitializer(Expr e) {
e.getEnclosingCallable() instanceof Constructor
}
predicate locallySynchronized(MethodAccess ma) {
predicate locallySynchronized(MethodCall ma) {
ma.getEnclosingStmt().getEnclosingStmt+() instanceof SynchronizedStmt
}
predicate hasUnsynchronizedCall(Method m) {
m.isPublic() and not m.isSynchronized()
or
exists(MethodAccess ma, Method caller |
exists(MethodCall ma, Method caller |
ma.getMethod() = m and caller = ma.getEnclosingCallable()
|
hasUnsynchronizedCall(caller) and

View File

@@ -61,12 +61,12 @@ class ValidSynchStmt extends Stmt {
exists(TryStmt try, LockObjectField lockField |
this = try.getBlock() and
lockField.getType().(RefType).hasQualifiedName("java.util.concurrent.locks", "ReentrantLock") and
exists(MethodAccess lockAction |
exists(MethodCall lockAction |
lockAction.getQualifier() = lockField.getAnAccess() and
lockAction.getMethod().getName() = "lock" and
dominates(lockAction, this)
) and
exists(MethodAccess unlockAction |
exists(MethodCall unlockAction |
unlockAction.getQualifier() = lockField.getAnAccess() and
unlockAction.getMethod().getName() = "unlock" and
postDominates(unlockAction, this)

View File

@@ -20,7 +20,7 @@ import java
* `super.m(x, y, z)`, possibly wrapped in one or more casts and/or parentheses.
*/
predicate delegatingSuperCall(Expr e, Method target) {
exists(MethodAccess call | call = e |
exists(MethodCall call | call = e |
call.getQualifier() instanceof SuperAccess and
call.getCallee() = target and
forall(Expr arg | arg = call.getAnArgument() | arg instanceof VarAccess)

View File

@@ -14,15 +14,15 @@
import java
class InvokeInterfaceOrVirtualMethodAccess extends MethodAccess {
InvokeInterfaceOrVirtualMethodAccess() {
class InvokeInterfaceOrVirtualMethodCall extends MethodCall {
InvokeInterfaceOrVirtualMethodCall() {
this.getMethod().getDeclaringType() instanceof Interface or
not this.hasQualifier() or
not this.getQualifier() instanceof SuperAccess
}
}
from InvokeInterfaceOrVirtualMethodAccess ma, Method m
from InvokeInterfaceOrVirtualMethodCall ma, Method m
where
ma.getMethod() = m and
m.hasName("notify") and

View File

@@ -48,7 +48,7 @@ private predicate synchronizedCallable(Callable c) {
c.isSynchronized()
or
c.isPrivate() and
forall(MethodAccess parent | parent.getCallee() = c |
forall(MethodCall parent | parent.getCallee() = c |
synchronizedThisAccess(parent, c.getDeclaringType())
)
}
@@ -60,7 +60,7 @@ private predicate synchronizedCallable(Callable c) {
* example, if the method call is `MyClass.wait()`, then the predicate
* holds if there is an enclosing synchronization on `MyClass.this`.
*/
private predicate synchronizedThisAccess(MethodAccess ma, Type thisType) {
private predicate synchronizedThisAccess(MethodCall ma, Type thisType) {
// Are we inside a synchronized method?
exists(Callable c |
c = ma.getEnclosingCallable() and
@@ -90,11 +90,11 @@ predicate synchronizedVarAccess(VarAccess x) {
}
/**
* This predicate holds if the `MethodAccess` is a qualified call,
* This predicate holds if the `MethodCall` is a qualified call,
* such as `this.wait()`, and it is not inside a synchronized statement
* or method.
*/
private predicate unsynchronizedExplicitThisAccess(MethodAccess ma) {
private predicate unsynchronizedExplicitThisAccess(MethodCall ma) {
exists(ThisAccess x |
x = ma.getQualifier() and
not synchronizedThisAccess(ma, x.getType())
@@ -102,27 +102,27 @@ private predicate unsynchronizedExplicitThisAccess(MethodAccess ma) {
}
/**
* Holds if the `MethodAccess` is an unqualified call,
* Holds if the `MethodCall` is an unqualified call,
* such as `wait()`, and it is not inside a synchronized statement
* or method.
*/
private predicate unsynchronizedImplicitThisAccess(MethodAccess ma) {
private predicate unsynchronizedImplicitThisAccess(MethodCall ma) {
not ma.hasQualifier() and
not synchronizedThisAccess(ma, ma.getEnclosingCallable().getDeclaringType())
}
/**
* Holds if the `MethodAccess` is on a variable,
* Holds if the `MethodCall` is on a variable,
* such as `x.wait()`, and it is not inside a synchronized statement.
*/
private predicate unsynchronizedVarAccess(MethodAccess ma) {
private predicate unsynchronizedVarAccess(MethodCall ma) {
exists(VarAccess x |
x = ma.getQualifier() and
not synchronizedVarAccess(x)
)
}
from MethodAccess ma, Method m
from MethodCall ma, Method m
where
m = ma.getMethod() and
m instanceof MethodRequiresSynch and

View File

@@ -20,10 +20,10 @@ class PriorityMethod extends Method {
}
}
class PriorityMethodAccess extends MethodAccess {
PriorityMethodAccess() { this.getMethod() instanceof PriorityMethod }
class PriorityMethodCall extends MethodCall {
PriorityMethodCall() { this.getMethod() instanceof PriorityMethod }
}
from PriorityMethodAccess ma
from PriorityMethodCall ma
where ma.getCompilationUnit().fromSource()
select ma, "Avoid using thread priorities. The effect is unpredictable and not portable."

View File

@@ -14,7 +14,7 @@
import java
from MethodAccess ma, Method sleep
from MethodCall ma, Method sleep
where
ma.getMethod() = sleep and
sleep.hasName("sleep") and

View File

@@ -26,7 +26,7 @@ private predicate cannotBeExtended(RefType t) {
not exists(RefType sub | sub != t | sub.getAnAncestor() = t)
}
from MethodAccess m, Constructor c, Class clazz
from MethodCall m, Constructor c, Class clazz
where
m.getMethod().getDeclaringType().hasQualifiedName("java.lang", "Thread") and
m.getMethod().getName() = "start" and

View File

@@ -39,22 +39,22 @@ class LockType extends RefType {
result.hasName("isHeldByCurrentThread")
}
MethodAccess getLockAccess() {
MethodCall getLockAccess() {
result.getMethod() = this.getLockMethod() and
// Not part of a Mockito verification call
not result instanceof MockitoVerifiedMethodAccess
not result instanceof MockitoVerifiedMethodCall
}
MethodAccess getUnlockAccess() {
MethodCall getUnlockAccess() {
result.getMethod() = this.getUnlockMethod() and
// Not part of a Mockito verification call
not result instanceof MockitoVerifiedMethodAccess
not result instanceof MockitoVerifiedMethodCall
}
MethodAccess getIsHeldByCurrentThreadAccess() {
MethodCall getIsHeldByCurrentThreadAccess() {
result.getMethod() = this.getIsHeldByCurrentThreadMethod() and
// Not part of a Mockito verification call
not result instanceof MockitoVerifiedMethodAccess
not result instanceof MockitoVerifiedMethodCall
}
}
@@ -147,7 +147,7 @@ predicate blockIsLocked(LockType t, BasicBlock src, BasicBlock b, int locks) {
)
}
from Callable c, LockType t, BasicBlock src, BasicBlock exit, MethodAccess lock
from Callable c, LockType t, BasicBlock src, BasicBlock exit, MethodCall lock
where
// Restrict results to those methods that actually attempt to unlock.
t.getUnlockAccess().getEnclosingCallable() = c and

View File

@@ -20,7 +20,7 @@ class WaitMethod extends Method {
}
}
from MethodAccess ma
from MethodCall ma
where
ma.getMethod() instanceof WaitMethod and
not ma.getEnclosingStmt().getEnclosingStmt*() instanceof LoopStmt

View File

@@ -21,7 +21,7 @@ class Synched extends Stmt {
}
}
from MethodAccess ma, SynchronizedStmt synch
from MethodCall ma, SynchronizedStmt synch
where
ma.getMethod().hasName("wait") and
ma.getMethod().getDeclaringType().hasQualifiedName("java.lang", "Object") and

View File

@@ -20,11 +20,11 @@ class YieldMethod extends Method {
}
}
class YieldMethodAccess extends MethodAccess {
YieldMethodAccess() { this.getMethod() instanceof YieldMethod }
class YieldMethodCall extends MethodCall {
YieldMethodCall() { this.getMethod() instanceof YieldMethod }
}
from YieldMethodAccess yield
from YieldMethodCall yield
where yield.getCompilationUnit().fromSource()
select yield,
"Do not use Thread.yield(). It is non-portable and will most likely not have the desired effect."

View File

@@ -31,7 +31,7 @@ where
exists(Method original | adapter = original.getDeclaringType() | m.getName() = original.getName()) and
not exists(Method overridden | adapter = overridden.getDeclaringType() | m.overrides(overridden)) and
// The method is not used for any other purpose.
not exists(MethodAccess ma | ma.getMethod() = m)
not exists(MethodCall ma | ma.getMethod() = m)
select m,
"Method " + m.getName() + " attempts to override a method in " + adapter.getName() +
", but does not have the same argument types. " + m.getName() +

View File

@@ -13,7 +13,7 @@
import java
from MethodAccess ma, Method m, MainMethod main
from MethodCall ma, Method m, MainMethod main
where
ma.getQualifier().getType().getCompilationUnit().getPackage().getName().matches("javax.swing%") and
(

View File

@@ -12,7 +12,7 @@
import java
from MethodAccess ma, Method changecase
from MethodCall ma, Method changecase
where
(
changecase.hasName("toUpperCase") or

View File

@@ -27,7 +27,7 @@ private FieldRead nonFinalFieldRead(Callable m, Field f) {
not f.isFinal()
}
private MethodAccess unqualifiedCallToNonAbstractMethod(Constructor c, Method m) {
private MethodCall unqualifiedCallToNonAbstractMethod(Constructor c, Method m) {
result.getEnclosingCallable() = c and
(
not exists(result.getQualifier()) or
@@ -38,7 +38,7 @@ private MethodAccess unqualifiedCallToNonAbstractMethod(Constructor c, Method m)
}
from
Constructor c, MethodAccess ma, Method m, Method n, Field f, FieldRead fa, Constructor d,
Constructor c, MethodCall ma, Method m, Method n, Field f, FieldRead fa, Constructor d,
FieldWrite fw
where
// Method access in a constructor

View File

@@ -27,21 +27,21 @@ class ArrayLengthRead extends FieldRead, SizeOfContainer {
}
/** An access to `String.length()`. */
class StringLengthRead extends MethodAccess, SizeOfContainer {
class StringLengthRead extends MethodCall, SizeOfContainer {
StringLengthRead() { this.getMethod() instanceof StringLengthMethod }
override string getContainerKind() { result = "a string" }
}
/** An access to `Collection.size()`. */
class CollectionSizeCall extends MethodAccess, SizeOfContainer {
class CollectionSizeCall extends MethodCall, SizeOfContainer {
CollectionSizeCall() { this.getMethod() instanceof CollectionSizeMethod }
override string getContainerKind() { result = "a collection" }
}
/** An access to `Map.size()`. */
class MapSizeCall extends MethodAccess, SizeOfContainer {
class MapSizeCall extends MethodCall, SizeOfContainer {
MapSizeCall() { this.getMethod() instanceof MapSizeMethod }
override string getContainerKind() { result = "a map" }

View File

@@ -18,7 +18,7 @@ import java
class DangerousExpression extends Expr {
DangerousExpression() {
exists(Expr e | this = e.getParent*() |
e instanceof MethodAccess or
e instanceof MethodCall or
e instanceof ArrayAccess or
exists(e.(FieldAccess).getQualifier())
)

View File

@@ -12,7 +12,7 @@
import java
from MethodAccess c, Method m, ParameterizedClass p, AnnotationType t
from MethodCall c, Method m, ParameterizedClass p, AnnotationType t
where
c.getMethod() = m and
m.hasName("isAnnotationPresent") and

View File

@@ -42,8 +42,8 @@ private predicate closeableType(RefType t) {
* An access to a method on a type in the 'java.sql` package that creates a closeable object in the `java.sql` package.
* For example, `PreparedStatement.executeQuery()` or `Connection.prepareStatement(String)`.
*/
class SqlResourceOpeningMethodAccess extends MethodAccess {
SqlResourceOpeningMethodAccess() {
class SqlResourceOpeningMethodCall extends MethodCall {
SqlResourceOpeningMethodCall() {
exists(Method m | this.getMethod() = m |
m.getDeclaringType().hasQualifiedName("java.sql", _) and
m.getReturnType().(RefType).hasQualifiedName("java.sql", _) and
@@ -60,7 +60,7 @@ class SqlResourceOpeningMethodAccess extends MethodAccess {
class CloseableInitExpr extends Expr {
CloseableInitExpr() {
this instanceof ClassInstanceExpr or
this instanceof SqlResourceOpeningMethodAccess
this instanceof SqlResourceOpeningMethodCall
}
}
@@ -86,7 +86,7 @@ private predicate closeableInit(Expr e, Expr parent) {
)
)
or
exists(SqlResourceOpeningMethodAccess ma | ma = e and parent = e)
exists(SqlResourceOpeningMethodCall ma | ma = e and parent = e)
or
exists(LocalVariableDecl v, Expr f | e = v.getAnAccess() and flowsInto(f, v) |
closeableInit(f, parent)
@@ -218,7 +218,7 @@ private predicate closeCalled(Variable v) {
exists(TryStmt try | try.getAResourceVariable() = v)
or
// Otherwise, there should be an explicit call to a method whose name contains "close".
exists(MethodAccess e |
exists(MethodCall e |
v = getCloseableVariable(_) or v instanceof Parameter or v instanceof LocalVariableDecl
|
e.getMethod().getName().toLowerCase().matches("%close%") and
@@ -263,7 +263,7 @@ private predicate closedResource(CloseableInitExpr cie) {
}
private predicate immediatelyClosed(ClassInstanceExpr cie) {
exists(MethodAccess ma | ma.getQualifier() = cie | ma.getMethod().hasName("close"))
exists(MethodCall ma | ma.getQualifier() = cie | ma.getMethod().hasName("close"))
}
/**
@@ -305,10 +305,10 @@ predicate noNeedToClose(CloseableInitExpr cie) {
flowsInto(sqlStmt, v) and
closedResource(sqlStmt) and
cie.getType() instanceof TypeResultSet and
cie.(SqlResourceOpeningMethodAccess).getQualifier() = v.getAnAccess()
cie.(SqlResourceOpeningMethodCall).getQualifier() = v.getAnAccess()
)
or
exists(MethodAccess ma | cie.(ClassInstanceExpr).getAnArgument() = ma |
exists(MethodCall ma | cie.(ClassInstanceExpr).getAnArgument() = ma |
ma.getMethod() instanceof ServletResponseGetOutputStreamMethod or
ma.getMethod() instanceof ServletResponseGetWriterMethod or
ma.getMethod() instanceof ServletRequestGetBodyMethod

View File

@@ -35,8 +35,8 @@ private predicate nonChainingReturn(Method m, ReturnStmt ret) {
ret.getResult().getType() != m.getDeclaringType()
or
// A method call to the wrong method is returned.
ret.getResult() instanceof MethodAccess and
exists(MethodAccess delegateCall, Method delegate |
ret.getResult() instanceof MethodCall and
exists(MethodCall delegateCall, Method delegate |
delegateCall = ret.getResult() and
delegate = delegateCall.getMethod()
|
@@ -47,7 +47,7 @@ private predicate nonChainingReturn(Method m, ReturnStmt ret) {
not hasDescendant(m.getReturnType(), delegate.getReturnType())
or
// A method on the wrong object is called.
not delegateCall.isOwnMethodAccess()
not delegateCall.isOwnMethodCall()
or
nonChaining(delegate)
)
@@ -55,6 +55,6 @@ private predicate nonChainingReturn(Method m, ReturnStmt ret) {
// Something else is returned.
not (
ret.getResult() instanceof ThisAccess or
ret.getResult() instanceof MethodAccess
ret.getResult() instanceof MethodCall
)
}

View File

@@ -33,7 +33,7 @@ predicate exclude(Method m) {
* - is different from `callToCheck`, and
* - is not a call to an excluded method.
*/
predicate checkExpr(MethodAccess callToCheck, MethodAccess otherCall, string operation, Variable v) {
predicate checkExpr(MethodCall callToCheck, MethodCall otherCall, string operation, Variable v) {
not exclude(otherCall.getMethod()) and
v.getAnAssignedValue() = callToCheck and
otherCall != callToCheck and
@@ -47,7 +47,7 @@ predicate checkExpr(MethodAccess callToCheck, MethodAccess otherCall, string ope
/**
* Holds if `operation` is implicitly called on `v`, and `v` is assigned the result of `callToCheck`.
*/
predicate implicitCheckExpr(MethodAccess callToCheck, string operation, Variable v) {
predicate implicitCheckExpr(MethodCall callToCheck, string operation, Variable v) {
exists(TryStmt try, LocalVariableDeclExpr decl |
try.getAResourceDecl().getAVariable() = decl and
decl.getVariable() = v and
@@ -62,7 +62,7 @@ predicate implicitCheckExpr(MethodAccess callToCheck, string operation, Variable
Expr getChainedAccess(Variable v) {
result = v.getAnAccess()
or
exists(MethodAccess chainedAccess | chainedAccess.getQualifier() = getChainedAccess(v) |
exists(MethodCall chainedAccess | chainedAccess.getQualifier() = getChainedAccess(v) |
designedForChaining(chainedAccess.getMethod()) and result = chainedAccess
)
}
@@ -70,7 +70,7 @@ Expr getChainedAccess(Variable v) {
/**
* The result of `ma` and a call to a method named `operation` are both assigned to the same variable.
*/
predicate checkedFunctionCall(MethodAccess ma, string operation) {
predicate checkedFunctionCall(MethodCall ma, string operation) {
relevantFunctionCall(ma, _) and
exists(Variable v | not v instanceof Field |
v.getAnAssignedValue() = ma and
@@ -81,24 +81,24 @@ predicate checkedFunctionCall(MethodAccess ma, string operation) {
/**
* The method access `ma` is a call to `m` where the result is assigned.
*/
predicate relevantFunctionCall(MethodAccess ma, Method m) {
predicate relevantFunctionCall(MethodCall ma, Method m) {
ma.getMethod() = m and
exists(Variable v | v.getAnAssignedValue() = ma) and
not okToIgnore(ma)
}
predicate okToIgnore(MethodAccess ma) { not ma.getCompilationUnit().fromSource() }
predicate okToIgnore(MethodCall ma) { not ma.getCompilationUnit().fromSource() }
predicate functionStats(Method m, string operation, int used, int total, int percentage) {
m.getReturnType() instanceof RefType and
// Calls to `m` where we also perform `operation`.
used = strictcount(MethodAccess ma | checkedFunctionCall(ma, operation) and m = ma.getMethod()) and
used = strictcount(MethodCall ma | checkedFunctionCall(ma, operation) and m = ma.getMethod()) and
// Calls to `m`.
total = strictcount(MethodAccess ma | relevantFunctionCall(ma, m)) and
total = strictcount(MethodCall ma | relevantFunctionCall(ma, m)) and
percentage = used * 100 / total
}
from MethodAccess unchecked, Method m, string operation, int percent
from MethodCall unchecked, Method m, string operation, int percent
where
relevantFunctionCall(unchecked, m) and
not checkedFunctionCall(unchecked, operation) and

View File

@@ -16,7 +16,7 @@
import java
import Chaining
predicate checkedMethodCall(MethodAccess ma) {
predicate checkedMethodCall(MethodCall ma) {
relevantMethodCall(ma, _) and
not ma instanceof ValueDiscardingExpr
}
@@ -73,31 +73,31 @@ predicate isMustBeQualifierMockingMethod(Method m) {
m.hasName("verify")
}
predicate relevantMethodCall(MethodAccess ma, Method m) {
predicate relevantMethodCall(MethodCall ma, Method m) {
// For "return value ignored", all method calls are relevant.
not ma.getFile().isKotlinSourceFile() and
ma.getMethod() = m and
not m.getReturnType().hasName("void") and
(not isMockingMethod(m) or isMustBeQualifierMockingMethod(m)) and
not isMockingMethod(ma.getQualifier().(MethodAccess).getMethod())
not isMockingMethod(ma.getQualifier().(MethodCall).getMethod())
}
predicate methodStats(Method m, int used, int total, int percentage) {
used = strictcount(MethodAccess ma | checkedMethodCall(ma) and m = ma.getMethod()) and
total = strictcount(MethodAccess ma | relevantMethodCall(ma, m)) and
used = strictcount(MethodCall ma | checkedMethodCall(ma) and m = ma.getMethod()) and
total = strictcount(MethodCall ma | relevantMethodCall(ma, m)) and
percentage = used * 100 / total
}
int chainedUses(Method m) {
result =
count(MethodAccess ma, MethodAccess qual |
count(MethodCall ma, MethodCall qual |
ma.getMethod() = m and
ma.getQualifier() = qual and
qual.getMethod() = m
)
}
from MethodAccess unchecked, Method m, int percent, int total
from MethodCall unchecked, Method m, int percent, int total
where
relevantMethodCall(unchecked, m) and
not checkedMethodCall(unchecked) and

View File

@@ -78,7 +78,7 @@ where
ssa.getCfgNode().(Expr).getParent*() = loop.(ForStmt).getAnInit()
) and
// And `cond` does not use method calls, field reads, or array reads.
not exists(MethodAccess ma | ma.getParent*() = cond) and
not exists(MethodCall ma | ma.getParent*() = cond) and
not exists(FieldRead fa |
// Ignore if field is final
not fa.getField().isFinal() and