From cbcd31185df4034aa835f3d4c29091a13bc4aa6a Mon Sep 17 00:00:00 2001 From: TDeSain Date: Tue, 19 Nov 2024 12:52:38 -0500 Subject: [PATCH] Handle empty SQL array values in DashboardDrawerRowMapper - Return an empty list if SQL array is null. - Check for single empty value in SQL array and return an empty list. - Convert valid SQL arrays to Java lists properly. --- .../dashboarddrawer/DashboardDrawerRowMapper.java | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/src/main/java/edu/harvard/dbmi/avillach/dictionary/dashboarddrawer/DashboardDrawerRowMapper.java b/src/main/java/edu/harvard/dbmi/avillach/dictionary/dashboarddrawer/DashboardDrawerRowMapper.java index 09eb99b..02ff597 100644 --- a/src/main/java/edu/harvard/dbmi/avillach/dictionary/dashboarddrawer/DashboardDrawerRowMapper.java +++ b/src/main/java/edu/harvard/dbmi/avillach/dictionary/dashboarddrawer/DashboardDrawerRowMapper.java @@ -25,10 +25,16 @@ public DashboardDrawer mapRow(ResultSet rs, int rowNum) throws SQLException { } private List convertSqlArrayToList(Array sqlArray) throws SQLException { - if (sqlArray == null) { + if (sqlArray == null ) { return List.of(); + } else { + Object[] arrayContents = (Object[]) sqlArray.getArray(); + // Check if the array contains a single empty value + if (arrayContents.length == 1 && "".equals(arrayContents[0])) { + return List.of(); + } else { + return Arrays.asList((String[]) sqlArray.getArray()); + } } - // Convert SQL Array to Java Array, then to List - return Arrays.asList((String[]) sqlArray.getArray()); } } \ No newline at end of file