Summary
The Javadoc for BsonValue.isNumber and BsonValue.asNumber indicates that true is returned "if the value is a BsonNumber". However, BsonDecimal128 extends BsonNumber and returns false for isNumber and throws an Exception for asNumber()
How to Reproduce
Java Driver version: "4.4.2"
@Test public void asNumber() { new BsonDecimal128(new Decimal128(1L)).asNumber(); } @Test public void isNumber() { Assert.assertTrue(new BsonDecimal128(new Decimal128(1L)).isNumber()); }
Produces failure:
There were 2 failures: 1) asNumber(com.xgen.mongot.index.query.pushdown.TestDocumentMatcher) org.bson.BsonInvalidOperationException: Value expected to be of a numerical BSON type is of unexpected type DECIMAL128 at org.bson.BsonValue.asNumber(BsonValue.java:81) at com.xgen.mongot.index.query.pushdown.TestDocumentMatcher.asNumber(TestDocumentMatcher.java:60) 2) isNumber(com.xgen.mongot.index.query.pushdown.TestDocumentMatcher) java.lang.AssertionError at org.junit.Assert.fail(Assert.java:87) at org.junit.Assert.assertTrue(Assert.java:42) at org.junit.Assert.assertTrue(Assert.java:53) at com.xgen.mongot.index.query.pushdown.TestDocumentMatcher.isNumber(TestDocumentMatcher.java:65)
Additional Background