Uploaded image for project: 'Java Driver'
  1. Java Driver
  2. JAVA-5265

Java driver throws exception for asNumber for BsonDecimal128

    • Type: Icon: Bug Bug
    • Resolution: Fixed
    • Priority: Icon: Minor - P4 Minor - P4
    • 5.0.0
    • Affects Version/s: None
    • Component/s: BSON
    • Labels:
      None
    • Minor Change
    • Needed
    • Hide

      1. What would you like to communicate to the user about this feature?
      2. Would you like the user to see examples of the syntax and/or executable code and its output?
      3. Which versions of the driver/connector does this apply to?

      Show
      1. What would you like to communicate to the user about this feature? 2. Would you like the user to see examples of the syntax and/or executable code and its output? 3. Which versions of the driver/connector does this apply to?

      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

       

            Assignee:
            jeff.yemin@mongodb.com Jeffrey Yemin
            Reporter:
            evan.darke@mongodb.com Evan Darke
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: