Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 6 additions & 10 deletions java/ql/src/Advisory/Java Objects/AvoidCloneMethodAccess.ql
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,10 @@

import java

class ObjectCloneMethod extends Method {
ObjectCloneMethod() {
this.getDeclaringType() instanceof TypeObject and
this.getName() = "clone" and
this.hasNoParameters()
}
}

from MethodAccess ma, ObjectCloneMethod clone
where ma.getMethod().overrides(clone)
from MethodAccess ma, Method m
where
m = ma.getMethod() and
m instanceof CloneMethod and
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This might a behavior change because previously it would only consider calls to methods directly overriding Object.clone, while now it considers transitive overrides as well.
However the way the query description is written suggests that this is desired.

// But ignore direct calls to Object.clone
not m.getDeclaringType() instanceof TypeObject
select ma, "Invoking a method that overrides clone() should be avoided."
9 changes: 3 additions & 6 deletions java/ql/src/Advisory/Java Objects/AvoidCloneOverride.ql
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,13 @@

import java

class ObjectCloneMethod extends Method {
ObjectCloneMethod() {
this.getDeclaringType() instanceof TypeObject and
this.getName() = "clone" and
this.hasNoParameters()
}
class ObjectCloneMethod extends CloneMethod {
ObjectCloneMethod() { this.getDeclaringType() instanceof TypeObject }
}

from Method m, ObjectCloneMethod clone
where
m.fromSource() and
// Only consider direct overrides of Object.clone
m.overrides(clone)
select m, "Overriding the Object.clone() method should be avoided."