Package jline.util

Class SerialCopy

java.lang.Object
jline.util.SerialCopy

public final class SerialCopy extends Object
Deep copy of an object graph by Java serialization, resolving classes against the loaders that defined them.

A plain ObjectInputStream resolves every class through the nearest user-defined loader on the stack, which for a copy made inside LINE is the loader of jline.jar. A lambda or anonymous class defined in user code loaded by a child loader (the JDK single-file source launcher, a notebook kernel, an IDE runner, MATLAB's dynamic class path) is invisible to that loader, so copying a model that carried such a handle (e.g. a class-dependence function) failed with "cannot assign instance of java.lang.invoke.SerializedLambda". The writer here records the loader of every class it describes, including the capturing class of a serialized lambda, and the reader tries them in turn after the default resolution, then the thread context loader. Copyright (c) 2012-2026, Imperial College London All rights reserved.

  • Method Details

    • deepCopy

      public static <T> T deepCopy(T obj) throws IOException, ClassNotFoundException
      Returns a deep copy of obj.
      Type Parameters:
      T - its type
      Parameters:
      obj - a serializable object graph
      Returns:
      an independent copy
      Throws:
      IOException - if some reachable object is not serializable
      ClassNotFoundException - if a class of the graph cannot be resolved on read