Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

核心阻塞队列枚举 BlockingQueueTypeEnum.createBlockingQueue(String blockingQueueName, Integer capacity)抛出NPE问题修复 #1111

Closed
LiXuemin opened this issue Mar 15, 2023 · 2 comments · Fixed by #1117
Assignees
Milestone

Comments

@LiXuemin
Copy link
Contributor

LiXuemin commented Mar 15, 2023

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);

原因分析

正常逻辑,代码已覆盖如下各自情况

  1. blockingQueueNamecapacity均合法:正常生成
  2. blockingQueueName 为空,capacity合法:会在私有方法customOrDefaultQueue(Integer capacity, Predicate<CustomBlockingQueue> predicate)中返回默认阻塞队列return new LinkedBlockingQueue<T>(temCapacity);
  3. blockingQueueName合法,capacity不合法:会在私有方法of(String blockingQueueName, Integer capacity) 中调用各阻塞队列的构造方法。capacitynull不同阻塞队列会调用各自无参构造方法或者使用DEFAULT_CAPACITYcapacity <=0会由各阻塞队列抛出IllegalArgumentException

异常

  1. blockingQueueNamenull或使用不存在的字符串,capacitynull: 最终会进入私有方法customOrDefaultQueue(Integer capacity, Predicate<CustomBlockingQueue> predicate)中,此时
int temCapacity = capacity;

Integer为null并赋值给int会抛出NPE。

问题重现步骤

调用方法

BlockingQueueTypeEnum.createBlockingQueue("abc", null);

BlockingQueueTypeEnum.createBlockingQueue(null, null)

修复办法

temCapacity修改为Integer, 或者capacity判空的条件前置

@LiXuemin
Copy link
Contributor Author

如果确认,请分配给我。

@pirme pirme added this to the 1.5.0 milestone Mar 15, 2023
@pirme
Copy link
Member

pirme commented Mar 15, 2023

@LiXuemin welcome

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment