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

java.diagnostic.filter is broken on Windows #3290

Closed
Kamii0909 opened this issue Sep 27, 2024 · 2 comments · Fixed by #3292
Closed

java.diagnostic.filter is broken on Windows #3290

Kamii0909 opened this issue Sep 27, 2024 · 2 comments · Fixed by #3292
Assignees
Labels

Comments

@Kamii0909
Copy link

[Error - 1:09:17 PM] Sep 27, 2024, 1:09:17 PM An internal error occurred during: "Publish Diagnostics".
Illegal char <:> at index 2: /D:/jdtls/src/App.java
java.nio.file.InvalidPathException: Illegal char <:> at index 2: /D:/jdtls/src/App.java
	at java.base/sun.nio.fs.WindowsPathParser.normalize(WindowsPathParser.java:204)
	at java.base/sun.nio.fs.WindowsPathParser.parse(WindowsPathParser.java:175)
	at java.base/sun.nio.fs.WindowsPathParser.parse(WindowsPathParser.java:77)
	at java.base/sun.nio.fs.WindowsPath.parse(WindowsPath.java:92)
	at java.base/sun.nio.fs.WindowsFileSystem.getPath(WindowsFileSystem.java:231)
	at java.base/java.nio.file.Path.of(Path.java:148)
	at java.base/java.nio.file.Paths.get(Paths.java:69)
	at org.eclipse.jdt.ls.core.internal.JDTUtils.isExcludedFile(JDTUtils.java:1871)
	at org.eclipse.jdt.ls.core.internal.handlers.BaseDiagnosticsHandler.matchesDiagnosticFilter(BaseDiagnosticsHandler.java:154)
	at org.eclipse.jdt.ls.core.internal.handlers.BaseDiagnosticsHandler.endReporting(BaseDiagnosticsHandler.java:138)
	at org.eclipse.jdt.internal.core.ReconcileWorkingCopyOperation.reportProblems(ReconcileWorkingCopyOperation.java:141)
	at org.eclipse.jdt.internal.core.ReconcileWorkingCopyOperation.executeOperation(ReconcileWorkingCopyOperation.java:110)
	at org.eclipse.jdt.internal.core.JavaModelOperation.run(JavaModelOperation.java:739)
	at org.eclipse.jdt.internal.core.JavaModelOperation.runOperation(JavaModelOperation.java:804)
	at org.eclipse.jdt.internal.core.CompilationUnit.reconcile(CompilationUnit.java:1303)
	at org.eclipse.jdt.ls.core.internal.handlers.BaseDocumentLifeCycleHandler.publishDiagnostics(BaseDocumentLifeCycleHandler.java:332)
	at org.eclipse.jdt.ls.core.internal.handlers.BaseDocumentLifeCycleHandler.publishDiagnostics(BaseDocumentLifeCycleHandler.java:295)
	at org.eclipse.jdt.ls.core.internal.handlers.BaseDocumentLifeCycleHandler$PublishDiagnosticJob.run(BaseDocumentLifeCycleHandler.java:777)
	at org.eclipse.core.internal.jobs.Worker.run(Worker.java:63)

This is due to improper path handling in JDTUtils. Applying the following patch (sort of) works:

diff --git a/org.eclipse.jdt.ls.core/src/org/eclipse/jdt/ls/core/internal/JDTUtils.java b/org.eclipse.jdt.ls.core/src/org/eclipse/jdt/ls/core/internal/JDTUtils.java
index 79af9970..d609a397 100644
--- a/org.eclipse.jdt.ls.core/src/org/eclipse/jdt/ls/core/internal/JDTUtils.java
+++ b/org.eclipse.jdt.ls.core/src/org/eclipse/jdt/ls/core/internal/JDTUtils.java
@@ -25,6 +25,7 @@ import java.net.URISyntaxException;
 import java.nio.file.FileSystem;
 import java.nio.file.Files;
 import java.nio.file.Paths;
+import java.nio.file.InvalidPathException;
 import java.util.ArrayList;
 import java.util.Collections;
 import java.util.Iterator;
@@ -1869,7 +1870,7 @@ public final class JDTUtils {
 		java.nio.file.Path[] path = new java.nio.file.Path[1];
 		try {
 			path[0] = Paths.get(uri.toURL().getPath());
-		} catch (MalformedURLException e) {
+		} catch (MalformedURLException | InvalidPathException e) {
 			path[0] = Paths.get(uri);
 		}
 		FileSystem fileSystems = path[0].getFileSystem();

And due to escaping, java.diagnostic.filter must be set to something like **\\\\src\\\\Foo.java. Technically, it is also possible to manually convert from Unix path to Windows path to support the the same configuration on both platform.

@rgrunber rgrunber added the bug label Sep 30, 2024
@rgrunber rgrunber added this to the End October 2024 milestone Sep 30, 2024
@rgrunber
Copy link
Contributor

I'm able to reproduce. It prevents the language server from starting (when java.diagnostic.filter is used on Windows). Might be related to https://github.com/eclipse-jdtls/eclipse.jdt.ls/pull/3235/files#diff-38af31aa96ae8ee1debae74bf388b43dea8891646b1032ecdb2f4a7ea3e06f8cR1871 , which fixed some encoding issues on Linux.

There should be a way to get a path from the uri without it failing.

@snjeza
Copy link
Contributor

snjeza commented Oct 1, 2024

And due to escaping, java.diagnostic.filter must be set to something like **\\src\\Foo.java. Technically, it is also possible to manually convert from Unix path to Windows path to support the the same configuration on both platform.

I have tried the following pattern on Windows:

"java.diagnostic.filter": [
        "**/src/main/java/**/HelloWorld.java"
 ],   

It works fine with the PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants