Skip to content

Commit da0a7f3

Browse files
committed
Move existing value-preserving methods to use ValuePreservingCallable
1 parent 40b0f68 commit da0a7f3

File tree

1 file changed

+24
-24
lines changed

1 file changed

+24
-24
lines changed

java/ql/src/semmle/code/java/dataflow/internal/DataFlowUtil.qll

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -398,6 +398,30 @@ abstract class FluentMethod extends ValuePreservingCallable {
398398
override predicate returnsValue(int arg) { arg = -1 }
399399
}
400400

401+
private class StandardLibraryValuePreservingCallable extends ValuePreservingCallable {
402+
int returnsArgNo;
403+
404+
StandardLibraryValuePreservingCallable() {
405+
this.getDeclaringType().hasQualifiedName("java.util", "Objects") and
406+
(
407+
this.hasName(["requireNonNull", "requireNonNullElseGet"]) and returnsArgNo = 0
408+
or
409+
this.hasName("requireNonNullElse") and returnsArgNo = [0 .. this.getNumberOfParameters() - 1]
410+
or
411+
this.hasName("toString") and returnsArgNo = 1
412+
)
413+
or
414+
this.getDeclaringType()
415+
.getSourceDeclaration()
416+
.getASourceSupertype*()
417+
.hasQualifiedName("java.util", "Stack") and
418+
this.hasName("push") and
419+
returnsArgNo = 0
420+
}
421+
422+
override predicate returnsValue(int argNo) { argNo = returnsArgNo }
423+
}
424+
401425
/**
402426
* INTERNAL: do not use.
403427
*
@@ -448,30 +472,6 @@ predicate simpleLocalFlowStep(Node node1, Node node2) {
448472
argNo = -1 and node1.asExpr() = ma.getQualifier()
449473
)
450474
)
451-
or
452-
exists(MethodAccess ma, Method m |
453-
ma = node2.asExpr() and
454-
m = ma.getMethod() and
455-
m.getDeclaringType().hasQualifiedName("java.util", "Objects") and
456-
(
457-
m.hasName(["requireNonNull", "requireNonNullElseGet"]) and node1.asExpr() = ma.getArgument(0)
458-
or
459-
m.hasName("requireNonNullElse") and node1.asExpr() = ma.getAnArgument()
460-
or
461-
m.hasName("toString") and node1.asExpr() = ma.getArgument(1)
462-
)
463-
)
464-
or
465-
exists(MethodAccess ma, Method m |
466-
ma = node2.asExpr() and
467-
m = ma.getMethod() and
468-
m.getDeclaringType()
469-
.getSourceDeclaration()
470-
.getASourceSupertype*()
471-
.hasQualifiedName("java.util", "Stack") and
472-
m.hasName("push") and
473-
node1.asExpr() = ma.getArgument(0)
474-
)
475475
}
476476

477477
/**

0 commit comments

Comments
 (0)