lahodaj commented on PR #8897:
URL: https://github.com/apache/netbeans/pull/8897#issuecomment-3405048741
I was looking at the test. The test is testing the DAP client, by running
the `java.lsp.server`'s Java DAP server and stepping using that.
The reason why the test fails is, I think, this: the test does not specify
any `testRun` parameter, and hence the autodetect is used. The autodetect asks
if a the given file is a main class, and uses the test actions if it is not.
And, when run in this tests, `isMainClass` returns `false`, so the test actions
are used, but there are no test actions available for the file. And hence the
debugger backend will fail to start.
There are multiple aspects to this:
- maybe the test should explicitly say it does not want a test run:
```
diff --git
a/ide/lsp.client/test/unit/src/org/netbeans/modules/lsp/client/debugger/DebuggerTest.java
b/ide/lsp.client/test/unit/src/org/netbeans/modules/lsp/client/debugger/DebuggerTest.java
index 3718f1f2ed..8736be5755 100644
---
a/ide/lsp.client/test/unit/src/org/netbeans/modules/lsp/client/debugger/DebuggerTest.java
+++
b/ide/lsp.client/test/unit/src/org/netbeans/modules/lsp/client/debugger/DebuggerTest.java
@@ -125,7 +125,8 @@ public class DebuggerTest extends NbTestCase {
.addConfiguration(Map.of("type", "java+",
"request", "launch",
"file",
FileUtil.toFile(testFile).getAbsolutePath(),
- "classPaths",
List.of("any")))
+ "classPaths",
List.of("any"),
+ "testRun", false))
.launch();
waitFor(true, () ->
DebuggerManager.getDebuggerManager().getSessions().length > 0);
assertEquals(1,
DebuggerManager.getDebuggerManager().getSessions().length);
@@ -198,7 +199,8 @@ public class DebuggerTest extends NbTestCase {
.addConfiguration(Map.of("type", "java+",
"request", "launch",
"file",
FileUtil.toFile(testFile).getAbsolutePath(),
- "classPaths",
List.of("any")))
+ "classPaths",
List.of("any"),
+ "testRun", false))
.launch();
waitFor(true, () ->
DebuggerManager.getDebuggerManager().getSessions().length > 0);
assertEquals(1,
DebuggerManager.getDebuggerManager().getSessions().length);
```
- when autodetection runs, ignoring the `UnitTestForSourceQuery` feels a bit
suspicious to me. Not sure how things work for Gradle, but if anything goes
wrong with the `isMainClass`, the launcher will default to use the test actions
instead of non-test actions, and that is, I think, likely to fail outside of
test roots for "normal" projects. In other words, it errs on the side of use of
the test actions, rather than the non-test actions. I still think the test
actions should never be used outside of test roots (is there something specific
in Gradle that would require running files in ordinary non-test roots using
*test* actions?):
```
diff --git
a/java/java.lsp.server/src/org/netbeans/modules/java/lsp/server/debugging/launch/NbLaunchDelegate.java
b/java/java.lsp.server/src/org/netbeans/modules/java/lsp/server/debugging/launch/NbLaunchDelegate.java
index a488f1bca3..93cbc81339 100644
---
a/java/java.lsp.server/src/org/netbeans/modules/java/lsp/server/debugging/launch/NbLaunchDelegate.java
+++
b/java/java.lsp.server/src/org/netbeans/modules/java/lsp/server/debugging/launch/NbLaunchDelegate.java
@@ -60,6 +60,7 @@ import
org.netbeans.api.extexecution.base.ExplicitProcessParameters;
import org.netbeans.api.extexecution.ExecutionDescriptor;
import org.netbeans.api.extexecution.ExecutionService;
import org.netbeans.api.java.classpath.ClassPath;
+import org.netbeans.api.java.queries.UnitTestForSourceQuery;
import org.netbeans.api.java.source.ClasspathInfo;
import org.netbeans.api.java.source.SourceUtils;
import org.netbeans.api.project.FileOwnerQuery;
@@ -578,11 +579,13 @@ public abstract class NbLaunchDelegate {
if (sourceCP != null) {
FileObject root = sourceCP.findOwnerRoot(toRun);
if (root != null) {
- String relativePath = FileUtil.getRelativePath(root,
toRun);
- if (relativePath != null &&
relativePath.toLowerCase(Locale.ENGLISH).endsWith(JAVA_FILE_EXT)) {
- String className = relativePath.substring(0,
relativePath.length() - JAVA_FILE_EXT.length()).replace('/', '.');
- ClasspathInfo cpi = ClasspathInfo.create(toRun);
- mainSource = SourceUtils.isMainClass(className,
cpi, true);
+ if (UnitTestForSourceQuery.findSources(root).length >
0) {
+ String relativePath =
FileUtil.getRelativePath(root, toRun);
+ if (relativePath != null &&
relativePath.toLowerCase(Locale.ENGLISH).endsWith(JAVA_FILE_EXT)) {
+ String className = relativePath.substring(0,
relativePath.length() - JAVA_FILE_EXT.length()).replace('/', '.');
+ ClasspathInfo cpi = ClasspathInfo.create(toRun);
+ mainSource = SourceUtils.isMainClass(className,
cpi, true);
+ }
}
}
}
```
- the reason why `isMainClass` returns `false` in this test is, I think,
that the indexing is not run on the source root. In theory, that would be
solvable, but in practice, it probably should not matter much, and (if needed)
using an explicit `"testRun": false` as above would be easier and more reliable.
-
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]
For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists