mirror of
https://github.com/github/codeql.git
synced 2025-12-18 01:33:15 +01:00
Merge pull request #6673 from Marcono1234/marcono1234/clone-method-models
Java: Remove duplicate classes modeling Object.clone
This commit is contained in:
@@ -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
|
||||
// But ignore direct calls to Object.clone
|
||||
not m.getDeclaringType() instanceof TypeObject
|
||||
select ma, "Invoking a method that overrides clone() should be avoided."
|
||||
|
||||
@@ -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."
|
||||
|
||||
Reference in New Issue
Block a user