2 OpenJDK introduces a potential incompatibility.
3 In particular, the java.util.logging.Logger behavior has
4 changed. Instead of using strong references, it now uses weak references
5 internally. That's a reasonable change, but unfortunately some code relies on
6 the old behavior - when changing logger configuration, it simply drops the
7 logger reference. That means that the garbage collector is free to reclaim
8 that memory, which means that the logger configuration is lost. For example,
11 <p><pre>public static void initLogging() throws Exception {
12 Logger logger = Logger.getLogger("edu.umd.cs");
13 logger.addHandler(new FileHandler()); // call to change logger configuration
14 logger.setUseParentHandlers(false); // another call to change logger configuration
16 <p>The logger reference is lost at the end of the method (it doesn't
17 escape the method), so if you have a garbage collection cycle just
18 after the call to initLogging, the logger configuration is lost
19 (because Logger only keeps weak references).</p>
20 <p><pre>public static void main(String[] args) throws Exception {
21 initLogging(); // adds a file handler to the logger
22 System.gc(); // logger configuration lost
23 Logger.getLogger("edu.umd.cs").info("Some message"); // this isn't logged to the file as expected
25 <p><em>Ulf Ochsenfahrt and Eric Fellheimer</em>