11/*
2- * Copyright (c) 2011, 2022 Oracle and/or its affiliates. All rights reserved.
2+ * Copyright (c) 2011, 2025 Oracle and/or its affiliates. All rights reserved.
33 *
44 * This program and the accompanying materials are made available under the
55 * terms of the Eclipse Public License v. 2.0, which is available at
2121import java .lang .reflect .ParameterizedType ;
2222import java .lang .reflect .Type ;
2323import java .util .ArrayList ;
24- import java .util .Arrays ;
2524import java .util .Collection ;
2625import java .util .Collections ;
2726import java .util .LinkedList ;
@@ -280,13 +279,8 @@ protected void configure() {
280279 model .getPriority (ContainerResponseFilter .class )));
281280 }
282281 }
283-
284- _readerInterceptors .addAll (
285- StreamSupport .stream (processingProviders .getGlobalReaderInterceptors ().spliterator (), false )
286- .collect (Collectors .toList ()));
287- _writerInterceptors .addAll (
288- StreamSupport .stream (processingProviders .getGlobalWriterInterceptors ().spliterator (), false )
289- .collect (Collectors .toList ()));
282+ processingProviders .getGlobalReaderInterceptors ().forEach (_readerInterceptors ::add );
283+ processingProviders .getGlobalWriterInterceptors ().forEach (_writerInterceptors ::add );
290284
291285 if (resourceMethod != null ) {
292286 addNameBoundFiltersAndInterceptors (
@@ -458,9 +452,7 @@ private Response invoke(final RequestProcessingContext context, final Object res
458452 if (entityAnn .length == 0 ) {
459453 response .setEntityAnnotations (methodAnnotations );
460454 } else {
461- final Annotation [] mergedAnn = Arrays .copyOf (methodAnnotations ,
462- methodAnnotations .length + entityAnn .length );
463- System .arraycopy (entityAnn , 0 , mergedAnn , methodAnnotations .length , entityAnn .length );
455+ final Annotation [] mergedAnn = mergeDistinctAnnotations (methodAnnotations , entityAnn );
464456 response .setEntityAnnotations (mergedAnn );
465457 }
466458 }
@@ -487,6 +479,22 @@ private Response invoke(final RequestProcessingContext context, final Object res
487479 return jaxrsResponse ;
488480 }
489481
482+ private static Annotation [] mergeDistinctAnnotations (Annotation [] existing , Annotation [] newOnes ) {
483+ List <Annotation > merged = new ArrayList <>(existing .length + newOnes .length );
484+ Collections .addAll (merged , existing );
485+
486+ newOnesLoop :
487+ for (Annotation n : newOnes ) {
488+ for (Annotation ex : existing ) {
489+ if (ex == n ) {
490+ continue newOnesLoop ;
491+ }
492+ }
493+ merged .add (n );
494+ }
495+ return merged .toArray (new Annotation [0 ]);
496+ }
497+
490498 private Type unwrapInvocableResponseType (ContainerRequest request , Type entityType ) {
491499 if (isCompletionStageResponseType
492500 && request .resolveProperty (ServerProperties .UNWRAP_COMPLETION_STAGE_IN_WRITER_ENABLE , Boolean .FALSE )) {
0 commit comments