Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ public byte asByte()
@Override
public short asShort()
{
if (!isInByteRange()) {
if (!isInShortRange()) {
throw new MessageIntegerOverflowException(value);
}
return (short) value;
Expand Down
31 changes: 30 additions & 1 deletion msgpack-core/src/test/scala/org/msgpack/value/ValueTest.scala
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
package org.msgpack.value

import java.math.BigInteger

import org.msgpack.core._

import scala.util.parsing.json.JSON
Expand Down Expand Up @@ -97,5 +96,35 @@ class ValueTest extends MessagePackSpec

}

"check appropriate range for integers" in {
import ValueFactory._
import java.lang.Byte
import java.lang.Short

newInteger(Byte.MAX_VALUE).asByte() shouldBe Byte.MAX_VALUE
newInteger(Byte.MIN_VALUE).asByte() shouldBe Byte.MIN_VALUE
newInteger(Short.MAX_VALUE).asShort() shouldBe Short.MAX_VALUE
newInteger(Short.MIN_VALUE).asShort() shouldBe Short.MIN_VALUE
newInteger(Integer.MAX_VALUE).asInt() shouldBe Integer.MAX_VALUE
newInteger(Integer.MIN_VALUE).asInt() shouldBe Integer.MIN_VALUE
intercept[MessageIntegerOverflowException] {
newInteger(Byte.MAX_VALUE+1).asByte()
}
intercept[MessageIntegerOverflowException] {
newInteger(Byte.MIN_VALUE-1).asByte()
}
intercept[MessageIntegerOverflowException] {
newInteger(Short.MAX_VALUE+1).asShort()
}
intercept[MessageIntegerOverflowException] {
newInteger(Short.MIN_VALUE-1).asShort()
}
intercept[MessageIntegerOverflowException] {
newInteger(Integer.MAX_VALUE+1.toLong).asInt()
}
intercept[MessageIntegerOverflowException] {
newInteger(Integer.MIN_VALUE-1.toLong).asInt()
}
}
}
}