Class UnsafeAccess

java.lang.Object
dev.derklaro.reflexion.internal.unsafe.UnsafeAccess

public final class UnsafeAccess extends Object
A utility class which allows access to sun.misc.Unsafe without needing to hassle with it. To verify that this util is ready to be used, use the isAvailable() method.
Since:
1.6
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    private static final Object
     
  • Constructor Summary

    Constructors
    Modifier
    Constructor
    Description
    private
     
  • Method Summary

    Modifier and Type
    Method
    Description
    static @UnknownNullability Object
    invokeMethod(@NotNull String methodName, @NotNull Class<?>[] argTypes, @NotNull Object... args)
    Calls the given method which is provided in sun.misc.Unsafe.
    static boolean
    Checks if the sun.misc.Unsafe instance could be resolved during the class init, and is now ready to call method with it.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • THE_UNSAFE

      private static final Object THE_UNSAFE
  • Constructor Details

    • UnsafeAccess

      private UnsafeAccess()
  • Method Details

    • isAvailable

      public static boolean isAvailable()
      Checks if the sun.misc.Unsafe instance could be resolved during the class init, and is now ready to call method with it.
      Returns:
      true if this instance can be used to access sun.misc.Unsafe, false otherwise.
    • invokeMethod

      public static @UnknownNullability Object invokeMethod(@NotNull @NotNull String methodName, @NotNull @NotNull Class<?>[] argTypes, @NotNull @NotNull Object... args)
      Calls the given method which is provided in sun.misc.Unsafe. This method returns null if either the method could not be resolved or the invocation throws an exception.
      Parameters:
      methodName - the name of the method to invoke.
      argTypes - the argument types of the method.
      args - the arguments to pass to the method.
      Returns:
      the result of the method invocation.
      Throws:
      NullPointerException - if the given method name, argument types or arguments array is null.
      IllegalStateException - if this util is not available for usage.