-
Notifications
You must be signed in to change notification settings - Fork 2k
Expand file tree
/
Copy pathFieldMasksSuperField.ql
More file actions
35 lines (33 loc) · 1.08 KB
/
FieldMasksSuperField.ql
File metadata and controls
35 lines (33 loc) · 1.08 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
/**
* @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 maintainability
* readability
*/
import java
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()
select masking, "This field shadows another field called $@ in a superclass.",
masked, masked.getName()