未验证 提交 0171ff6a 编写于 作者: K kezhenxu94 提交者: GitHub

Promote Integer to Long before multiplying to avoid numeric overflow (#5602)

上级 235fbe72
......@@ -27,7 +27,7 @@ import org.apache.skywalking.apm.commons.datacarrier.partition.IDataPartitioner;
public class Channels<T> {
private final QueueBuffer<T>[] bufferChannels;
private IDataPartitioner<T> dataPartitioner;
private BufferStrategy strategy;
private final BufferStrategy strategy;
private final long size;
public Channels(int channelSize, int bufferSize, IDataPartitioner<T> partitioner, BufferStrategy strategy) {
......@@ -36,12 +36,13 @@ public class Channels<T> {
bufferChannels = new QueueBuffer[channelSize];
for (int i = 0; i < channelSize; i++) {
if (BufferStrategy.BLOCKING.equals(strategy)) {
bufferChannels[i] = new ArrayBlockingQueueBuffer<T>(bufferSize, strategy);
bufferChannels[i] = new ArrayBlockingQueueBuffer<>(bufferSize, strategy);
} else {
bufferChannels[i] = new Buffer<T>(bufferSize, strategy);
bufferChannels[i] = new Buffer<>(bufferSize, strategy);
}
}
size = channelSize * bufferSize;
// noinspection PointlessArithmeticExpression
size = 1L * channelSize * bufferSize; // it's not pointless, it prevents numeric overflow before assigning an integer to a long
}
public boolean save(T data) {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册