Skip to content
Edit this page

Troubleshooting

UncopyableObjectException: Cannot copy java.lang.Thread in com.acme.Task ...

The graph contains a live object: a thread, a reference, an open file, a socket, a process, an executor. Decide what the clone gets by a type, field or object action: CopyAction.ORIGINAL to share it, CopyAction.CLEAR to drop it, or a custom copier. See JDK types.

The message names the object which references the live one. To see the whole path from the root, clone the same graph with Cloners.builder().mode(CloningMode.RECURSIVE), see Modes.

UncopyableObjectException: Cannot copy ...$$Lambda... the lambda captures values, which cannot be read ...

The package of a capturing lambda is not open to the cloner, e.g. a lambda of the JDK with a toolset without module opening. Use the default toolset, open the package, or share the lambda by CopyAction.ORIGINAL, see JDK types.

Cannot make ... accessible. Open its package to the cloner ...

A toolset relies on reflection, and the package of the class is not open to the cloner. Use the default toolset, open the package by --add-opens, or choose a module opening, see Toolsets.

Cannot access field ...

No field access mechanism of the toolset can access the field. The same remedies as above; Toolsets.unsafe() reaches any field of a normal class.

The JVM denies writing the final field ... by reflection ...

JDK 26+ started with --illegal-final-field-mutation=deny (a future default) does not let reflection write final fields. Start the JVM with --enable-final-field-mutation=ALL-UNNAMED, add copy constructors to the class with the build tools, or use a toolset with Unsafe field access, see Java versions.

The JVM denies the memory access of Unsafe ...

The toolset needs Unsafe field access, and the JVM is started with --sun-misc-unsafe-memory-access=deny (a future default). Use the default toolset, it accesses fields by reflection then.

Cannot clone ...: it is part of a reference cycle ...

An object which creates its clone from copied values (a record, a Copyable, a single-phase custom copier) is part of a cycle which needs it before its clone exists. Break the cycle for cloning, e.g. by CopyAction.CLEAR for one of its fields, or write a TwoPhaseObjectCopier for one of the types.

No instance allocator supports ...

No mechanism of the toolset can create an instance of the class without a constructor, and the constructor fallback is disabled or the class has no usable constructor. Use the default toolset or enable the constructor fallback. On the module path the cloner gets no Unsafe unless the application requires jdk.unsupported, see Dependencies.

Registration mismatch when cloning ...

A custom copier or a Copyable must call CopyContext.register(clone) exactly once and return the registered clone.

WARNING: sun.misc.Unsafe::... has been called by io.github.sugarcubes.cloner...

JDK 24+ warns once about Unsafe memory access, which the default toolset uses for fields. It is harmless; see Toolsets for how to avoid it.

WARNING: Final field ... has been mutated reflectively by class io.github.sugarcubes.cloner...

JDK 26+ warns once when reflection writes a final field: the toolset accesses fields by reflection. Start the JVM with --enable-final-field-mutation=ALL-UNNAMED, or see Java versions for the other ways.

UnsupportedOperationException: Run with -Djdk.reflect.allowNonSerializableConstruction=true ...

JDK 28 refuses sun.reflect.ReflectionFactory for classes which are not serializable. The toolsets of the cloner create them by Unsafe then; a custom allocator calling ReflectionFactory must do the same.

Copy constructors: ... gets no copy constructor: ...

The agent cannot add the copy constructor to a listed class, e.g. its superclass has none: list the superclass too, or exclude the class by !. The class is cloned as usual.

Copy constructors: no bytecode engine for the classes of ...

The agent runs on JDK 8 to 23, where the JVM has no ClassFile API, and neither the cloner nor the class loader sees ASM. Put org.ow2.asm:asm on the classpath, or run on JDK 24+.

Copy constructors: the class loader ... does not see the cloner ...

The classes of the loader would call the cloner from their copy constructors, but the loader does not see it, e.g. a loader without parent. Its classes are cloned as usual.

WARNING: A restricted method in java.lang.System has been called ... narcissus

Narcissus loads a native library. Start the JVM with --enable-native-access=ALL-UNNAMED, or remove Narcissus from the classpath if you do not need it.