Promote Integer to Long before multiplying to avoid numeric overflow (#5602)
This commit is contained in:
parent
235fbe729c
commit
0171ff6a01
|
|
@ -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) {
|
||||
|
|
|
|||
Loading…
Reference in New Issue