apache/shardingsphere · error · UnsupportedDataTypeConversionException

0

0

Error message

Unsupported conversion data type '%s' for value '%s'.

What it means

UnsupportedDataTypeConversionException from MySQLResultSetValueConverter.convertValue: after switching on the target type, any NumberFormatException or ArithmeticException raised during numeric conversion is caught (and ignored) then rethrown as this typed exception naming the target class and value. 'Unsupported conversion data type %s for value %s' means the value could not be coerced into the requested type.

Source

Thrown at jdbc/src/main/java/org/apache/shardingsphere/driver/jdbc/core/resultset/MySQLResultSetValueConverter.java:74

                case "int":
                case "java.lang.Integer":
                    return stringValue.isEmpty() ? 0 : convertIntegralValue(stringValue, convertType).intValueExact();
                case "long":
                case "java.lang.Long":
                    return stringValue.isEmpty() ? 0L : convertIntegralValue(stringValue, convertType).longValueExact();
                case "double":
                case "java.lang.Double":
                    return stringValue.isEmpty() ? 0.0D : convertNumericValue(stringValue, convertType).doubleValue();
                case "float":
                case "java.lang.Float":
                    return stringValue.isEmpty() ? 0.0F : convertNumericValue(stringValue, convertType).floatValue();
                case "java.math.BigDecimal":
                    return stringValue.isEmpty() ? BigDecimal.ZERO : convertNumericValue(stringValue, convertType);
                default:
                    return ResultSetUtils.convertValue(value, convertType);
            }
        } catch (final NumberFormatException | ArithmeticException ignored) {
            throw new UnsupportedDataTypeConversionException(convertType, value);
        }
    }
    
    @Override
    public String getType() {
        return "MySQL";
    }
    
    private byte convertByteValue(final String value, final Class<?> convertType) {
        byte[] bytes = value.getBytes(StandardCharsets.UTF_8);
        if (1 != bytes.length) {
            throw new UnsupportedDataTypeConversionException(convertType, value);
        }
        return bytes[0];
    }
    
    private Boolean convertBooleanValue(final String value, final Class<?> convertType) {
        if ("Y".equalsIgnoreCase(value) || "yes".equalsIgnoreCase(value) || "T".equalsIgnoreCase(value) || "true".equalsIgnoreCase(value)) {

View on GitHub (pinned to e952770a21)

Solutions

  1. Match getters to the actual column type; for MySQL string-backed metadata values use getString and parse defensively.
  2. Validate/clean the value (null check, numeric regex) before requesting numeric conversion.
  3. If overflow/scale is the cause, retrieve as BigDecimal and narrow manually with explicit handling.

Example fix

// before
long rows = rs.getLong("ROWS");
// after
String raw = rs.getString("ROWS");
Long rows = (raw == null || !raw.matches("-?\\d+")) ? null : Long.parseLong(raw);
Defensive patterns

Strategy: validation

Validate before calling

String raw = rs.getString(col);
if (raw == null || !raw.matches("-?[\\d.eE]+")) handleBadValue(raw);

Try / catch

catch (UnsupportedDataTypeConversionException ex) { log offending value/type; fall back to getString parsing; }

Prevention

When it happens

Trigger: Calling getXxx on a metadata/converted ResultSet where the stored string cannot parse into the requested numeric type — e.g. getBigDecimal on 'abc', getDouble on a value overflowing the parse, or division/scale arithmetic failing.

Common situations: Reading MySQL SHOW-based metadata values (as strings) with the wrong getter type; null/empty-like or non-numeric content in a numeric column; charset or driver differences changing the raw value; upstream data corruption.

Related errors


AI-assisted analysis of apache/shardingsphere@e952770a21 (2026-08-14). Data as JSON: /api/errors/9d34c4ad6e9fd45b. Report an issue: GitHub.