mirror of
https://github.com/github/codeql.git
synced 2026-04-28 18:25:24 +02:00
Unused local query: exclude mandatory declarations
This commit is contained in:
@@ -11,22 +11,13 @@
|
||||
import java
|
||||
import DeadLocals
|
||||
|
||||
predicate exceptionVariable(LocalVariableDeclExpr ve) {
|
||||
exists(CatchClause catch | catch.getVariable() = ve)
|
||||
}
|
||||
|
||||
predicate enhancedForVariable(LocalVariableDeclExpr ve) {
|
||||
exists(EnhancedForStmt for | for.getVariable() = ve)
|
||||
}
|
||||
|
||||
from LocalVariableDeclExpr ve, LocalVariableDecl v
|
||||
where
|
||||
v = ve.getVariable() and
|
||||
not assigned(v) and
|
||||
not read(v) and
|
||||
(not exists(ve.getInit()) or exprHasNoEffect(ve.getInit())) and
|
||||
// Remove contexts where Java forces a variable declaration: enhanced-for and catch clauses.
|
||||
// Remove contexts where Java forces a variable declaration: enhanced-for, catch clauses and pattern cases.
|
||||
// Rules about catch clauses belong in an exception handling query
|
||||
not exceptionVariable(ve) and
|
||||
not enhancedForVariable(ve)
|
||||
not ve.hasImplicitInit()
|
||||
select v, "Variable " + v.getName() + " is not used."
|
||||
|
||||
Reference in New Issue
Block a user