Skip to content

Commit

Permalink
Make for fileObjects uninterruptible
Browse files Browse the repository at this point in the history
In some cases, the system libraries still become unaccessible after an
interrupted thread.
This patch aims at ensuring the libraries are always made
uninterruptible upon access.
  • Loading branch information
mickaelistria committed Dec 19, 2024
1 parent 3d3f6fc commit b415e6b
Showing 1 changed file with 40 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
package org.eclipse.jdt.internal.javac;

import java.io.IOException;
import java.lang.reflect.Field;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
Expand All @@ -20,8 +21,13 @@

import javax.annotation.processing.Processor;
import javax.tools.FileObject;
import javax.tools.ForwardingFileObject;
import javax.tools.ForwardingJavaFileManager;
import javax.tools.JavaFileManager;
import javax.tools.JavaFileObject;
import javax.tools.JavaFileObject.Kind;

import org.eclipse.core.runtime.ILog;

import com.sun.source.util.Plugin;
import com.sun.tools.javac.file.PathFileObject;
Expand Down Expand Up @@ -100,13 +106,44 @@ public JavaFileManager getFileManager() {
public void close() {
// do nothing, to keep instance usable in the future
}
@Override
public FileObject getFileForInput(Location location, String packageName, String relativeName) throws IOException {
var res = super.getFileForInput(location, packageName, relativeName);
if (res instanceof PathFileObject pathFileObject) {
ZipFileSystemProviderWithCache.makeFileSystemUninterruptible(pathFileObject.getPath().getFileSystem());
}
makeUnderlyingFileObjectUninterruptible(res);
return res;
}
@Override
public JavaFileObject getJavaFileForInput(Location location, String className, Kind kind) throws IOException {
var res = super.getJavaFileForInput(location, className, kind);
makeUnderlyingFileObjectUninterruptible(res);
return res;
}
@Override
public Iterable<JavaFileObject> list(Location location, String packageName, java.util.Set<Kind> kinds, boolean recurse) throws IOException {
var res = super.list(location, packageName, kinds, recurse);
res.forEach(this::makeUnderlyingFileObjectUninterruptible);
return res;
}
private void makeUnderlyingFileObjectUninterruptible(FileObject fo) {
PathFileObject toUninterrupted = null;
if (fo instanceof PathFileObject o) {
toUninterrupted = o;
}
if (fo instanceof ForwardingFileObject<?> forwarding) {
try {
Field fileObjectField = ForwardingFileObject.class.getDeclaredField("fileObject");
Object o = fileObjectField.get(forwarding);
if (o instanceof PathFileObject pathFileObject) {
toUninterrupted = pathFileObject;
}
} catch (Exception e) {
ILog.get().error(e.getMessage(), e);
}
}
if (toUninterrupted != null) {
ZipFileSystemProviderWithCache.makeFileSystemUninterruptible(toUninterrupted.getPath().getFileSystem());
}
}
});
}

Expand Down

0 comments on commit b415e6b

Please sign in to comment.