Merge pull request #6673 from Marcono1234/marcono1234/clone-method-models

Java: Remove duplicate classes modeling Object.clone
This commit is contained in:
Anders Schack-Mulligen
2021-09-13 11:13:14 +02:00
committed by GitHub
2 changed files with 9 additions and 16 deletions

View File

@@ -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."

View File

@@ -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."