diff --git a/src/main/java/org/jboss/netty/handler/execution/MemoryAwareThreadPoolExecutor.java b/src/main/java/org/jboss/netty/handler/execution/MemoryAwareThreadPoolExecutor.java index 47d07a14db..bb38b21ef9 100644 --- a/src/main/java/org/jboss/netty/handler/execution/MemoryAwareThreadPoolExecutor.java +++ b/src/main/java/org/jboss/netty/handler/execution/MemoryAwareThreadPoolExecutor.java @@ -380,6 +380,9 @@ public class MemoryAwareThreadPoolExecutor extends ThreadPoolExecutor { * Returns the maximum total size of the queued events for this pool. */ public long getMaxTotalMemorySize() { + if (totalLimiter == null) { + return 0; + } return totalLimiter.limit; } diff --git a/src/test/java/org/jboss/netty/handler/execution/MemoryAwareThreadPoolExecutorTest.java b/src/test/java/org/jboss/netty/handler/execution/MemoryAwareThreadPoolExecutorTest.java new file mode 100644 index 0000000000..54865d609f --- /dev/null +++ b/src/test/java/org/jboss/netty/handler/execution/MemoryAwareThreadPoolExecutorTest.java @@ -0,0 +1,28 @@ +/* + * Copyright 2011 The Netty Project + * + * The Netty Project licenses this file to you under the Apache License, + * version 2.0 (the "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at: + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations + * under the License. + */package org.jboss.netty.handler.execution; + +import static org.junit.Assert.*; +import org.junit.Test; + +public class MemoryAwareThreadPoolExecutorTest { + + // See https://github.com/netty/netty/issues/634 + @Test + public void testNPEOnUnlimetedExecutor() { + MemoryAwareThreadPoolExecutor executor = new MemoryAwareThreadPoolExecutor(2, 0, 0); + assertEquals(0, executor.getMaxTotalMemorySize()); + } +}