From 23392f8d468c46d59a5643be8e1296337bb29a80 Mon Sep 17 00:00:00 2001 From: Sam Freund Date: Sun, 1 Feb 2026 20:09:13 -0600 Subject: [PATCH] Add missing early-return to legacy ML model load (#2347) ## Description Previously, when attempting to load a model that did not follow the old naming pattern that was in the models directory, we caused PV to crash due to a missing early return (reproducable on this branch with the extra bonus ML model and missing label file): ``` [2026-02-01 17:35:15] [Config - NeuralNetworkModelManager] [ERROR] Model properties are null. This could mean the config for model /home/matth/photonvision/test-resources/old_configs/2025.3.1-old-nnmm/models/iCauseProblems.rknn was unable to be found in the database. Trying legacy... [2026-02-01 17:35:15] [Config - NeuralNetworkModelManager] [ERROR] Failed to translate legacy model filename to properties: /home/matth/photonvision/test-resources/old_configs/2025.3.1-old-nnmm/models/iCauseProblems.rknn: /home/matth/photonvision/test-resources/old_configs/2025.3.1-old-nnmm/models/iCauseProblems-labels.txt SQLConfigTest > testLoadNewNNMM() FAILED java.lang.NullPointerException: Cannot invoke "org.photonvision.common.configuration.NeuralNetworkModelsSettings$ModelProperties.toString()" because "properties" is null at org.photonvision.common.configuration.NeuralNetworkModelManager.loadModel(NeuralNetworkModelManager.java:342) at java.base/java.util.stream.ForEachOps$ForEachOp$OfRef.accept(ForEachOps.java:183) ``` This PR fixes it by adding the missing early-return, and adding unit tests to make sure we handle this. ## Meta Merge checklist: - [x] Pull Request title is [short, imperative summary](https://cbea.ms/git-commit/) of proposed changes - [x] The description documents the _what_ and _why_, including events that led to this PR - [ ] If this PR changes behavior or adds a feature, user documentation is updated - [ ] If this PR touches photon-serde, all messages have been regenerated and hashes have not changed unexpectedly - [ ] If this PR touches configuration, this is backwards compatible with all settings going back to the previous seasons's last release (seasons end after champs ends) - [ ] If this PR touches pipeline settings or anything related to data exchange, the frontend typing is updated - [x] If this PR addresses a bug, a regression test for it is added --------- Co-authored-by: Matt M --- .../common/configuration/NeuralNetworkModelManager.java | 3 ++- .../old_configs/2025.3.1-old-nnmm/models/iCauseProblems.rknn | 0 .../old_configs/2025.3.1-old-nnmm/models/iCauseProblems.tflite | 0 3 files changed, 2 insertions(+), 1 deletion(-) create mode 100644 test-resources/old_configs/2025.3.1-old-nnmm/models/iCauseProblems.rknn create mode 100644 test-resources/old_configs/2025.3.1-old-nnmm/models/iCauseProblems.tflite diff --git a/photon-core/src/main/java/org/photonvision/common/configuration/NeuralNetworkModelManager.java b/photon-core/src/main/java/org/photonvision/common/configuration/NeuralNetworkModelManager.java index 9180c6363..b1df50fa4 100644 --- a/photon-core/src/main/java/org/photonvision/common/configuration/NeuralNetworkModelManager.java +++ b/photon-core/src/main/java/org/photonvision/common/configuration/NeuralNetworkModelManager.java @@ -321,7 +321,7 @@ public class NeuralNetworkModelManager { ConfigManager.getInstance().getConfig().neuralNetworkPropertyManager().getModel(path); if (properties == null) { - logger.error( + logger.warn( "Model properties are null. This could mean the config for model " + path + " was unable to be found in the database. Trying legacy..."); @@ -336,6 +336,7 @@ public class NeuralNetworkModelManager { .addModelProperties(properties); } catch (IllegalArgumentException | IOException e) { logger.error("Failed to translate legacy model filename to properties: " + path, e); + return; } } diff --git a/test-resources/old_configs/2025.3.1-old-nnmm/models/iCauseProblems.rknn b/test-resources/old_configs/2025.3.1-old-nnmm/models/iCauseProblems.rknn new file mode 100644 index 000000000..e69de29bb diff --git a/test-resources/old_configs/2025.3.1-old-nnmm/models/iCauseProblems.tflite b/test-resources/old_configs/2025.3.1-old-nnmm/models/iCauseProblems.tflite new file mode 100644 index 000000000..e69de29bb