Class NativeHandle

java.lang.Object
com.exonum.binding.core.proxy.NativeHandle
All Implemented Interfaces:
java.lang.AutoCloseable

public final class NativeHandle
extends java.lang.Object
implements java.lang.AutoCloseable
An implementation-specific handle to the native object. Once closed, can no longer be accessed.
  • Field Summary

    Fields 
    Modifier and Type Field Description
    static long INVALID_NATIVE_HANDLE
    A reserved value for an invalid native handle, equal to nullptr in C++.
  • Constructor Summary

    Constructors 
    Constructor Description
    NativeHandle​(long nativeHandle)
    Creates new native handle.
  • Method Summary

    Modifier and Type Method Description
    void close()  
    long get()
    Returns a native implementation-specific handle if it may be safely used to access the native object.
    java.lang.String toString()  

    Methods inherited from class java.lang.Object

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

  • Constructor Details

    • NativeHandle

      public NativeHandle​(long nativeHandle)
      Creates new native handle. Validates it's state not allowing to create nullptr handle.
      Throws:
      java.lang.IllegalStateException - if this native handle is invalid (nullptr)
  • Method Details

    • get

      public long get()
      Returns a native implementation-specific handle if it may be safely used to access the native object.

      The returned value shall only be passed as an argument to native methods.

      Warning: do not cache the return value, as you won't be able to catch use-after-free.

      Throws:
      java.lang.IllegalStateException - if this native handle is invalid (closed or nullptr)
    • close

      public void close()
      Specified by:
      close in interface java.lang.AutoCloseable
    • toString

      public java.lang.String toString()
      Overrides:
      toString in class java.lang.Object