Include more details if we throw an IllegalArgumentException because of overflow (#10330)
Motivation: We should include as much details as possible when throwing an IllegalArgumentException because of overflow in CompositeByteBuf Modifications: Add more details and factor out check into a static method to share code Result: Make it more clear why an operations failed
This commit is contained in:
parent
32a77394a3
commit
4dfe541167
@ -266,6 +266,13 @@ public class CompositeByteBuf extends AbstractReferenceCountedByteBuf implements
|
|||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static void checkForOverflow(int capacity, int readableBytes) {
|
||||||
|
if (capacity + readableBytes < 0) {
|
||||||
|
throw new IllegalArgumentException("Can't increase by " + readableBytes + " as capacity(" + capacity + ")" +
|
||||||
|
" would overflow " + Integer.MAX_VALUE);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Precondition is that {@code buffer != null}.
|
* Precondition is that {@code buffer != null}.
|
||||||
*/
|
*/
|
||||||
@ -281,9 +288,7 @@ public class CompositeByteBuf extends AbstractReferenceCountedByteBuf implements
|
|||||||
|
|
||||||
// Check if we would overflow.
|
// Check if we would overflow.
|
||||||
// See https://github.com/netty/netty/issues/10194
|
// See https://github.com/netty/netty/issues/10194
|
||||||
if (capacity() + readableBytes < 0) {
|
checkForOverflow(capacity(), readableBytes);
|
||||||
throw new IllegalArgumentException("Can't increase by " + readableBytes);
|
|
||||||
}
|
|
||||||
|
|
||||||
addComp(cIndex, c);
|
addComp(cIndex, c);
|
||||||
wasAdded = true;
|
wasAdded = true;
|
||||||
@ -373,9 +378,7 @@ public class CompositeByteBuf extends AbstractReferenceCountedByteBuf implements
|
|||||||
|
|
||||||
// Check if we would overflow.
|
// Check if we would overflow.
|
||||||
// See https://github.com/netty/netty/issues/10194
|
// See https://github.com/netty/netty/issues/10194
|
||||||
if (capacity + readableBytes < 0) {
|
checkForOverflow(capacity, readableBytes);
|
||||||
throw new IllegalArgumentException("Can't increase by " + readableBytes);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
// only set ci after we've shifted so that finally block logic is always correct
|
// only set ci after we've shifted so that finally block logic is always correct
|
||||||
int ci = Integer.MAX_VALUE;
|
int ci = Integer.MAX_VALUE;
|
||||||
|
Loading…
Reference in New Issue
Block a user