Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix errors from java multi-file source launcher #6832

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading