Skip to content

Commit 2a932f0

Browse files
authored
Merge pull request #20328 from michaelnebel/java/ql4ql
Java: Fix some Ql4Ql violations.
2 parents ab641b3 + a732b36 commit 2a932f0

File tree

23 files changed

+65
-73
lines changed

23 files changed

+65
-73
lines changed

java/ql/lib/experimental/quantum/JCA.qll

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -269,7 +269,7 @@ module JCAModel {
269269
}
270270

271271
/**
272-
* Data-flow configuration modelling flow from a cipher string literal to a cipher algorithm consumer.
272+
* Data-flow configuration modeling flow from a cipher string literal to a cipher algorithm consumer.
273273
*/
274274
private module CipherAlgorithmStringToCipherConsumerConfig implements DataFlow::ConfigSig {
275275
predicate isSource(DataFlow::Node src) { src.asExpr() instanceof CipherStringLiteral }
@@ -404,9 +404,7 @@ module JCAModel {
404404
* For example, in `Cipher.getInstance(algorithm)`, this class represents `algorithm`.
405405
*/
406406
class CipherGetInstanceAlgorithmArg extends CipherAlgorithmValueConsumer instanceof Expr {
407-
CipherGetInstanceCall call;
408-
409-
CipherGetInstanceAlgorithmArg() { this = call.getAlgorithmArg() }
407+
CipherGetInstanceAlgorithmArg() { this = any(CipherGetInstanceCall call).getAlgorithmArg() }
410408

411409
override Crypto::ConsumerInputDataFlowNode getInputNode() { result.asExpr() = this }
412410

@@ -1333,7 +1331,7 @@ module JCAModel {
13331331
}
13341332

13351333
/**
1336-
* Data-flow configuration modelling flow from a key agreement string literal to a key agreement algorithm consumer.
1334+
* Data-flow configuration modeling flow from a key agreement string literal to a key agreement algorithm consumer.
13371335
*/
13381336
private module KeyAgreementAlgorithmStringToConsumerConfig implements DataFlow::ConfigSig {
13391337
predicate isSource(DataFlow::Node src) { src.asExpr() instanceof KeyAgreementStringLiteral }
@@ -1539,11 +1537,9 @@ module JCAModel {
15391537
}
15401538

15411539
class MacOperationCall extends Crypto::MacOperationInstance instanceof MethodCall {
1542-
Expr output;
1543-
15441540
MacOperationCall() {
15451541
super.getMethod().getDeclaringType().hasQualifiedName("javax.crypto", "Mac") and
1546-
(
1542+
exists(Expr output |
15471543
super.getMethod().hasStringSignature(["doFinal()", "doFinal(byte[])"]) and this = output
15481544
or
15491545
super.getMethod().hasStringSignature("doFinal(byte[], int)") and

java/ql/lib/experimental/quantum/Language.qll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ private class ConstantDataSource extends Crypto::GenericConstantSourceInstance i
113113
}
114114

115115
/**
116-
* An instance of random number generation, modelled as the expression
116+
* An instance of random number generation, modeled as the expression
117117
* tied to an output node (i.e., the result of the source of randomness)
118118
*/
119119
abstract class RandomnessInstance extends Crypto::RandomNumberGenerationInstance {

java/ql/lib/printAst.ql

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@ external string selectedSourceFile();
1818

1919
class PrintAstConfigurationOverride extends PrintAstConfiguration {
2020
/**
21-
* Holds if the location matches the selected file in the VS Code extension and
22-
* the element is `fromSource`.
21+
* Holds if the location `l` matches the selected file in the VS Code extension and
22+
* the element `e` is `fromSource`.
2323
*/
2424
override predicate shouldPrint(Element e, Location l) {
2525
super.shouldPrint(e, l) and

java/ql/lib/semmle/code/java/Concurrency.qll

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,8 @@ predicate locallySynchronizedOnThis(Expr e, RefType thisType) {
2626
}
2727

2828
/**
29-
* Holds if `e` is synchronized by a `synchronized` modifier on the enclosing (static) method.
29+
* Holds if `e` is synchronized by a `synchronized` modifier on the enclosing (static) method
30+
* declared in the type `classType`.
3031
*/
3132
predicate locallySynchronizedOnClass(Expr e, RefType classType) {
3233
exists(SynchronizedCallable c | c = e.getEnclosingCallable() |

java/ql/lib/semmle/code/java/Conversions.qll

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -100,12 +100,12 @@ class InvocationConversionContext extends ConversionSite {
100100
* See the Java Language Specification, Section 5.4.
101101
*/
102102
class StringConversionContext extends ConversionSite {
103-
AddExpr a;
104-
105103
StringConversionContext() {
106-
a.getAnOperand() = this and
107-
not this.getType() instanceof TypeString and
108-
a.getAnOperand().getType() instanceof TypeString
104+
exists(AddExpr a |
105+
a.getAnOperand() = this and
106+
not this.getType() instanceof TypeString and
107+
a.getAnOperand().getType() instanceof TypeString
108+
)
109109
}
110110

111111
override Type getConversionTarget() { result instanceof TypeString }

java/ql/lib/semmle/code/java/Statement.qll

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -291,7 +291,7 @@ class TryStmt extends Stmt, @trystmt {
291291
CatchClause getACatchClause() { result.getParent() = this }
292292

293293
/**
294-
* Gets the `catch` clause at the specified (zero-based) position
294+
* Gets the `catch` clause at the specified (zero-based) position `index`
295295
* in this `try` statement.
296296
*/
297297
CatchClause getCatchClause(int index) {
@@ -305,7 +305,7 @@ class TryStmt extends Stmt, @trystmt {
305305
/** Gets a resource variable declaration, if any. */
306306
LocalVariableDeclStmt getAResourceDecl() { result.getParent() = this and result.getIndex() <= -3 }
307307

308-
/** Gets the resource variable declaration at the specified position in this `try` statement. */
308+
/** Gets the resource variable declaration at the specified position `index` in this `try` statement. */
309309
LocalVariableDeclStmt getResourceDecl(int index) {
310310
result = this.getAResourceDecl() and
311311
index = -3 - result.getIndex()
@@ -314,7 +314,7 @@ class TryStmt extends Stmt, @trystmt {
314314
/** Gets a resource expression, if any. */
315315
VarAccess getAResourceExpr() { result.getParent() = this and result.getIndex() <= -3 }
316316

317-
/** Gets the resource expression at the specified position in this `try` statement. */
317+
/** Gets the resource expression at the specified position `index` in this `try` statement. */
318318
VarAccess getResourceExpr(int index) {
319319
result = this.getAResourceExpr() and
320320
index = -3 - result.getIndex()
@@ -323,7 +323,7 @@ class TryStmt extends Stmt, @trystmt {
323323
/** Gets a resource in this `try` statement, if any. */
324324
ExprParent getAResource() { result = this.getAResourceDecl() or result = this.getAResourceExpr() }
325325

326-
/** Gets the resource at the specified position in this `try` statement. */
326+
/** Gets the resource at the specified position `index` in this `try` statement. */
327327
ExprParent getResource(int index) {
328328
result = this.getResourceDecl(index) or result = this.getResourceExpr(index)
329329
}

java/ql/lib/semmle/code/java/dataflow/internal/ContainerFlow.qll

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -470,7 +470,8 @@ private predicate enhancedForStmtStep(Node node1, Node node2, Type containerType
470470
}
471471

472472
/**
473-
* Holds if the step from `node1` to `node2` reads a value from an array.
473+
* Holds if the step from `node1` to `node2` reads a value from an array, where
474+
* the elements are of type `elemType`.
474475
* This covers ordinary array reads as well as array iteration through enhanced
475476
* `for` statements.
476477
*/

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -263,8 +263,8 @@ class Content extends TContent {
263263

264264
/**
265265
* Holds if this element is at the specified location.
266-
* The location spans column `startcolumn` of line `startline` to
267-
* column `endcolumn` of line `endline` in file `filepath`.
266+
* The location spans column `sc` of line `sl` to
267+
* column `ec` of line `el` in file `path`.
268268
* For more information, see
269269
* [Locations](https://codeql.github.com/docs/writing-codeql-queries/providing-locations-in-codeql-queries/).
270270
*/
@@ -362,8 +362,8 @@ class ContentSet instanceof Content {
362362

363363
/**
364364
* Holds if this element is at the specified location.
365-
* The location spans column `startcolumn` of line `startline` to
366-
* column `endcolumn` of line `endline` in file `filepath`.
365+
* The location spans column `sc` of line `sl` to
366+
* column `ec` of line `el` in file `path`.
367367
* For more information, see
368368
* [Locations](https://codeql.github.com/docs/writing-codeql-queries/providing-locations-in-codeql-queries/).
369369
*/

java/ql/lib/semmle/code/java/dataflow/internal/rangeanalysis/SignAnalysisSpecific.qll

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,7 @@ private module Impl {
204204
/** Gets the character value of expression `e`. */
205205
string getCharValue(Expr e) { result = e.(CharacterLiteral).getValue() }
206206

207-
/** Gets the constant `float` value of non-`ConstantIntegerExpr` expressions. */
207+
/** Gets the constant `float` value of non-`ConstantIntegerExpr` expression `e`. */
208208
float getNonIntegerValue(Expr e) {
209209
result = e.(LongLiteral).getValue().toFloat() or
210210
result = e.(FloatLiteral).getValue().toFloat() or
@@ -256,12 +256,12 @@ private module Impl {
256256
exists(EnhancedForStmt for | def = for.getVariable())
257257
}
258258

259-
/** Returns the operand of the operation if `def` is a decrement. */
259+
/** Returns the operand of the operation if `e` is a decrement. */
260260
Expr getDecrementOperand(Element e) {
261261
result = e.(PostDecExpr).getExpr() or result = e.(PreDecExpr).getExpr()
262262
}
263263

264-
/** Returns the operand of the operation if `def` is an increment. */
264+
/** Returns the operand of the operation if `e` is an increment. */
265265
Expr getIncrementOperand(Element e) {
266266
result = e.(PostIncExpr).getExpr() or result = e.(PreIncExpr).getExpr()
267267
}

java/ql/lib/semmle/code/java/frameworks/Mockito.qll

Lines changed: 16 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -223,10 +223,10 @@ class MockitoInjectedField extends MockitoAnnotatedField {
223223
// If there is no initializer for this field, and there is a most mockable constructor,
224224
// then we are doing a parameterized injection of mocks into a most mockable constructor.
225225
result = mockInjectedClass.getAMostMockableConstructor()
226-
else
227-
if this.usingPropertyInjection()
228-
then
229-
// We will call the no-arg constructor if the field wasn't initialized.
226+
else (
227+
this.usingPropertyInjection() and
228+
// We will call the no-arg constructor if the field wasn't initialized.
229+
(
230230
not exists(this.getInitializer()) and
231231
result = mockInjectedClass.getNoArgsConstructor()
232232
or
@@ -241,9 +241,8 @@ class MockitoInjectedField extends MockitoAnnotatedField {
241241
// once, but we instead assume that there are sufficient mocks to go around.
242242
mockedField.getType().(RefType).getAnAncestor() = result.getParameterType(0)
243243
)
244-
else
245-
// There's no instance, and no no-arg constructor we can call, so injection fails.
246-
none()
244+
)
245+
)
247246
)
248247
}
249248

@@ -253,18 +252,16 @@ class MockitoInjectedField extends MockitoAnnotatedField {
253252
* Field injection only occurs if property injection and not constructor injection is used.
254253
*/
255254
Field getASetField() {
256-
if this.usingPropertyInjection()
257-
then
258-
result = this.getMockInjectedClass().getASetField() and
259-
exists(MockitoMockedField mockedField |
260-
mockedField.getDeclaringType() = this.getDeclaringType() and
261-
mockedField.isValid()
262-
|
263-
// We make a simplifying assumption here - in theory, each mock can only be injected
264-
// once, but we instead assume that there are sufficient mocks to go around.
265-
mockedField.getType().(RefType).getAnAncestor() = result.getType()
266-
)
267-
else none()
255+
this.usingPropertyInjection() and
256+
result = this.getMockInjectedClass().getASetField() and
257+
exists(MockitoMockedField mockedField |
258+
mockedField.getDeclaringType() = this.getDeclaringType() and
259+
mockedField.isValid()
260+
|
261+
// We make a simplifying assumption here - in theory, each mock can only be injected
262+
// once, but we instead assume that there are sufficient mocks to go around.
263+
mockedField.getType().(RefType).getAnAncestor() = result.getType()
264+
)
268265
}
269266
}
270267

0 commit comments

Comments
 (0)