File tree Expand file tree Collapse file tree 2 files changed +9
-16
lines changed
java/ql/src/Advisory/Java Objects Expand file tree Collapse file tree 2 files changed +9
-16
lines changed Original file line number Diff line number Diff line change 11
11
12
12
import java
13
13
14
- class ObjectCloneMethod extends Method {
15
- ObjectCloneMethod ( ) {
16
- this .getDeclaringType ( ) instanceof TypeObject and
17
- this .getName ( ) = "clone" and
18
- this .hasNoParameters ( )
19
- }
20
- }
21
-
22
- from MethodAccess ma , ObjectCloneMethod clone
23
- where ma .getMethod ( ) .overrides ( clone )
14
+ from MethodAccess ma , Method m
15
+ where
16
+ m = ma .getMethod ( ) and
17
+ m instanceof CloneMethod and
18
+ // But ignore direct calls to Object.clone
19
+ not m .getDeclaringType ( ) instanceof TypeObject
24
20
select ma , "Invoking a method that overrides clone() should be avoided."
Original file line number Diff line number Diff line change 11
11
12
12
import java
13
13
14
- class ObjectCloneMethod extends Method {
15
- ObjectCloneMethod ( ) {
16
- this .getDeclaringType ( ) instanceof TypeObject and
17
- this .getName ( ) = "clone" and
18
- this .hasNoParameters ( )
19
- }
14
+ class ObjectCloneMethod extends CloneMethod {
15
+ ObjectCloneMethod ( ) { this .getDeclaringType ( ) instanceof TypeObject }
20
16
}
21
17
22
18
from Method m , ObjectCloneMethod clone
23
19
where
24
20
m .fromSource ( ) and
21
+ // Only consider direct overrides of Object.clone
25
22
m .overrides ( clone )
26
23
select m , "Overriding the Object.clone() method should be avoided."
You can’t perform that action at this time.
0 commit comments