Skip to content

Commit

Permalink
Merge pull request #6832 from matthiasblaesing/fix_multifile_launcher2
Browse files Browse the repository at this point in the history
Fix errors from java multi-file source launcher
  • Loading branch information
matthiasblaesing authored Dec 12, 2023
2 parents 57b607c + 0f346ba commit ac3936a
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@
import java.util.List;
import java.util.Map;
import java.util.TreeMap;
import java.util.logging.Level;
import java.util.logging.Logger;
import java.util.stream.Collectors;
import org.netbeans.api.annotations.common.CheckForNull;
import org.netbeans.modules.java.file.launcher.api.SourceLauncher;
Expand All @@ -43,6 +45,8 @@
*/
public class SharedRootData {

private static final Logger LOG = Logger.getLogger(SharedRootData.class.getName());

private static final Map<FileObject, SharedRootData> root2Data = new HashMap<>();

public static synchronized void ensureRootRegistered(FileObject root) {
Expand Down Expand Up @@ -104,11 +108,14 @@ private synchronized void setNewProperties(Map<String, String> newProperties) {
}
String joinedCommandLine = SourceLauncher.joinCommandLines(options.values());
try {
if (!joinedCommandLine.equals(root.getAttribute(SingleSourceFileUtil.FILE_VM_OPTIONS))) {
if (
!root.getFileSystem().isReadOnly() // Skip read-only FSes (like JarFileSystem)
&& !joinedCommandLine.equals(root.getAttribute(SingleSourceFileUtil.FILE_VM_OPTIONS))
) {
root.setAttribute(SingleSourceFileUtil.FILE_VM_OPTIONS, joinedCommandLine);
}
} catch (IOException ex) {
Exceptions.printStackTrace(ex);
LOG.log(Level.INFO, "Failed to set " + SingleSourceFileUtil.FILE_VM_OPTIONS + " for " + root.getPath(), ex);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ private ClassPath getSourcePath(FileObject file) {
if (DISABLE_MULTI_SOURCE_ROOT) return null;
synchronized (this) {
//XXX: what happens if there's a Java file in user's home???
if (file.isData() && "text/x-java".equals(file.getMIMEType())) {
if (file.isValid() && file.isData() && "text/x-java".equals(file.getMIMEType())) {
return file2SourceCP.computeIfAbsent(file, f -> {
try {
String content = new String(file.asBytes(), FileEncodingQuery.getEncoding(file));
Expand Down

0 comments on commit ac3936a

Please sign in to comment.