Inspectopedia Help

'clone()' method in non-Cloneable class

Reports classes that override the clone() method but don't implement the Cloneable interface. This usually represents a programming error.

Locating this inspection

By ID

Can be used to locate inspection in e.g. Qodana configuration files, where you can quickly enable or disable it, or adjust its settings.

CloneInNonCloneableClass
Via Settings dialog

Path to the inspection settings via IntelliJ Platform IDE Settings dialog, when you need to adjust inspection settings directly from your IDE.

Settings or Preferences | Editor | Inspections | Java | Cloning issues

Use the Only warn on 'public' clone methods option to ignore methods that aren't public.

For classes designed to be inherited, you may choose to override clone() and declare it as protected without implementing the Cloneable interface and decide whether to implement the Cloneable interface in subclasses.

Inspection options

Here you can find the description of settings available for the 'clone()' method in non-Cloneable class inspection, and the reference of their default values.

Only warn on 'public' clone methods

Default: Selected

Availability

By default bundled with

IntelliJ IDEA 2024.1, Qodana for JVM 2024.1,

Can be installed with plugin

Java, 241.18072

Last modified: 18 June 2024