Files
codeql/java/ql/src/Advisory/Deprecated Code/AvoidDeprecatedCallableAccess.ql
2018-10-11 11:31:37 +02:00

29 lines
911 B
Plaintext

/**
* @name Deprecated method or constructor invocation
* @description Using a method or constructor that has been marked as deprecated may be dangerous or
* fail to take advantage of a better method or constructor.
* @kind problem
* @problem.severity recommendation
* @precision high
* @id java/deprecated-call
* @tags maintainability
* non-attributable
* external/cwe/cwe-477
*/
import java
private predicate isDeprecatedCallable(Callable c) {
c.getAnAnnotation() instanceof DeprecatedAnnotation or
exists(c.getDoc().getJavadoc().getATag("@deprecated"))
}
from Call ca, Callable c
where
ca.getCallee() = c and
isDeprecatedCallable(c) and
// Exclude deprecated calls from within deprecated code.
not isDeprecatedCallable(ca.getCaller())
select ca, "Invoking $@ should be avoided because it has been deprecated.", c,
c.getDeclaringType() + "." + c.getName()