From 62bea15ec763f09f2a8df1ba4266804b4e8641c3 Mon Sep 17 00:00:00 2001 From: Thomas <> Date: Fri, 1 Jul 2022 15:58:16 +0200 Subject: fix(matching): add null-check in custom comperator for address-search results --- .../auth/eidas/v2/controller/AdresssucheController.java | 12 +++++++++--- .../auth/eidas/v2/test/utils/AddressSearchResultTest.java | 3 ++- 2 files changed, 11 insertions(+), 4 deletions(-) (limited to 'modules/authmodule-eIDAS-v2/src') diff --git a/modules/authmodule-eIDAS-v2/src/main/java/at/asitplus/eidas/specific/modules/auth/eidas/v2/controller/AdresssucheController.java b/modules/authmodule-eIDAS-v2/src/main/java/at/asitplus/eidas/specific/modules/auth/eidas/v2/controller/AdresssucheController.java index 4bb1343a..6faa35fd 100644 --- a/modules/authmodule-eIDAS-v2/src/main/java/at/asitplus/eidas/specific/modules/auth/eidas/v2/controller/AdresssucheController.java +++ b/modules/authmodule-eIDAS-v2/src/main/java/at/asitplus/eidas/specific/modules/auth/eidas/v2/controller/AdresssucheController.java @@ -228,9 +228,15 @@ public class AdresssucheController { } int extractInt(String s) { - final String num = s.replaceAll("\\D", ""); - // return 0 if no digits found - return num.isEmpty() ? 0 : Integer.parseInt(num); + if (StringUtils.isNotEmpty(s)) { + final String num = s.replaceAll("\\D", ""); + // return 0 if no digits found + return num.isEmpty() ? 0 : Integer.parseInt(num); + + } else { + return 0; + + } } }; } diff --git a/modules/authmodule-eIDAS-v2/src/test/java/at/asitplus/eidas/specific/modules/auth/eidas/v2/test/utils/AddressSearchResultTest.java b/modules/authmodule-eIDAS-v2/src/test/java/at/asitplus/eidas/specific/modules/auth/eidas/v2/test/utils/AddressSearchResultTest.java index 89692ab7..fef157db 100644 --- a/modules/authmodule-eIDAS-v2/src/test/java/at/asitplus/eidas/specific/modules/auth/eidas/v2/test/utils/AddressSearchResultTest.java +++ b/modules/authmodule-eIDAS-v2/src/test/java/at/asitplus/eidas/specific/modules/auth/eidas/v2/test/utils/AddressSearchResultTest.java @@ -24,6 +24,7 @@ public class AddressSearchResultTest { buildRandom("3"), buildRandom("1"), buildRandom("10"), + buildRandom(null), buildRandom("10-12"), buildRandom("15") ); @@ -34,7 +35,7 @@ public class AddressSearchResultTest { assertArrayEquals("wrong order", - new Object[]{"1", "2", "3", "10", "15", "10-12"}, + new Object[]{null, "1", "2", "3", "10", "15", "10-12"}, sorted.toArray()); -- cgit v1.2.3