Closed
Description
BUG 报告
问题
核心阻塞队列枚举类中方法 BlockingQueueTypeEnum.createBlockingQueue(String blockingQueueName, Integer capacity)
在参数均为null
时,会抛出异常
java.lang.NullPointerException: Cannot invoke "java.lang.Integer.intValue()" because "capacity" is null
预期行为
生成new LinkedBlockingQueue<T>(DEFAULT_CAPACITY);
原因分析
正常逻辑,代码已覆盖如下各自情况
blockingQueueName
和capacity
均合法:正常生成blockingQueueName
为空,capacity
合法:会在私有方法customOrDefaultQueue(Integer capacity, Predicate<CustomBlockingQueue> predicate)
中返回默认阻塞队列return new LinkedBlockingQueue<T>(temCapacity);
blockingQueueName
合法,capacity
不合法:会在私有方法of(String blockingQueueName, Integer capacity)
中调用各阻塞队列的构造方法。capacity
为null
不同阻塞队列会调用各自无参构造方法或者使用DEFAULT_CAPACITY
;capacity <=0
会由各阻塞队列抛出IllegalArgumentException
。
异常
- 当
blockingQueueName
为null
或使用不存在的字符串,capacity
为null
: 最终会进入私有方法customOrDefaultQueue(Integer capacity, Predicate<CustomBlockingQueue> predicate)
中,此时
int temCapacity = capacity;
Integer为null并赋值给int会抛出NPE。
问题重现步骤
调用方法
BlockingQueueTypeEnum.createBlockingQueue("abc", null);
BlockingQueueTypeEnum.createBlockingQueue(null, null)
修复办法
将temCapacity
修改为Integer
, 或者capacity
判空的条件前置