From 0504a442aefa918af7e70872b589ad73ccad5863 Mon Sep 17 00:00:00 2001 From: Norman Maurer Date: Sun, 10 Mar 2013 21:06:59 +0100 Subject: [PATCH] Check for NPE and also optimze HashSet allocation --- .../netty/channel/ChannelPromiseAggregator.java | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/transport/src/main/java/io/netty/channel/ChannelPromiseAggregator.java b/transport/src/main/java/io/netty/channel/ChannelPromiseAggregator.java index 0bff77709f..850223b8fa 100644 --- a/transport/src/main/java/io/netty/channel/ChannelPromiseAggregator.java +++ b/transport/src/main/java/io/netty/channel/ChannelPromiseAggregator.java @@ -32,16 +32,31 @@ public final class ChannelPromiseAggregator implements ChannelFutureListener { private Set pendingPromises; public ChannelPromiseAggregator(ChannelPromise aggregatePromise) { + if (aggregatePromise == null) { + throw new NullPointerException("aggregatePromise"); + } this.aggregatePromise = aggregatePromise; } + /** + * Add the given {@link ChannelPromise}s to the aggregator. + */ public ChannelPromiseAggregator add(ChannelPromise... promises) { if (promises == null) { throw new NullPointerException("promises"); } + if (promises.length == 0) { + return this; + } synchronized (this) { if (pendingPromises == null) { - pendingPromises = new HashSet(); + int size; + if (promises.length > 1) { + size = promises.length; + } else { + size = 2; + } + pendingPromises = new HashSet(size); } for (ChannelPromise p: promises) { if (p == null) {