mirror of
https://github.com/github/codeql.git
synced 2025-12-24 12:46:34 +01:00
23 lines
629 B
Plaintext
23 lines
629 B
Plaintext
/**
|
|
* @name Inefficient empty string test
|
|
* @description Checking a string for equality with an empty string is inefficient.
|
|
* @kind problem
|
|
* @problem.severity recommendation
|
|
* @precision high
|
|
* @id java/inefficient-empty-string-test
|
|
* @tags efficiency
|
|
* maintainability
|
|
*/
|
|
|
|
import java
|
|
|
|
from MethodAccess mc
|
|
where
|
|
mc.getQualifier().getType() instanceof TypeString and
|
|
mc.getMethod().hasName("equals") and
|
|
(
|
|
mc.getArgument(0).(StringLiteral).getValue() = "" or
|
|
mc.getQualifier().(StringLiteral).getValue() = ""
|
|
)
|
|
select mc, "Inefficient comparison to empty string, check for zero length instead."
|