From b80fbd46f7f4157bc6bc2c67c19d07413fa7e026 Mon Sep 17 00:00:00 2001 From: Artem Bilan Date: Wed, 13 Jun 2018 14:25:43 -0400 Subject: [PATCH] Fix varargs warn for CompositeProducerListener **Cherry-pick to 2.1.x** --- .../kafka/support/CompositeProducerListener.java | 5 +++++ .../org/springframework/kafka/core/KafkaTemplateTests.java | 3 ++- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/spring-kafka/src/main/java/org/springframework/kafka/support/CompositeProducerListener.java b/spring-kafka/src/main/java/org/springframework/kafka/support/CompositeProducerListener.java index 4f022aa7ad..ca72657572 100644 --- a/spring-kafka/src/main/java/org/springframework/kafka/support/CompositeProducerListener.java +++ b/spring-kafka/src/main/java/org/springframework/kafka/support/CompositeProducerListener.java @@ -30,7 +30,9 @@ * * @param the key type. * @param the value type. + * * @author Gary Russell + * @author Artem Bilan * * @since 2.1.6 * @@ -40,13 +42,16 @@ public class CompositeProducerListener implements ProducerListener { private final List> delegates = new CopyOnWriteArrayList<>(); @SafeVarargs + @SuppressWarnings("varargs") public CompositeProducerListener(ProducerListener... delegates) { setDelegates(delegates); } @SafeVarargs + @SuppressWarnings("varargs") public final void setDelegates(ProducerListener... delegates) { Assert.notNull(delegates, "'delegates' cannot be null"); + Assert.noNullElements(delegates, "'delegates' cannot contain null elements"); this.delegates.clear(); this.delegates.addAll(Arrays.asList(delegates)); } diff --git a/spring-kafka/src/test/java/org/springframework/kafka/core/KafkaTemplateTests.java b/spring-kafka/src/test/java/org/springframework/kafka/core/KafkaTemplateTests.java index 96a83994c6..4ada7938a8 100644 --- a/spring-kafka/src/test/java/org/springframework/kafka/core/KafkaTemplateTests.java +++ b/spring-kafka/src/test/java/org/springframework/kafka/core/KafkaTemplateTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2017 the original author or authors. + * Copyright 2016-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -268,6 +268,7 @@ public void onError(ProducerRecord producerRecord, Exception ex } PL pl1 = new PL(); PL pl2 = new PL(); + @SuppressWarnings("unchecked") CompositeProducerListener cpl = new CompositeProducerListener<>(pl1, pl2); template.setProducerListener(cpl); template.sendDefault("foo");