From fe0c2fa36513b1b3bf2b2f0820efacc5e78be577 Mon Sep 17 00:00:00 2001 From: Kevin Birk Date: Tue, 2 Jul 2024 14:19:53 -0400 Subject: [PATCH] Fix NPE when getting model config lists (#4017) Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> --- .../models/dataservice/model/Model.java | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/packages/server/src/main/java/software/uncharted/terarium/hmiserver/models/dataservice/model/Model.java b/packages/server/src/main/java/software/uncharted/terarium/hmiserver/models/dataservice/model/Model.java index d886a0ef27..e495b0f443 100644 --- a/packages/server/src/main/java/software/uncharted/terarium/hmiserver/models/dataservice/model/Model.java +++ b/packages/server/src/main/java/software/uncharted/terarium/hmiserver/models/dataservice/model/Model.java @@ -99,7 +99,9 @@ public Model clone() { @JsonIgnore @TSIgnore public List getObservables() { - if (this.getSemantics() == null || this.getSemantics().getOde() == null) { + if (this.getSemantics() == null + || this.getSemantics().getOde() == null + || this.getSemantics().getOde().getObservables() == null) { return new ArrayList(); } return this.getSemantics().getOde().getObservables(); @@ -111,12 +113,13 @@ public List getParameters() { final ObjectMapper objectMapper = new ObjectMapper(); if (this.isRegnet()) { return objectMapper.convertValue(this.getModel().get("parameters"), new TypeReference<>() {}); - } else { - if (this.getSemantics() == null || this.getSemantics().getOde() == null) { - return new ArrayList(); - } - return this.getSemantics().getOde().getParameters(); } + if (this.getSemantics() == null + || this.getSemantics().getOde() == null + || this.getSemantics().getOde().getParameters() == null) { + return new ArrayList(); + } + return this.getSemantics().getOde().getParameters(); } @JsonIgnore @@ -126,7 +129,9 @@ public List getInitials() { if (this.isRegnet()) { return objectMapper.convertValue(this.getModel().get("initials"), new TypeReference<>() {}); } else { - if (this.getSemantics() == null || this.getSemantics().getOde() == null) { + if (this.getSemantics() == null + || this.getSemantics().getOde() == null + || this.getSemantics().getOde().getInitials() == null) { return new ArrayList(); } return this.getSemantics().getOde().getInitials();