mbien commented on code in PR #9151:
URL: https://github.com/apache/netbeans/pull/9151#discussion_r2734004313
##########
java/java.source.base/test/unit/src/org/netbeans/api/java/source/TreePathHandleTest.java:
##########
@@ -170,29 +172,40 @@ public void test134457() throws Exception {
public void testTreePathIsNotParsing() throws Exception {
FileObject file = FileUtil.createData(sourceRoot, "test/test.java");
-
writeIntoFile(file, "package test; public class test {}");
- writeIntoFile(FileUtil.createData(sourceRoot, "test/test2.java"),
"package test; public class test2 {}");
+
+ FileObject file2 = FileUtil.createData(sourceRoot, "test/test2.java");
+ writeIntoFile(file2, "package test; public class test2 {}");
JavaSource js = JavaSource.forFileObject(file);
SourceUtilsTestUtil.compileRecursively(sourceRoot);
- js.runUserActionTask(new Task<CompilationController>() {
- public void run(CompilationController parameter) throws Exception {
- parameter.toPhase(Phase.RESOLVED);
-
- TypeElement string =
parameter.getElements().getTypeElement("test.test2");
-
- SecurityManager old = System.getSecurityManager();
-
- System.setSecurityManager(new SecMan());
-
- TreePathHandle.create(string, parameter);
-
- System.setSecurityManager(old);
+ AtomicBoolean wasRead = new AtomicBoolean();
+
+ js.runUserActionTask(controller -> {
+ controller.toPhase(Phase.RESOLVED);
+
+ TypeElement string =
controller.getElements().getTypeElement("test.test2");
+
+ try (RecordingStream rs = new RecordingStream()) {
+ rs.setMaxSize(Long.MAX_VALUE);
+ rs.enable("jdk.FileRead").withoutThreshold().withStackTrace();
+ rs.onEvent("jdk.FileRead", e -> {
+ if (e.getString("path").endsWith("test2.java")) {
+ wasRead.set(true);
+ System.err.println(e);
+ }
+ });
+ rs.startAsync();
+// file2.getInputStream().read(); // check: commenting this in
should fail the test
+ TreePathHandle.create(string, controller);
+ // TODO call directly post JDK 21 bump
+ RecordingStream.class.getMethod("stop").invoke(rs); // flushes
stream
}
}, true);
+
+ assertFalse("file was read", wasRead.get());
Review Comment:
POC of how to replace `SecurityManager` based IO monitoring with `JFR`. This
wont work in all cases since the `jdk.FileRead/Write` events are for read/write
operations in the literal sense, not for file attribute access. (e.g the tests
in the versioning module will likely require a different approach to replace SM
usage there)
--
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