--- a/java.source.ant/antsrc/org/netbeans/modules/java/source/ant/JavacTask.java +++ a/java.source.ant/antsrc/org/netbeans/modules/java/source/ant/JavacTask.java @@ -46,6 +46,8 @@ import java.io.File; import java.io.IOException; +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; import java.net.MalformedURLException; import java.util.Arrays; import java.util.Iterator; @@ -62,10 +64,12 @@ */ public class JavacTask extends Javac { + private static final String CLASS_ZIP_FILE_INDEX = "com.sun.tools.javac.zip.ZipFileIndex"; //NOI18N + private static final String METHOD_CLOSE = "clearCache"; //NOI18N + @Override public void execute() throws BuildException { - Project p = getProject(); - + final Project p = getProject(); p.log("Overridden Javac task called", Project.MSG_DEBUG); boolean ensureBuilt = p.getProperty("ensure.built.source.roots") != null @@ -105,7 +109,11 @@ } if (!wasBuilt) { - super.execute(); + try { + super.execute(); + } finally { + cleanUp(p); + } } } else { if (CheckForCleanBuilds.cleanBuild.get() && getSrcdir() != null) { @@ -132,8 +140,34 @@ } } } + try { + super.execute(); + } finally { + cleanUp(p); + } + } + } - super.execute(); + + private static void cleanUp (final Project p) { + try { + p.log("Cleaning ZipFileIndex cache", Project.MSG_DEBUG); //NOI18N + final Class zipFileIndex = Class.forName(CLASS_ZIP_FILE_INDEX); + final Method clean = zipFileIndex.getDeclaredMethod(METHOD_CLOSE); + clean.invoke(null); + p.log("ZipFileIndex cache cleaned", Project.MSG_DEBUG); //NOI18N + } catch (ClassNotFoundException e) { + p.log("ZipFileIndex clearCache failed", e, Project.MSG_VERBOSE); //NOI18N + } catch (NoSuchMethodException e) { + p.log("ZipFileIndex clearCache failed", e, Project.MSG_VERBOSE); //NOI18N + } catch (SecurityException e) { + p.log("ZipFileIndex clearCache failed", e, Project.MSG_VERBOSE); //NOI18N + } catch (InvocationTargetException e) { + p.log("ZipFileIndex clearCache failed", e, Project.MSG_VERBOSE); //NOI18N + } catch (IllegalArgumentException e) { + p.log("ZipFileIndex clearCache failed", e, Project.MSG_VERBOSE); //NOI18N + } catch (IllegalAccessException e) { + p.log("ZipFileIndex clearCache failed", e, Project.MSG_VERBOSE); //NOI18N } } --- a/java.source/src/org/netbeans/modules/java/source/JBrowseModule.java +++ a/java.source/src/org/netbeans/modules/java/source/JBrowseModule.java @@ -60,16 +60,7 @@ /** Creates a new instance of JBrowseModule */ public JBrowseModule() { } - - public @Override void restored() { - super.restored(); - //XXX: - //#143234: javac caches content of all jar files in a static map, which leads to memory leaks affecting the IDE - //when "internal" execution of javac is used - //the property below disables the caches - //java.project might be a better place (currently does not have a ModuleInstall) - System.setProperty("useJavaUtilZip", "true"); //NOI18N - } + public @Override void close () { super.close();