Files
codeql/java/ql/src/Advisory/Declarations/NonPrivateField.ql
2018-10-11 11:31:37 +02:00

30 lines
878 B
Plaintext

/**
* @name Non-private field
* @description A non-constant field that is not declared 'private',
* but is not accessed outside of its declaring type, may decrease code maintainability.
* @kind problem
* @problem.severity recommendation
* @precision medium
* @id java/non-private-field
* @tags maintainability
*/
import java
import semmle.code.java.JDKAnnotations
class NonConstantSourceField extends Field {
NonConstantSourceField() {
this.fromSource() and
not (this.isFinal() and this.isStatic())
}
}
from NonConstantSourceField f
where
not f.isPrivate() and
not exists(VarAccess va | va.getVariable() = f |
va.getEnclosingCallable().getDeclaringType() != f.getDeclaringType()
) and
not f.getAnAnnotation() instanceof ReflectiveAccessAnnotation
select f, "This non-private field is not accessed outside of its declaring type."