-
Notifications
You must be signed in to change notification settings - Fork 2k
Expand file tree
/
Copy pathFieldMasksSuperField.ql
More file actions
38 lines (35 loc) · 1.28 KB
/
FieldMasksSuperField.ql
File metadata and controls
38 lines (35 loc) · 1.28 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
/**
* @name Field masks field in super class
* @description Hiding a field in a superclass by redeclaring it in a subclass might be
* unintentional, especially if references to the hidden field are not qualified using
* 'super'.
* @kind problem
* @problem.severity warning
* @precision medium
* @id java/field-masks-super-field
* @tags quality
* maintainability
* readability
* correctness
*/
import java
private import semmle.code.java.frameworks.android.Compose
class VisibleInstanceField extends Field {
VisibleInstanceField() {
not this.isPrivate() and
not this.isStatic()
}
}
from RefType type, RefType supertype, VisibleInstanceField masked, VisibleInstanceField masking
where
type.getASourceSupertype+() = supertype and
masking.getDeclaringType() = type and
masked.getDeclaringType() = supertype and
masked.getName() = masking.getName() and
// Exclude intentional masking.
not exists(VarAccess va | va.getVariable() = masked | va.getQualifier() instanceof SuperAccess) and
type.fromSource() and
// Exclude live literal variables, which is generated code.
not masking.getInitializer() instanceof LiveLiteral
select masking, "This field shadows another field called $@ in a superclass.", masked,
masked.getName()