From 6cc15fb06c9490e349847e043eea7c188e88794e Mon Sep 17 00:00:00 2001 From: merabtenei Date: Sun, 28 May 2023 21:38:14 +0100 Subject: fix NullPointerException when attribute key is defined and value is set to null, caused by calling .toString() on null. --- src/main/java/org/traccar/model/ExtendedModel.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/org/traccar/model/ExtendedModel.java b/src/main/java/org/traccar/model/ExtendedModel.java index 6a4f502f7..d3d247fdd 100644 --- a/src/main/java/org/traccar/model/ExtendedModel.java +++ b/src/main/java/org/traccar/model/ExtendedModel.java @@ -90,7 +90,7 @@ public class ExtendedModel extends BaseModel { } public String getString(String key, String defaultValue) { - if (attributes.containsKey(key)) { + if (attributes.containsKey(key) && attributes.get(key) != null) { return attributes.get(key).toString(); } else { return defaultValue; -- cgit v1.2.3 From ef3088a09c42e518fe9c6a313b9c15523adb8b15 Mon Sep 17 00:00:00 2001 From: "I. MERABTENE" <95150308+merabtenei@users.noreply.github.com> Date: Mon, 29 May 2023 10:35:28 +0100 Subject: Update src/main/java/org/traccar/model/ExtendedModel.java Co-authored-by: Anton Tananaev --- src/main/java/org/traccar/model/ExtendedModel.java | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/main/java/org/traccar/model/ExtendedModel.java b/src/main/java/org/traccar/model/ExtendedModel.java index d3d247fdd..9da9c7529 100644 --- a/src/main/java/org/traccar/model/ExtendedModel.java +++ b/src/main/java/org/traccar/model/ExtendedModel.java @@ -90,8 +90,9 @@ public class ExtendedModel extends BaseModel { } public String getString(String key, String defaultValue) { - if (attributes.containsKey(key) && attributes.get(key) != null) { - return attributes.get(key).toString(); + if (attributes.containsKey(key)) { + Object value = attributes.get(key); + return value != null ? value.toString() : value; } else { return defaultValue; } -- cgit v1.2.3 From 46dabfabdc7b6cc12cbad9863e38ab1ff97c40a5 Mon Sep 17 00:00:00 2001 From: merabtenei Date: Mon, 29 May 2023 16:03:12 +0100 Subject: fix return null value --- src/main/java/org/traccar/model/ExtendedModel.java | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/main/java/org/traccar/model/ExtendedModel.java b/src/main/java/org/traccar/model/ExtendedModel.java index d3d247fdd..0a0923ba1 100644 --- a/src/main/java/org/traccar/model/ExtendedModel.java +++ b/src/main/java/org/traccar/model/ExtendedModel.java @@ -90,8 +90,9 @@ public class ExtendedModel extends BaseModel { } public String getString(String key, String defaultValue) { - if (attributes.containsKey(key) && attributes.get(key) != null) { - return attributes.get(key).toString(); + if (attributes.containsKey(key)) { + Object value = attributes.containsKey(key); + return value != null ? value.toString() : null; } else { return defaultValue; } -- cgit v1.2.3 From d244b4bc4999ba3e3dca607bf797c3f7d7f578ff Mon Sep 17 00:00:00 2001 From: merabtenei Date: Mon, 29 May 2023 18:07:31 +0100 Subject: fix typo: replaced .containsKey with .get --- src/main/java/org/traccar/model/ExtendedModel.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/org/traccar/model/ExtendedModel.java b/src/main/java/org/traccar/model/ExtendedModel.java index 0a0923ba1..d5cd094da 100644 --- a/src/main/java/org/traccar/model/ExtendedModel.java +++ b/src/main/java/org/traccar/model/ExtendedModel.java @@ -91,7 +91,7 @@ public class ExtendedModel extends BaseModel { public String getString(String key, String defaultValue) { if (attributes.containsKey(key)) { - Object value = attributes.containsKey(key); + Object value = attributes.get(key); return value != null ? value.toString() : null; } else { return defaultValue; -- cgit v1.2.3