Skip to content

Commit

Permalink
Minor cleanup/improvement of AutoCloseableWithLeakDetectionBase.
Browse files Browse the repository at this point in the history
  • Loading branch information
Aklakan committed Dec 5, 2024
1 parent e7d35b6 commit e1efa53
Showing 1 changed file with 7 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@
* If finalize is called (typically only by the GC) and there was no prior call to close then
* a warning including the stack trace is logged.
*
* Implementing classes should override {@link #closeActual()} rather than
* {@link #close()}.
* Implementing classes need to override {@link #closeActual()} because {@link #close()} is final.
*
* @author Claus Stadler
*
Expand Down Expand Up @@ -40,14 +39,15 @@ public StackTraceElement[] getInstantiationStackTrace() {
}

@Override
@SuppressWarnings("deprecation")
protected void finalize() throws Throwable {
try {
if (!isClosed) {
if (logger.isWarnEnabled()) {
String objectIdStr = ObjectUtils.identityToString(this);
String stackTraceStr = StackTraceUtils.toString(instantiationStackTrace);
logger.warn(String.format("Close invoked via GC rather than user logic - indicates resource leak. Object %s constructed at %s", objectIdStr, stackTraceStr));
}
if (logger.isWarnEnabled()) {
String objectIdStr = ObjectUtils.identityToString(this);
String stackTraceStr = StackTraceUtils.toString(instantiationStackTrace);
logger.warn(String.format("Close invoked via GC rather than user logic - indicates resource leak. Object %s constructed at %s", objectIdStr, stackTraceStr));
}
close();
}
} finally {
Expand Down

0 comments on commit e1efa53

Please sign in to comment.