Inspectopedia 2025.3 Help

'clone()' does not declare 'CloneNotSupportedException'

Reports clone() methods that do not declare throws CloneNotSupportedException.

If throws CloneNotSupportedException is not declared, the method's subclasses will not be able to prohibit cloning in the standard way. This inspection does not report clone() methods declared final and clone() methods on final classes.

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.

CloneDoesntDeclareCloneNotSupportedException
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

Configure the inspection:

Use the Only warn on 'protected' clone methods option to indicate that this inspection should only warn on protected clone() methods. The Effective Java book (second and third edition) recommends omitting the CloneNotSupportedException declaration on public methods, because the methods that do not throw checked exceptions are easier to use.

Example:

public class Example implements Cloneable { // method doesn't declare 'throws CloneNotSupportedException' protected Object clone() { try { return super.clone(); } catch (CloneNotSupportedException e) { return null; } } }

Inspection ID: CloneDeclaresCloneNotSupported

Inspection options

Here you can find the description of settings available for the 'clone()' does not declare 'CloneNotSupportedException' inspection, and the reference of their default values.

Only warn on 'protected' clone methods

Option ID:

onlyWarnOnProtectedClone

Default value:

Selected

Suppressing Inspection

You can suppress this inspection by placing the following comment marker before the code fragment where you no longer want messages from this inspection to appear:

//noinspection CloneDoesntDeclareCloneNotSupportedException

More detailed instructions as well as other ways and options that you have can be found in the product documentation:

Inspection Details

By default bundled with:

IntelliJ IDEA 2025.3, Qodana for JVM 2025.3,

Last modified: 03 December 2025