Class FinalFieldSetter

java.lang.Object
org.apache.sis.internal.util.FinalFieldSetter

public final class FinalFieldSetter extends Object
Convenience methods for setting the final field of an object. This class shall be used only after deserialization or cloning of Apache SIS objects. The usage pattern is:

On deserialization:

On clone:

Same as above but invoking cloneFailure(e) if the operation failed. The exception to be thrown is not the same.

Historical note

Previous version was implementing PrivilegedAction<FinalFieldSetter<T>> for working in the context of a security manager. This feature has been removed since java.security.AccessController has been deprecated in Java 17.
Since:
1.0
Version:
1.2
See Also:
  • Constructor Details

    • FinalFieldSetter

      private FinalFieldSetter()
      Do not allow instantiation of this class.
  • Method Details

    • set

      public static <T> void set(Class<T> classe, String field, T instance, Object value) throws NoSuchFieldException, IllegalAccessException
      Sets the value of the final field.
      Type Parameters:
      T - the type of object in which to set a final field. Should be Apache SIS classes only.
      Parameters:
      classe - the Apache SIS class of object for which to set a final field.
      field - the name of the final field for which to set a value.
      instance - the instance on which to set the value.
      value - the value to set.
      Throws:
      NoSuchFieldException - if the given field has not been found.
      IllegalAccessException - if the value cannot be set.
    • set

      public static <T> void set(Class<T> classe, String field, String second, T instance, Object value, Object more) throws NoSuchFieldException, IllegalAccessException
      Sets the values of the final fields.
      Type Parameters:
      T - the type of object in which to set a final field. Should be Apache SIS classes only.
      Parameters:
      classe - the Apache SIS class of object for which to set a final field.
      field - the name of the first final field for which to set a value.
      second - the name of the second final field for which to set a value.
      instance - the instance on which to set the value.
      value - the value of the first field to set.
      more - the value of the second field to set.
      Throws:
      NoSuchFieldException - if a given field has not been found.
      IllegalAccessException - if a value cannot be set.
    • readFailure

      public static InvalidClassException readFailure(ReflectiveOperationException cause)
      Creates an exception for a readObject(ObjectInputStream) method.
      Parameters:
      cause - the failure.
      Returns:
      the exception to throw.
    • cloneFailure

      public static RuntimeException cloneFailure(ReflectiveOperationException cause)
      Creates an exception for a clone() method.
      Parameters:
      cause - the failure.
      Returns:
      the exception to throw.