import org.eclipse.jdt.annotation.Nullable;
/**
- * Implementation of {@link CloseTracked} which can be used as a field in
- * another class which implements {@link CloseTracked} and delegates its methods
- * to this.
+ * Implementation of {@link CloseTracked} which can be used as a field in another class which implements
+ * {@link CloseTracked} and delegates its methods to this.
*
- * <p>This is useful if that class already has another parent class.
- * If it does not, then it's typically more convenient to just extend AbstractCloseTracked.
+ * <p>
+ * This is useful if that class already has another parent class. If it does not, then it's typically more convenient to
+ * just extend AbstractCloseTracked.
*
* @author Michael Vorburger.ch
*/
final class CloseTrackedTrait<T extends CloseTracked<T>> implements CloseTracked<T> {
-
// NB: It's important that we keep a Throwable here, and not directly the StackTraceElement[] !
// This is because creating a new Throwable() is a lot less expensive in terms of runtime overhead
// than actually calling its getStackTrace(), which we can delay until we really need to.
if (transactionChainRegistry.isDebugContextEnabled()) {
// NB: We're NOT doing the (expensive) getStackTrace() here just yet (only below)
// TODO When we're on Java 9, then instead use the new java.lang.StackWalker API..
- this.allocationContext = new Throwable();
+ allocationContext = new Throwable();
} else {
- this.allocationContext = null;
+ allocationContext = null;
}
this.realCloseTracked = requireNonNull(realCloseTracked, "realCloseTracked");
- this.closeTrackedRegistry = requireNonNull(transactionChainRegistry, "transactionChainRegistry");
- this.closeTrackedRegistry.add(this);
+ closeTrackedRegistry = requireNonNull(transactionChainRegistry, "transactionChainRegistry");
+ closeTrackedRegistry.add(this);
}
@Override
@SuppressFBWarnings("PZLA_PREFER_ZERO_LENGTH_ARRAYS")
public @Nullable StackTraceElement[] getAllocationContextStackTrace() {
- return allocationContext != null ? allocationContext.getStackTrace() : null;
+ final var local = allocationContext;
+ return local != null ? local.getStackTrace() : null;
}
public void removeFromTrackedRegistry() {