apache/shardingsphere · error · UnsupportedDataTypeConversionException
0
0
Error message
Unsupported conversion data type '%s' for value '%s'.
What it means
Thrown by ResultSetUtils.convertURL when a caller requests a column value as java.net.URL (rs.getObject(i, URL.class)) and the stored value's string form is not a parsable URL. The MalformedURLException from `new URL(value.toString())` is deliberately swallowed and re-raised as UnsupportedDataTypeConversionException naming the URL type and the offending value. ShardingSphere's JDBC result-set layer uses this utility to emulate the driver-level getObject-with-type contract.
Source
Thrown at infra/executor/src/main/java/org/apache/shardingsphere/infra/executor/sql/execute/result/query/impl/driver/jdbc/type/util/ResultSetUtils.java:201
return value.toInstant().atZone(ZoneId.systemDefault()).toLocalDate();
}
if (LocalTime.class.equals(convertType)) {
return value.toInstant().atZone(ZoneId.systemDefault()).toLocalTime();
}
if (OffsetDateTime.class.equals(convertType)) {
return value.toInstant().atZone(ZoneId.systemDefault()).toOffsetDateTime();
}
if (String.class.equals(convertType)) {
return value.toString();
}
return value;
}
private static Object convertURL(final Object value) {
try {
return new URL(value.toString());
} catch (final MalformedURLException ignored) {
throw new UnsupportedDataTypeConversionException(URL.class, value);
}
}
private static Object convertNumberValue(final Object value, final Class<?> convertType) {
Number number = (Number) value;
switch (convertType.getName()) {
case "boolean":
return longToBoolean(number.longValue());
case "byte":
case "java.lang.Byte":
return number.byteValue();
case "short":
case "java.lang.Short":
return number.shortValue();
case "int":
case "java.lang.Integer":
return number.intValue();
case "long":View on GitHub (pinned to e952770a21)
Solutions
- Fix the stored data to be fully-qualified URLs (include scheme, e.g. 'http://host:port/path').
- Read the column as String instead: rs.getString(i), then construct java.net.URL yourself with explicit error handling.
- Catch UnsupportedDataTypeConversionException around the getObject call and degrade to the raw string value.
Example fix
// before URL url = resultSet.getObject(1, java.net.URL.class); // after String raw = resultSet.getString(1); URL url = new URL(raw); // explicit MalformedURLException handling
Defensive patterns
Strategy: validation
Validate before calling
String raw = resultSet.getString(1);
java.net.URL url = null;
try { url = new java.net.URL(raw); } catch (java.net.MalformedURLException e) { /* handle bad data */ } Try / catch
try { URL u = rs.getObject(1, URL.class); } catch (UnsupportedDataTypeConversionException e) { URL u = fallbackParse(rs.getString(1)); } Prevention
- Store only fully-qualified URLs (scheme + host) in URL-typed columns.
- Validate URL shape at write time, not read time.
When it happens
Trigger: Calling getObject(index, java.net.URL.class) (or a driver path that maps to it) on a ShardingSphere ResultSet where the column text has no valid protocol, e.g. 'localhost:8080/path' without a scheme, 'not a url', or a value with embedded whitespace/control characters that makes java.net.URL constructor throw MalformedURLException.
Common situations: Columns typed as URL/DATALINK in metadata but holding free text or partially-qualified hosts; test fixtures and mock data with URL-shaped strings missing 'http://'; values copied from logs or user input that were never validated as URLs before being stored.
Related errors
AI-assisted analysis of apache/shardingsphere@e952770a21 (2026-08-14).
Data as JSON: /api/errors/51a79ddac0b0ec8d.
Report an issue: GitHub.