Class RecursiveObjectLeaker


  • @Beta
    public final class RecursiveObjectLeaker
    extends Object
    Thread-local hack to make recursive extensions work without too much hassle. The idea is that prior to instantiating an extension, the definition object checks whether it is already present on the stack, recorded object is returned.

    If it is not, it will push itself to the stack as unresolved and invoke the constructor. The constructor's lowermost class calls to this class and if the topmost entry is not resolved, it will leak itself.

    Upon return from the constructor, the topmost entry is removed and if the queue is empty, the thread-local variable will be cleaned up.

    WARNING: BE CAREFUL WHEN USING THIS CLASS. IT LEAKS OBJECTS WHICH ARE NOT COMPLETELY INITIALIZED.

    WARNING: THIS CLASS LEAVES THREAD-LOCAL RESIDUE. MAKE SURE IT IS OKAY OR CALL cleanup() IN APPROPRIATE PLACES.

    THIS CLASS IS EXTREMELY DANGEROUS (okay, not as much as sun.misc.unsafe). YOU HAVE BEEN WARNED. IF SOMETHING BREAKS IT IS PROBABLY YOUR FAULT AND YOU ARE ON YOUR OWN.

    Author:
    Robert Varga
    • Method Detail

      • beforeConstructor

        public static void beforeConstructor​(Object key)
      • inConstructor

        public static void inConstructor​(Object obj)
      • afterConstructor

        public static void afterConstructor​(Object key)
      • lookup

        public static <T> @Nullable T lookup​(Object key,
                                             Class<T> requiredClass)
      • cleanup

        public static void cleanup()