From 9b80d157a801cc4a35c61bc383aebf9d1d7dd69a Mon Sep 17 00:00:00 2001 From: Atanas Gegov Date: Thu, 31 Oct 2024 17:45:12 +0100 Subject: [PATCH] Return immutable Set for a Collection Fixes https://github.com/jwtk/jjwt/issues/965 --- .../main/java/io/jsonwebtoken/lang/Collections.java | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) diff --git a/api/src/main/java/io/jsonwebtoken/lang/Collections.java b/api/src/main/java/io/jsonwebtoken/lang/Collections.java index 01768fc64..326267da2 100644 --- a/api/src/main/java/io/jsonwebtoken/lang/Collections.java +++ b/api/src/main/java/io/jsonwebtoken/lang/Collections.java @@ -86,19 +86,13 @@ public static List of(T... elements) { /** * Returns the specified collection as a {@link Set} instance. * - * @param c the collection to represent as a set + * @param c the collection to be converted * @param collection element type - * @return a type-safe immutable {@code Set} containing the specified collection elements. + * @return a type-safe immutable {@code Set} containing the specified collection elements. * @since 0.12.0 */ public static Set asSet(Collection c) { - if (c instanceof Set) { - return (Set) c; - } - if (isEmpty(c)) { - return java.util.Collections.emptySet(); - } - return java.util.Collections.unmodifiableSet(new LinkedHashSet<>(c)); + return java.util.Collections.unmodifiableSet(new LinkedHashSet(c)); } /**