From f4a152ed29edf8f8266420df52daaa14f5d7747d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andreas=20Sch=C3=A4rtl?= <andreas@schaertl.me> Date: Fri, 2 Oct 2020 10:46:00 +0200 Subject: [PATCH] app: fix: do not crash on empty Meta fields --- .../java/info/mathhub/uloapi/query/Meta.java | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/src/ulo-storage-applications/src/main/java/info/mathhub/uloapi/query/Meta.java b/src/ulo-storage-applications/src/main/java/info/mathhub/uloapi/query/Meta.java index cbd263d..346463d 100644 --- a/src/ulo-storage-applications/src/main/java/info/mathhub/uloapi/query/Meta.java +++ b/src/ulo-storage-applications/src/main/java/info/mathhub/uloapi/query/Meta.java @@ -28,15 +28,15 @@ public class Meta { public String paratype; public String getName() { - return this.name; + return this.nonNullString(this.name); } public String getSourceref() { - return this.sourceref; + return this.nonNullString(this.sourceref); } public String getParatype() { - return this.paratype; + return this.nonNullString(this.paratype); } @Override @@ -47,4 +47,15 @@ public class Meta { ); } + /** + * @return Return argument {@code s} if {@code s} is not {@code null}. + * If {@code} s} is {@code null}, return an empty {@code String}. + */ + private String nonNullString(String s) { + if (s == null) { + return ""; + } else { + return s; + } + } } -- GitLab