From d00b9ad014b4e616787c171672e56f5c69367e98 Mon Sep 17 00:00:00 2001 From: Alexey Markevich Date: Tue, 6 Jun 2023 23:27:23 +0200 Subject: [PATCH] NO-JIRA artemis-core-client: minor SecurityFormatter improvement --- .../activemq/artemis/utils/SecurityFormatter.java | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/artemis-core-client/src/main/java/org/apache/activemq/artemis/utils/SecurityFormatter.java b/artemis-core-client/src/main/java/org/apache/activemq/artemis/utils/SecurityFormatter.java index 08c414d0ed..14d2b20c5b 100644 --- a/artemis-core-client/src/main/java/org/apache/activemq/artemis/utils/SecurityFormatter.java +++ b/artemis-core-client/src/main/java/org/apache/activemq/artemis/utils/SecurityFormatter.java @@ -16,10 +16,11 @@ */ package org.apache.activemq.artemis.utils; -import java.util.ArrayList; +import java.util.Collections; import java.util.HashSet; import java.util.List; import java.util.Set; +import java.util.StringTokenizer; import org.apache.activemq.artemis.core.security.Role; @@ -65,15 +66,11 @@ public class SecurityFormatter { return roles; } + @SuppressWarnings("unchecked") private static List toList(final String commaSeparatedString) { - List list = new ArrayList<>(); - if (commaSeparatedString == null || commaSeparatedString.trim().length() == 0) { - return list; + if (commaSeparatedString == null || commaSeparatedString.trim().isEmpty()) { + return Collections.emptyList(); } - String[] values = commaSeparatedString.split(","); - for (String value : values) { - list.add(value.trim()); - } - return list; + return List.class.cast(Collections.list(new StringTokenizer(commaSeparatedString, ", "))); } }