test UnitTestsCompilerOptionsQueryImplTest fails on Java 17 and Java 21
Apache NetBeans version
Apache NetBeans 26
What happened
While trying to triage #8560, I ran the tests for the package org.netbeans.modules.java.api.common.queries; because it
contains the file org.netbeans.modules.java.api.common.queries.ModuleInfoAccessibilityQueryImpl that @pedro-w metions in his patch.
The failures are: (ant output)
[junit] ------------- ---------------- ---------------
[junit] Testcase: testRootsChanges(org.netbeans.modules.java.api.common.queries.UnitTestsCompilerOptionsQueryImplTest): FAILED
[junit] expected:<[-XD-Xmodule:org.nb.App, --add-reads, org.nb.App=ALL-UNNAMED]> but was:<[]>
[junit] junit.framework.AssertionFailedError: expected:<[-XD-Xmodule:org.nb.App, --add-reads, org.nb.App=ALL-UNNAMED]> but was:<[]>
[junit] at org.netbeans.modules.java.api.common.queries.UnitTestsCompilerOptionsQueryImplTest.testRootsChanges(UnitTestsCompilerOptionsQueryImplTest.java:215)
[junit] at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
[junit] Jun 23, 2025 2:57:31 PM org.netbeans.modules.java.source.parsing.JavacParser validateSourceLevel
[junit] at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77)
[junit] at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
[junit] at org.netbeans.junit.NbTestCase.access$200(NbTestCase.java:84)
[junit] at org.netbeans.junit.NbTestCase$2.doSomething(NbTestCase.java:489)
[junit] at org.netbeans.junit.NbTestCase$1Guard.run(NbTestCase.java:410)
[junit] at java.base/java.lang.Thread.run(Thread.java:840)
[junit] WARNING: Even though the source level of /home/hom/homberghp/netbeans/master/java/java.api.common/build/test/unit/work/o.n.m.j.a.c.q.U/jdktiism/src is set to: 9, java.lang.AssertionError cannot be found on the bootclasspath:
[junit]
[junit]
[junit]
[junit] Testcase: testModuleInfoChanges(org.netbeans.modules.java.api.common.queries.UnitTestsCompilerOptionsQueryImplTest): FAILED
[junit] expected:<[-XD-Xmodule:org.nb.App, --add-reads, org.nb.App=ALL-UNNAMED]> but was:<[]>
[junit] Working directory: /home/hom/homberghp/netbeans/master/java/java.api.common/build/test/unit/work/o.n.m.j.a.c.q.U/jdktiism
[junit] junit.framework.AssertionFailedError: expected:<[-XD-Xmodule:org.nb.App, --add-reads, org.nb.App=ALL-UNNAMED]> but was:<[]>
[junit] at org.netbeans.modules.java.api.common.queries.UnitTestsCompilerOptionsQueryImplTest.testModuleInfoChanges(UnitTestsCompilerOptionsQueryImplTest.java:258)
[junit] at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
[junit] at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77)
[junit] at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
[junit] at org.netbeans.junit.NbTestCase.access$200(NbTestCase.java:84)
[junit] at org.netbeans.junit.NbTestCase$2.doSomething(NbTestCase.java:489)
[junit] at org.netbeans.junit.NbTestCase$1Guard.run(NbTestCase.java:410)
[junit] at java.base/java.lang.Thread.run(Thread.java:840)
[junit]
[junit]
[junit] Testcase: testJDK9_TestModule(org.netbeans.modules.java.api.common.queries.UnitTestsCompilerOptionsQueryImplTest): FAILED
[junit] expected:<[--add-reads, org.nb.AppTest=ALL-UNNAMED]> but was:<[]>
[junit] junit.framework.AssertionFailedError: expected:<[--add-reads, org.nb.AppTest=ALL-UNNAMED]> but was:<[]>
[junit] at org.netbeans.modules.java.api.common.queries.UnitTestsCompilerOptionsQueryImplTest.testJDK9_TestModule(UnitTestsCompilerOptionsQueryImplTest.java:145)
[junit] at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
[junit] at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77)
[junit] at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
[junit] at org.netbeans.junit.NbTestCase.access$200(NbTestCase.java:84)
[junit] at org.netbeans.junit.NbTestCase$2.doSomething(NbTestCase.java:489)
[junit] at org.netbeans.junit.NbTestCase$1Guard.run(NbTestCase.java:410)
[junit] at java.base/java.lang.Thread.run(Thread.java:840)
[junit]
[junit]
[junit] Testcase: testSourceLevelChanges(org.netbeans.modules.java.api.common.queries.UnitTestsCompilerOptionsQueryImplTest): FAILED
[junit] expected:<[-XD-Xmodule:org.nb.App, --add-reads, org.nb.App=ALL-UNNAMED]> but was:<[]>
[junit] junit.framework.AssertionFailedError: expected:<[-XD-Xmodule:org.nb.App, --add-reads, org.nb.App=ALL-UNNAMED]> but was:<[]>
[junit] at org.netbeans.modules.java.api.common.queries.UnitTestsCompilerOptionsQueryImplTest.testSourceLevelChanges(UnitTestsCompilerOptionsQueryImplTest.java:184)
[junit] at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
[junit] at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77)
[junit] at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
[junit] at org.netbeans.junit.NbTestCase.access$200(NbTestCase.java:84)
[junit] at org.netbeans.junit.NbTestCase$2.doSomething(NbTestCase.java:489)
[junit] at org.netbeans.junit.NbTestCase$1Guard.run(NbTestCase.java:410)
[junit] at java.base/java.lang.Thread.run(Thread.java:840)
[junit]
[junit]
[junit] Testcase: testModuleInfoCreation(org.netbeans.modules.java.api.common.queries.UnitTestsCompilerOptionsQueryImplTest): FAILED
[junit] expected:<[-XD-Xmodule:org.nb.App, --add-reads, org.nb.App=ALL-UNNAMED]> but was:<[]>
[junit] junit.framework.AssertionFailedError: expected:<[-XD-Xmodule:org.nb.App, --add-reads, org.nb.App=ALL-UNNAMED]> but was:<[]>
[junit] at org.netbeans.modules.java.api.common.queries.UnitTestsCompilerOptionsQueryImplTest.testModuleInfoCreation(UnitTestsCompilerOptionsQueryImplTest.java:239)
[junit] at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
[junit] at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77)
[junit] at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
[junit] at org.netbeans.junit.NbTestCase.access$200(NbTestCase.java:84)
[junit] at org.netbeans.junit.NbTestCase$2.doSomething(NbTestCase.java:489)
[junit] at org.netbeans.junit.NbTestCase$1Guard.run(NbTestCase.java:410)
[junit] at java.base/java.lang.Thread.run(Thread.java:840)
[junit]
[junit]
[junit] Testcase: testJDK9_TestInlinedIntoSourceModule(org.netbeans.modules.java.api.common.queries.UnitTestsCompilerOptionsQueryImplTest): FAILED
[junit] expected:<[-XD-Xmodule:org.nb.App, --add-reads, org.nb.App=ALL-UNNAMED]> but was:<[]>
[junit] junit.framework.AssertionFailedError: expected:<[-XD-Xmodule:org.nb.App, --add-reads, org.nb.App=ALL-UNNAMED]> but was:<[]>
[junit] at org.netbeans.modules.java.api.common.queries.UnitTestsCompilerOptionsQueryImplTest.testJDK9_TestInlinedIntoSourceModule(UnitTestsCompilerOptionsQueryImplTest.java:124)
[junit] at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
[junit] at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77)
[junit] at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
[junit] at org.netbeans.junit.NbTestCase.access$200(NbTestCase.java:84)
[junit] at org.netbeans.junit.NbTestCase$2.doSomething(NbTestCase.java:489)
[junit] at org.netbeans.junit.NbTestCase$1Guard.run(NbTestCase.java:410)
[junit] at java.base/java.lang.Thread.run(Thread.java:840)
[junit]
[junit]
[junit] Test org.netbeans.modules.java.api.common.queries.UnitTestsCompilerOptionsQueryImplTest FAILED
BUILD SUCCESSFUL
Total time: 3 seconds
These failures keep me from proposing a PR as proposed in #8560.
Language / Project Type / NetBeans Component
NB module java/java.api.common
How to reproduce
Build the module java/java.api.common
run the test with netbeans or with ant. The command line for ant is
ant -Dtest.type=unit -Dcontinue.after.failing.tests=true -Dtest.includes=org/netbeans/modules/java/api/common/queries/UnitTestsCompilerOptionsQueryImplTest.java test-single
Did this work correctly in an earlier version?
No / Don't know
Operating System
ubuntu 24.04
JDK
17 and 21
Apache NetBeans packaging
Apache NetBeans binary zip
Anything else
This problem is repeatable.
Not sure if these tests are still relevant. Currently the build seems to pass with either these failures, or the tests are not run.
Are you willing to submit a pull request?
Yes
This is the same kind of issue as #8560 actually - the addition of getModule() to the API.
I applied this patch
diff --git a/java/java.source.base/src/org/netbeans/modules/java/source/JavaSourceUtilImpl.java b/java/java.source.base/src/org/netbeans/modules/java/source/JavaSourceUtilImpl.java
index ddb82083e4..7611aa0fb0 100644
--- a/java/java.source.base/src/org/netbeans/modules/java/source/JavaSourceUtilImpl.java
+++ b/java/java.source.base/src/org/netbeans/modules/java/source/JavaSourceUtilImpl.java
@@ -290,12 +290,12 @@ public final class JavaSourceUtilImpl extends org.netbeans.modules.java.preproce
public String parseModuleName() throws IOException {
cc.toPhase(JavaSource.Phase.PARSED);
final CompilationUnitTree cu = cc.getCompilationUnit();
- for (Tree decl : cu.getTypeDecls()) {
- if (decl.getKind() == Tree.Kind.MODULE) {
- return ((ModuleTree) decl).getName().toString();
- }
+ ModuleTree decl = cu.getModule();
+ if (decl != null) {
+ return decl.getName().toString();
+ } else {
+ return null;
}
- return null;
}
@Override
and almost all the tests in the "Java Common Project API" will pass, apart from one failure which I can't see where it comes from:
Alright, that last test fail is because SourceLevelQueryImplTest tries to set a Security Manager and that's not allowed any more.
Can we just delete it do you think?
https://github.com/apache/netbeans/blob/e80ec881f2f4c1950c8e3a317ff2be2f35a20603/java/java.api.common/test/unit/src/org/netbeans/modules/java/api/common/queries/SourceLevelQueryImplTest.java#L66-L83
failing tests were disabled when the module was hooked into CI: https://github.com/apache/netbeans/pull/8621
This seems a bit wider than my original bug (I would bet not many people have been blocked by not being able to detect missing javadocs in a modular ant project!) so I think we should
- see if there are any other cases where this Java 17 API change has affected the code base
- make a single PR to get them all
- add missing tests for #8560
What do you think @homberghp ? I can look into the first and last of these but I think you've got more experience making pull requests than me
Following up on this, I found one other piece of code where this API change would have an effect but looking at its caller I don't believe it could ever have done anything anyway.
On the missing tests - I have written one but there is some hard-to-find problem that causes the implementation to fail when called from a test which doesn't happen when it's called from a real Netbeans project.
I can write up more details if anyone is interested - let me know!!