Skip to content

Commit 90c1d37

Browse files
authored
Merge pull request #20 from asdf-format/eslavich/fix-long-as-int-bug
Allow longs within int range to be cast to int
2 parents 6e51602 + 52f55d0 commit 90c1d37

1 file changed

Lines changed: 3 additions & 1 deletion

File tree

‎asdf-core/src/main/java/org/asdfformat/asdf/node/impl/NumberAsdfNode.java‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,8 +131,10 @@ public float asFloat() {
131131
public int asInt() {
132132
if (value instanceof Byte || value instanceof Short || value instanceof Integer) {
133133
return value.intValue();
134+
} else if (value instanceof Long && (long) value >= Integer.MIN_VALUE && (long) value <= Integer.MAX_VALUE) {
135+
return value.intValue();
134136
} else {
135-
throw new IllegalStateException("Node cannot be represented as long");
137+
throw new IllegalStateException("Node cannot be represented as int");
136138
}
137139
}
138140

0 commit comments

Comments
 (0)