gnodet commented on code in PR #3591:
URL: https://github.com/apache/maven-surefire/pull/3591#discussion_r4792286442
##########
surefire-api/src/main/java/org/apache/maven/surefire/api/util/TempFileManager.java:
##########
@@ -148,6 +150,17 @@ public synchronized File createTempFile(String prefix,
String suffix) {
throw new UncheckedIOException(new IOException("Unable to create
temporary file " + tempFile));
}
+ // run with this class' own permissions: under a SecurityManager,
every frame on the call
+ // stack needs file permissions on the temp directory, including
whatever unrelated,
+ // possibly restricted code (e.g. a test or an OSGi bundle) merely
called System.out.println()
+ // and ended up here via ConsoleOutputCapture
+ String finalPrefix = prefix;
+ String finalSuffix = suffix;
+ return AccessController.doPrivileged(
+ (PrivilegedAction<File>) () -> createTempFileOrRetry(tempFile,
finalPrefix, finalSuffix));
+ }
+
+ private File createTempFileOrRetry(File tempFile, String prefix, String
suffix) {
Review Comment:
_Claude Code on behalf of Guillaume Nodet_
**Thread Safety Issue**: This method should be `synchronized` because it:
1. Accesses `tempFiles` collection (line 164 and later in the method)
2. Is not currently synchronized but relies on being called from a
synchronized context
Making it synchronized ensures the contract is explicit and prevents future
bugs.
##########
surefire-api/src/main/java/org/apache/maven/surefire/api/util/TempFileManager.java:
##########
@@ -148,6 +150,17 @@ public synchronized File createTempFile(String prefix,
String suffix) {
throw new UncheckedIOException(new IOException("Unable to create
temporary file " + tempFile));
}
+ // run with this class' own permissions: under a SecurityManager,
every frame on the call
+ // stack needs file permissions on the temp directory, including
whatever unrelated,
+ // possibly restricted code (e.g. a test or an OSGi bundle) merely
called System.out.println()
+ // and ended up here via ConsoleOutputCapture
+ String finalPrefix = prefix;
+ String finalSuffix = suffix;
+ return AccessController.doPrivileged(
Review Comment:
_Claude Code on behalf of Guillaume Nodet_
**Nested doPrivileged blocks**: When `createTempFileOrRetry()` calls
`createTempFile()` recursively (on filename collision), it creates nested
privileged blocks:
```
createTempFile() → doPrivileged() → createTempFileOrRetry() →
createTempFile() → doPrivileged()
```
While semantically correct, this is inefficient. Consider whether the
privileged scope can be minimized to just the actual I/O operations (`mkdirs()`
and `createNewFile()`), though this would require more significant refactoring.
This is a minor optimization concern—the current approach is correct.
--
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]