java.io.File.LazyInitialization (original) (raw)

Alan Bateman Alan.Bateman at oracle.com
Sat Jan 21 19:01:47 UTC 2012


On 21/01/2012 18:11, Alex Lam S.L. wrote:

Hi there,

Whilst reading the JDK6 source code for java.io.File.createTempFile(), I noticed that: ... private static class LazyInitialization { ... static final String temporaryDirectory = temporaryDirectory(); static String temporaryDirectory() {...} ... } ... public static File createTempFile(String prefix, String suffix, File directory) throws IOException { ... if (directory == null) { String tmpDir = LazyInitialization.temporaryDirectory(); ... Shouldn't the last line use the static field instead of the static method? The static field "temporaryDirectory" is not used anywhere else in the class, which also make this seem suspicious.

Alex. Yes indeed, and this was pointed out some time ago too [1]. This is code that has been replaced in jdk7 and it's just that we didn't go back to jdk6 to clean it up.

-Alan

[1] http://mail.openjdk.java.net/pipermail/core-libs-dev/2010-January/003515.html



More information about the core-libs-dev mailing list