diff --git a/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/batch/ClasspathJep247.java b/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/batch/ClasspathJep247.java index 89b7667e82b..8b828fc6e0d 100644 --- a/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/batch/ClasspathJep247.java +++ b/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/batch/ClasspathJep247.java @@ -261,7 +261,7 @@ public FileVisitResult postVisitDirectory(java.nio.file.Path dir, IOException ex } if (moduleName == null) { // Delegate to the boss, even if it means inaccurate error reporting at times - List mods = JRTUtil.getModulesDeclaringPackage(this.file, qualifiedPackageName, moduleName); + List mods = JRTUtil.getModulesDeclaringPackage(this.jrtFileSystem, qualifiedPackageName, moduleName); return CharOperation.toCharArrays(mods); } return singletonModuleNameIf(this.packageCache.contains(qualifiedPackageName)); diff --git a/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/batch/ClasspathJep247Jdk12.java b/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/batch/ClasspathJep247Jdk12.java index dd3ad355712..aa488bc89be 100644 --- a/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/batch/ClasspathJep247Jdk12.java +++ b/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/batch/ClasspathJep247Jdk12.java @@ -264,7 +264,7 @@ void acceptModule(ClassFileReader reader, Map cache) { public synchronized char[][] getModulesDeclaringPackage(String qualifiedPackageName, String moduleName) { if (this.jdklevel >= ClassFileConstants.JDK9) { // Delegate to the boss, even if it means inaccurate error reporting at times - List mods = JRTUtil.getModulesDeclaringPackage(this.file, qualifiedPackageName, moduleName); + List mods = JRTUtil.getModulesDeclaringPackage(this.jrtFileSystem, qualifiedPackageName, moduleName); return CharOperation.toCharArrays(mods); } if (this.packageCache == null) { diff --git a/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/batch/ClasspathJrt.java b/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/batch/ClasspathJrt.java index 4c69deb5a63..9e0957de012 100644 --- a/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/batch/ClasspathJrt.java +++ b/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/batch/ClasspathJrt.java @@ -43,10 +43,12 @@ import org.eclipse.jdt.internal.compiler.lookup.BinaryTypeBinding.ExternalAnnotationStatus; import org.eclipse.jdt.internal.compiler.util.CtSym; import org.eclipse.jdt.internal.compiler.util.JRTUtil; +import org.eclipse.jdt.internal.compiler.util.JrtFileSystem; @SuppressWarnings({"rawtypes", "unchecked"}) public class ClasspathJrt extends ClasspathLocation implements IMultiModuleEntry { public final File file; + protected final JrtFileSystem jrtFileSystem; protected ZipFile annotationZipFile; protected final boolean closeZipFileAtEnd; protected static final Map> ModulesCache = new ConcurrentHashMap<>(); @@ -57,6 +59,11 @@ public ClasspathJrt(File file, boolean closeZipFileAtEnd, AccessRuleSet accessRuleSet, String destinationPath) { super(accessRuleSet, destinationPath); this.file = file; + try { + this.jrtFileSystem= JRTUtil.getJrtSystem(file, null); + } catch (IOException e) { + throw new IllegalStateException("Failed to init packages for " + file, e); //$NON-NLS-1$ + } this.closeZipFileAtEnd = closeZipFileAtEnd; this.moduleNamesCache = new HashSet<>(); } @@ -67,12 +74,12 @@ public List fetchLinkedJars(FileSystem.ClasspathSectionProblemReporter problemRe } @Override public char[][] getModulesDeclaringPackage(String qualifiedPackageName, String moduleName) { - List modules = JRTUtil.getModulesDeclaringPackage(this.file, qualifiedPackageName, moduleName); + List modules = JRTUtil.getModulesDeclaringPackage(this.jrtFileSystem, qualifiedPackageName, moduleName); return CharOperation.toCharArrays(modules); } @Override public boolean hasCompilationUnit(String qualifiedPackageName, String moduleName) { - return JRTUtil.hasCompilationUnit(this.file, qualifiedPackageName, moduleName); + return JRTUtil.hasCompilationUnit(this.jrtFileSystem, qualifiedPackageName, moduleName); } @Override public NameEnvironmentAnswer findClass(char[] typeName, String qualifiedPackageName, String moduleName, String qualifiedBinaryFileName) { @@ -84,7 +91,7 @@ public NameEnvironmentAnswer findClass(char[] typeName, String qualifiedPackageN return null; // most common case try { - IBinaryType reader = ClassFileReader.readFromModule(this.file, moduleName, qualifiedBinaryFileName, this.moduleNamesCache::contains); + IBinaryType reader = JRTUtil.getClassfile(this.jrtFileSystem, qualifiedBinaryFileName, moduleName, this.moduleNamesCache::contains); if (reader != null) { reader = maybeDecorateForExternalAnnotations(qualifiedBinaryFileName, reader); @@ -135,7 +142,7 @@ public char[][][] findTypeNames(final String qualifiedPackageName, final String final ArrayList answers = new ArrayList(); try { - JRTUtil.walkModuleImage(this.file, new JRTUtil.JrtFileVisitor() { + JRTUtil.walkModuleImage(this.jrtFileSystem, new JRTUtil.JrtFileVisitor() { @Override public FileVisitResult visitPackage(java.nio.file.Path dir, java.nio.file.Path modPath, BasicFileAttributes attrs) throws IOException { @@ -209,7 +216,7 @@ public void loadModules() { Map cache = ModulesCache.computeIfAbsent(this.file.getPath(), key -> { HashMap newCache = new HashMap<>(); try { - org.eclipse.jdt.internal.compiler.util.JRTUtil.walkModuleImage(this.file, + org.eclipse.jdt.internal.compiler.util.JRTUtil.walkModuleImage(this.jrtFileSystem, new org.eclipse.jdt.internal.compiler.util.JRTUtil.JrtFileVisitor() { @Override @@ -227,7 +234,7 @@ public FileVisitResult visitFile(Path f, Path mod, BasicFileAttributes attrs) @Override public FileVisitResult visitModule(Path p, String name) throws IOException { try { - ClasspathJrt.this.acceptModule(JRTUtil.getClassfile(ClasspathJrt.this.file, IModule.MODULE_INFO_CLASS, name), newCache); + ClasspathJrt.this.acceptModule(ClasspathJrt.this.jrtFileSystem.getClassfile(IModule.MODULE_INFO_CLASS, name), newCache); } catch (ClassFormatException e) { throw new IOException(e); } diff --git a/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/tool/EclipseCompilerImpl.java b/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/tool/EclipseCompilerImpl.java index a8ed78c2a21..fbb8d0bb2e9 100644 --- a/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/tool/EclipseCompilerImpl.java +++ b/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/tool/EclipseCompilerImpl.java @@ -540,7 +540,7 @@ protected void handleLocations() { EclipseFileManager efm = (EclipseFileManager) standardJavaFileManager; @SuppressWarnings("resource") // XXX EclipseFileManager should close jrtfs but it looks like standardJavaFileManager is never closed // Was leaking new JrtFileSystem(classpathJrt.file): - JrtFileSystem jrtfs = efm.getJrtFileSystem(classpathJrt.file); + JrtFileSystem jrtfs = efm.getJrtFileSystem(classpathJrt.file); // XXX use classpathJrt.jrtFileSystem?? efm.locationHandler.newSystemLocation(StandardLocation.SYSTEM_MODULES, jrtfs); } catch (IOException e) { String error = "Failed to create JRTFS from " + classpathJrt.file; //$NON-NLS-1$