From 95f73048ceb8ecd5ca2ae59d152d8c9101fff596 Mon Sep 17 00:00:00 2001 From: Roel Spilker Date: Mon, 31 Jan 2011 23:55:06 +0100 Subject: Issue 182: Cleanup documentation should include null-check --- usage_examples/CleanupExample_post.jpage | 8 ++++++-- website/features/Cleanup.html | 6 ++++++ 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/usage_examples/CleanupExample_post.jpage b/usage_examples/CleanupExample_post.jpage index 91458459..7e87c153 100644 --- a/usage_examples/CleanupExample_post.jpage +++ b/usage_examples/CleanupExample_post.jpage @@ -13,10 +13,14 @@ public class CleanupExample { out.write(b, 0, r); } } finally { - out.close(); + if (out != null) { + out.close(); + } } } finally { - in.close(); + if (in != null) { + in.close(); + } } } } diff --git a/website/features/Cleanup.html b/website/features/Cleanup.html index 2efd6a3a..4ac4d75e 100644 --- a/website/features/Cleanup.html +++ b/website/features/Cleanup.html @@ -42,6 +42,12 @@

Small print

+

+ In the finally block, the cleanup method is only called if the given resource is not null. However, if you use delombok + on the code, a call to lombok.Lombok.preventNullAnalysis(Object o) is inserted to prevent warnings if static code analysis could + determine that a null-check would not be needed. Compilation with lombok.jar on the classpath removes that method call, + so there is no runtime dependency. +

If your code throws an exception, and the cleanup method call that is then triggered also throws an exception, then the original exception is hidden by the exception thrown by the cleanup call. You should not rely on this 'feature'. Preferably, lombok would like to generate -- cgit