From 174c77a0376b8b29a50fc6cb8e0bace65bf9ec09 Mon Sep 17 00:00:00 2001 From: Claude Date: Mon, 7 Sep 2026 08:04:38 +0000 Subject: [PATCH] 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 Claude-Session: https://claude.ai/code/session_01Hpa6bjie5qkeNG62y6FmXm --- .../controller/OperatorProfileStore.java | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/src/main/java/kst4contest/controller/OperatorProfileStore.java b/src/main/java/kst4contest/controller/OperatorProfileStore.java index b2354e19..c2c3e9e3 100644 --- a/src/main/java/kst4contest/controller/OperatorProfileStore.java +++ b/src/main/java/kst4contest/controller/OperatorProfileStore.java @@ -348,11 +348,17 @@ public class OperatorProfileStore { Path targetPath = Path.of(registryFilePath).toAbsolutePath(); Path parentDirectory = targetPath.getParent(); - try { - if (parentDirectory != null) { - Files.createDirectories(parentDirectory); - } + if (parentDirectory == null) { + LOGGER.log(Level.SEVERE, + "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( parentDirectory, PROFILES_REGISTRY_FILE, ".tmp");