mirror of
https://github.com/github/codeql.git
synced 2026-02-08 19:21:07 +01:00
Query: Noninitial imports of the standard library
Finds a single result in
```
semmle.code.java.dataflow.internal.rangeanalysis.SignAnalysisSpecific.qll
```
which starts with
```ql
module Private {
import semmle.code.java.dataflow.RangeUtils as RU
private import semmle.code.java.dataflow.SSA as Ssa
private import semmle.code.java.controlflow.Guards as G
private import java as J
private import Sign
...
```
This commit is contained in:
30
ql/src/queries/performance/NonInitialStdLibImport.ql
Normal file
30
ql/src/queries/performance/NonInitialStdLibImport.ql
Normal file
@@ -0,0 +1,30 @@
|
||||
/**
|
||||
* @name Standard library is not the first import
|
||||
* @description Importing other libraries before the standard library can cause a change in
|
||||
* evaluation order and may lead to performance errors.
|
||||
* @kind problem
|
||||
* @problem.severity error
|
||||
* @id ql/noninitial-stdlib-import
|
||||
* @tags performance
|
||||
* @precision high
|
||||
*/
|
||||
|
||||
import ql
|
||||
|
||||
predicate isStdLibImport(Import i, string name) {
|
||||
name = i.getQualifiedName(0) and
|
||||
i.getLocation().getFile().getRelativePath().matches(name + "%") and
|
||||
not exists(i.getQualifiedName(1))
|
||||
}
|
||||
|
||||
Import importBefore(Import i) {
|
||||
exists(Module m, int bi, int ii |
|
||||
result = m.getMember(bi) and
|
||||
i = m.getMember(ii) and
|
||||
bi < ii
|
||||
)
|
||||
}
|
||||
|
||||
from Import i
|
||||
where isStdLibImport(i, _) and exists(importBefore(i))
|
||||
select i, "This import may cause reevaluation to occur, as there are other imports preceding it"
|
||||
Reference in New Issue
Block a user