Fix NPE in MemoryAwareThreadPoolExecutor and also add a testcase. See #634

This commit is contained in:
Norman Maurer 2012-10-01 06:57:12 +02:00
parent 04dc94575d
commit 8f4c583e40
2 changed files with 31 additions and 0 deletions

View File

@ -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;
}

View File

@ -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());
}
}