mirror of
https://github.com/github/codeql.git
synced 2026-01-12 22:14:47 +01:00
27 lines
697 B
Plaintext
27 lines
697 B
Plaintext
/**
|
|
* @name Overriding definition of clone()
|
|
* @description Overriding 'Object.clone' is bad practice. Copying an object using the 'Cloneable
|
|
* interface' and 'Object.clone' is error-prone.
|
|
* @kind problem
|
|
* @problem.severity recommendation
|
|
* @precision medium
|
|
* @id java/override-of-clone-method
|
|
* @tags reliability
|
|
*/
|
|
|
|
import java
|
|
|
|
class ObjectCloneMethod extends Method {
|
|
ObjectCloneMethod() {
|
|
this.getDeclaringType() instanceof TypeObject and
|
|
this.getName() = "clone" and
|
|
this.hasNoParameters()
|
|
}
|
|
}
|
|
|
|
from Method m, ObjectCloneMethod clone
|
|
where
|
|
m.fromSource() and
|
|
m.overrides(clone)
|
|
select m, "Overriding the Object.clone() method should be avoided."
|