From 4bbc0f515d83b57b0629cac40d1059791b963ec9 Mon Sep 17 00:00:00 2001
From: Evgeny Mandrikov toString()
method in java.lang.Object
, which is probably what was intended.
[Bill Pugh]: Sorry, but I strongly disagree that this should be a warning, and I think your code + is just fine. Users of your code shouldn't care how you've implemented equals(), and they should never + depend on == to compare instances, since that bypasses the libraries ability to control how objects + are compared. +
]]>+ In general, if a method opens a stream or other resource, + the method should use a try/finally block to ensure that + the stream or resource is cleaned up before the method + returns. +
++ This bug pattern is essentially the same as the + OS_OPEN_STREAM and ODR_OPEN_DATABASE_RESOURCE + bug patterns, but is based on a different + (and hopefully better) static analysis technique. + We are interested is getting feedback about the + usefulness of this bug pattern. + To send feedback, either: +
++ In particular, + the false-positive suppression heuristics for this + bug pattern have not been extensively tuned, so + reports about false positives are helpful to us. +
++ See Weimer and Necula, Finding and Preventing Run-Time Error Handling Mistakes, for + a description of the analysis technique. +
]]>public static void initLogging() throws Exception { + Logger logger = Logger.getLogger("edu.umd.cs"); + logger.addHandler(new FileHandler()); // call to change logger configuration + logger.setUseParentHandlers(false); // another call to change logger configuration + }+
The logger reference is lost at the end of the method (it doesn't + escape the method), so if you have a garbage collection cycle just + after the call to initLogging, the logger configuration is lost + (because Logger only keeps weak references).
+public static void main(String[] args) throws Exception { + initLogging(); // adds a file handler to the logger + System.gc(); // logger configuration lost + Logger.getLogger("edu.umd.cs").info("Some message"); // this isn't logged to the file as expected + }+
Ulf Ochsenfahrt and Eric Fellheimer +
]]>