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 @@
+ 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