Fail cleanly when the registry path has no directory

SpotBugs flagged a null passed to Files.createTempFile: the null check guarded
only createDirectories, while the temporary file creation would still have
dereferenced it. The path is resolved absolute so this is practically
unreachable, but bailing out with a log line is cheaper than the latent NPE.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Hpa6bjie5qkeNG62y6FmXm
This commit is contained in:
Rsclub2_2andClaude Opus 5 committed 2026-10-05 22:27:47 +02:00
1 parent 679453b433
commit a53be727da
1 file changed
+10 -4
@@ -348,11 +348,17 @@ public class OperatorProfileStore {
Path targetPath = Path.of(registryFilePath).toAbsolutePath(); Path targetPath = Path.of(registryFilePath).toAbsolutePath();
Path parentDirectory = targetPath.getParent(); Path parentDirectory = targetPath.getParent();
try { if (parentDirectory == null) {
if (parentDirectory != null) { LOGGER.log(Level.SEVERE,
Files.createDirectories(parentDirectory); "The operator profile registry path has no directory: {0}", registryFilePath);
} return false;
}
try {
Files.createDirectories(parentDirectory);
// The temporary file has to live next to the target so the final move can be
// atomic; both must be on the same file system.
Path temporaryPath = Files.createTempFile( Path temporaryPath = Files.createTempFile(
parentDirectory, PROFILES_REGISTRY_FILE, ".tmp"); parentDirectory, PROFILES_REGISTRY_FILE, ".tmp");