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 1111
1212import java
1313
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
2420select ma , "Invoking a method that overrides clone() should be avoided."
Original file line number Diff line number Diff line change 1111
1212import java
1313
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 }
2016}
2117
2218from Method m , ObjectCloneMethod clone
2319where
2420 m .fromSource ( ) and
21+ // Only consider direct overrides of Object.clone
2522 m .overrides ( clone )
2623select m , "Overriding the Object.clone() method should be avoided."
You can’t perform that action at this time.
0 commit comments