Skip to content

Commit 610553e

Browse files
committed
Merge pull request #287 from mecp/v07-develop
asShort in ImmutableLongValueImpl should check isInShortRange
2 parents e40d59f + 6b9d5d3 commit 610553e

File tree

2 files changed

+31
-2
lines changed

2 files changed

+31
-2
lines changed

msgpack-core/src/main/java/org/msgpack/value/impl/ImmutableLongValueImpl.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ public byte asByte()
158158
@Override
159159
public short asShort()
160160
{
161-
if (!isInByteRange()) {
161+
if (!isInShortRange()) {
162162
throw new MessageIntegerOverflowException(value);
163163
}
164164
return (short) value;

msgpack-core/src/test/scala/org/msgpack/value/ValueTest.scala

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
package org.msgpack.value
1717

1818
import java.math.BigInteger
19-
2019
import org.msgpack.core._
2120

2221
import scala.util.parsing.json.JSON
@@ -97,5 +96,35 @@ class ValueTest extends MessagePackSpec
9796

9897
}
9998

99+
"check appropriate range for integers" in {
100+
import ValueFactory._
101+
import java.lang.Byte
102+
import java.lang.Short
103+
104+
newInteger(Byte.MAX_VALUE).asByte() shouldBe Byte.MAX_VALUE
105+
newInteger(Byte.MIN_VALUE).asByte() shouldBe Byte.MIN_VALUE
106+
newInteger(Short.MAX_VALUE).asShort() shouldBe Short.MAX_VALUE
107+
newInteger(Short.MIN_VALUE).asShort() shouldBe Short.MIN_VALUE
108+
newInteger(Integer.MAX_VALUE).asInt() shouldBe Integer.MAX_VALUE
109+
newInteger(Integer.MIN_VALUE).asInt() shouldBe Integer.MIN_VALUE
110+
intercept[MessageIntegerOverflowException] {
111+
newInteger(Byte.MAX_VALUE+1).asByte()
112+
}
113+
intercept[MessageIntegerOverflowException] {
114+
newInteger(Byte.MIN_VALUE-1).asByte()
115+
}
116+
intercept[MessageIntegerOverflowException] {
117+
newInteger(Short.MAX_VALUE+1).asShort()
118+
}
119+
intercept[MessageIntegerOverflowException] {
120+
newInteger(Short.MIN_VALUE-1).asShort()
121+
}
122+
intercept[MessageIntegerOverflowException] {
123+
newInteger(Integer.MAX_VALUE+1.toLong).asInt()
124+
}
125+
intercept[MessageIntegerOverflowException] {
126+
newInteger(Integer.MIN_VALUE-1.toLong).asInt()
127+
}
128+
}
100129
}
101130
}

0 commit comments

Comments
 (0)