Greg Harris created KAFKA-16288:
-----------------------------------

             Summary: Values.convertToDecimal throws ClassCastExceptions on 
String inputs
                 Key: KAFKA-16288
                 URL: https://issues.apache.org/jira/browse/KAFKA-16288
             Project: Kafka
          Issue Type: Bug
          Components: connect
    Affects Versions: 1.1.0
            Reporter: Greg Harris
            Assignee: Greg Harris


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.



--
This message was sent by Atlassian Jira
(v8.20.10#820010)

Reply via email to