mirror of
https://github.com/bitcoinj/bitcoinj.git
synced 2024-11-20 02:09:29 +01:00
Improve Coin range check to cope with Long.MIN_VALUE correctly
This commit is contained in:
parent
f40785fbdf
commit
bb368c9543
@ -82,9 +82,11 @@ public final class Coin implements Monetary, Comparable<Coin>, Serializable {
|
||||
*/
|
||||
public final long value;
|
||||
|
||||
private final long MAX_SATOSHIS = COIN_VALUE * NetworkParameters.MAX_COINS;
|
||||
|
||||
private Coin(final long satoshis) {
|
||||
checkArgument(Math.abs(satoshis) <= COIN_VALUE * NetworkParameters.MAX_COINS,
|
||||
"%s satoshis exceeds maximum possible quantity of Bitcoin.", satoshis);
|
||||
checkArgument(-MAX_SATOSHIS <= satoshis && satoshis <= MAX_SATOSHIS,
|
||||
"%s satoshis exceeds maximum possible quantity of Bitcoin.", satoshis);
|
||||
this.value = satoshis;
|
||||
}
|
||||
|
||||
|
@ -62,6 +62,11 @@ public class CoinTest {
|
||||
} catch (IllegalArgumentException e) {
|
||||
}
|
||||
|
||||
try {
|
||||
valueOf(Long.MIN_VALUE);
|
||||
fail();
|
||||
} catch (IllegalArgumentException e) {}
|
||||
|
||||
try {
|
||||
valueOf(1, -1);
|
||||
fail();
|
||||
|
Loading…
Reference in New Issue
Block a user