Uploaded image for project: 'Kafka'
  1. Kafka
  2. KAFKA-16288

Values.convertToDecimal throws ClassCastExceptions on String inputs

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Resolved
    • Minor
    • Resolution: Fixed
    • 1.1.0
    • 3.8.0
    • connect
    • None

    Description

      The convertToDecimal function does a best-effort conversion of an arbitrary Object to a BigDecimal. Generally when a conversion cannot take place (such as when an unknown subclass is passed-in) the function throws a DataException. However, specifically for String inputs with valid number within, a ClassCastException is thrown.

      This is because there is an extra "doubleValue" call in the implementation: https://github.com/apache/kafka/blob/ead2431c37ace9255df88ffe819bb905311af088/connect/api/src/main/java/org/apache/kafka/connect/data/Values.java#L427 which immediately causes a ClassCastException in the caller: https://github.com/apache/kafka/blob/ead2431c37ace9255df88ffe819bb905311af088/connect/api/src/main/java/org/apache/kafka/connect/data/Values.java#L305 

      This appears accidental, because the case for String is explicitly handled, it just behaves poorly. Instead of the ClassCastException, the number should be parsed correctly.

      Attachments

        Issue Links

          Activity

            People

              gharris1727 Greg Harris
              gharris1727 Greg Harris
              Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: