Thu, 10 Feb 2011 14:24:26 -0800
7018098: CacheFSInfo persists too long
Reviewed-by: mcimadamore
1.1 --- a/src/share/classes/com/sun/tools/javac/file/CacheFSInfo.java Wed Feb 09 18:26:08 2011 -0800 1.2 +++ b/src/share/classes/com/sun/tools/javac/file/CacheFSInfo.java Thu Feb 10 14:24:26 2011 -0800 1.3 @@ -49,16 +49,13 @@ 1.4 public static void preRegister(final Context context) { 1.5 context.put(FSInfo.class, new Context.Factory<FSInfo>() { 1.6 public FSInfo make() { 1.7 - if (singleton == null) 1.8 - singleton = new CacheFSInfo(); 1.9 - context.put(FSInfo.class, singleton); 1.10 - return singleton; 1.11 + FSInfo instance = new CacheFSInfo(); 1.12 + context.put(FSInfo.class, instance); 1.13 + return instance; 1.14 } 1.15 }); 1.16 } 1.17 1.18 - static CacheFSInfo singleton; 1.19 - 1.20 public void clearCache() { 1.21 cache.clear(); 1.22 }
2.1 --- a/src/share/classes/com/sun/tools/javac/processing/JavacProcessingEnvironment.java Wed Feb 09 18:26:08 2011 -0800 2.2 +++ b/src/share/classes/com/sun/tools/javac/processing/JavacProcessingEnvironment.java Thu Feb 10 14:24:26 2011 -0800 2.3 @@ -55,6 +55,7 @@ 2.4 import com.sun.tools.javac.api.JavacTrees; 2.5 import com.sun.tools.javac.code.*; 2.6 import com.sun.tools.javac.code.Symbol.*; 2.7 +import com.sun.tools.javac.file.FSInfo; 2.8 import com.sun.tools.javac.file.JavacFileManager; 2.9 import com.sun.tools.javac.jvm.*; 2.10 import com.sun.tools.javac.main.JavaCompiler; 2.11 @@ -1069,6 +1070,10 @@ 2.12 if (tl != null) 2.13 next.put(TaskListener.class, tl); 2.14 2.15 + FSInfo fsInfo = context.get(FSInfo.class); 2.16 + if (fsInfo != null) 2.17 + next.put(FSInfo.class, fsInfo); 2.18 + 2.19 JavaFileManager jfm = context.get(JavaFileManager.class); 2.20 Assert.checkNonNull(jfm); 2.21 next.put(JavaFileManager.class, jfm);
3.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 3.2 +++ b/test/tools/javac/file/T7018098.java Thu Feb 10 14:24:26 2011 -0800 3.3 @@ -0,0 +1,121 @@ 3.4 +/* 3.5 + * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved. 3.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 3.7 + * 3.8 + * This code is free software; you can redistribute it and/or modify it 3.9 + * under the terms of the GNU General Public License version 2 only, as 3.10 + * published by the Free Software Foundation. 3.11 + * 3.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 3.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 3.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 3.15 + * version 2 for more details (a copy is included in the LICENSE file that 3.16 + * accompanied this code). 3.17 + * 3.18 + * You should have received a copy of the GNU General Public License version 3.19 + * 2 along with this work; if not, write to the Free Software Foundation, 3.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 3.21 + * 3.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 3.23 + * or visit www.oracle.com if you need additional information or have any 3.24 + * questions. 3.25 + */ 3.26 + 3.27 +/** 3.28 + * @test 3.29 + * @bug 7018098 3.30 + * @summary CacheFSInfo persists too long 3.31 + * @library ../lib 3.32 + * @build JavacTestingAbstractProcessor T7018098 3.33 + * @run main T7018098 3.34 + */ 3.35 + 3.36 +import java.io.*; 3.37 +import java.util.*; 3.38 +import javax.annotation.processing.RoundEnvironment; 3.39 +import javax.annotation.processing.SupportedOptions; 3.40 +import javax.lang.model.element.TypeElement; 3.41 +import javax.tools.Diagnostic; 3.42 + 3.43 +import com.sun.tools.javac.file.FSInfo; 3.44 +import com.sun.tools.javac.processing.JavacProcessingEnvironment; 3.45 +import com.sun.tools.javac.util.Context; 3.46 + 3.47 +@SupportedOptions("expect") 3.48 +public class T7018098 extends JavacTestingAbstractProcessor { 3.49 + public static void main(String... args) throws Exception { 3.50 + new T7018098().run(); 3.51 + } 3.52 + 3.53 + static File testDir = new File("T7018098.dir"); 3.54 + 3.55 + void run() throws Exception { 3.56 + String myName = T7018098.class.getSimpleName(); 3.57 + File testSrc = new File(System.getProperty("test.src")); 3.58 + File file = new File(testSrc, myName + ".java"); 3.59 + 3.60 + _assert(!testDir.exists()); 3.61 + 3.62 + compile( 3.63 + "-proc:only", 3.64 + "-processor", myName, 3.65 + "-Aexpect=false", 3.66 + file.getPath()); 3.67 + 3.68 + testDir.mkdirs(); 3.69 + _assert(testDir.exists()); 3.70 + 3.71 + compile( 3.72 + "-proc:only", 3.73 + "-processor", myName, 3.74 + "-Aexpect=true", 3.75 + file.getPath()); 3.76 + } 3.77 + 3.78 + void _assert(boolean cond) { 3.79 + if (!cond) 3.80 + throw new AssertionError(); 3.81 + } 3.82 + 3.83 + void compile(String... args) throws Exception { 3.84 + StringWriter sw = new StringWriter(); 3.85 + PrintWriter pw = new PrintWriter(sw); 3.86 + int rc = com.sun.tools.javac.Main.compile(args, pw); 3.87 + pw.close(); 3.88 + String out = sw.toString(); 3.89 + if (!out.isEmpty()) 3.90 + System.err.println(out); 3.91 + if (rc != 0) 3.92 + throw new Exception("compilation failed unexpectedly: rc=" + rc); 3.93 + } 3.94 + 3.95 + //--------------- 3.96 + 3.97 + @Override 3.98 + public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) { 3.99 + Context context = ((JavacProcessingEnvironment) processingEnv).getContext(); 3.100 + FSInfo fsInfo = context.get(FSInfo.class); 3.101 + 3.102 + round++; 3.103 + if (round == 1) { 3.104 + boolean expect = Boolean.valueOf(options.get("expect")); 3.105 + checkEqual("cache result", fsInfo.isDirectory(testDir), expect); 3.106 + initialFSInfo = fsInfo; 3.107 + } else { 3.108 + checkEqual("fsInfo", fsInfo, initialFSInfo); 3.109 + } 3.110 + 3.111 + return true; 3.112 + } 3.113 + 3.114 + <T> void checkEqual(String label, T actual, T expected) { 3.115 + if (actual != expected) 3.116 + messager.printMessage(Diagnostic.Kind.ERROR, 3.117 + "Unexpected value for " + label 3.118 + + "; expected: " + expected 3.119 + + "; found: " + actual); 3.120 + } 3.121 + 3.122 + int round = 0; 3.123 + FSInfo initialFSInfo; 3.124 +}