apple/pkl · error · FormatException
double
Error message
double
What it means
FormatException("double", value.getClass()) is thrown by DependencyMetadata.parsePObject when the `value` field of a DataSize entry is present but not a JSON number (Double). DataSize values must be numeric; strings like "10mb" or booleans are rejected. It indicates a wrong-typed value in the metadata.
Source
Thrown at pkl-core/src/main/java/org/pkl/core/packages/DependencyMetadata.java:253
}
return new PObject(classInfo, properties);
}
case "Pattern" -> {
var value = jsObj.getString("value");
return Pattern.compile(value);
}
case "DataSize" -> {
var symbol = jsObj.getString("unit");
var value = jsObj.get("value");
if (value == null) {
throw new MissingFieldException(jsObj, "value");
}
var unit = DataSizeUnit.parse(symbol);
if (unit == null) {
throw new PklException("Invalid DataSize unit symbol: " + symbol);
}
if (!(value instanceof Double num)) {
throw new FormatException("double", value.getClass());
}
return new DataSize(num, unit);
}
case "Duration" -> {
var symbol = jsObj.getString("unit");
var value = jsObj.get("value");
if (value == null) {
throw new MissingFieldException(jsObj, "value");
}
var unit = DurationUnit.parse(symbol);
if (unit == null) {
throw new PklException("Invalid Duration unit symbol: " + symbol);
}
if (!(value instanceof Double num)) {
throw new FormatException("double", value.getClass());
}
return new Duration(num, unit);
}View on GitHub (pinned to f3efcbfc9b)
Solutions
- Write `value` as an unquoted JSON number: {"value": 10.0}.
- Move any unit text out of the string and into the `unit` field.
- Regenerate metadata with `pkl project package` to ensure correct typing.
- Fix converters/tools that stringify numeric fields during serialization.
Example fix
// before
{"type": "DataSize", "unit": "mb", "value": "10"}
// after
{"type": "DataSize", "unit": "mb", "value": 10.0} Defensive patterns
Strategy: validation
Validate before calling
if (entry.get("type").asString().equals("DataSize")) {
var v = entry.get("value");
if (v == null || !v.isNumber()) throw new IllegalStateException("DataSize 'value' must be a JSON number, got: " + v);
} Prevention
- Never quote numeric values in metadata JSON.
- Split combined strings like "10.5mb" into numeric value plus unit field.
- Configure converters/serializers to keep numbers unquoted.
- Validate value types with a JSON schema in CI.
When it happens
Trigger: Parsing metadata with a DataSize entry such as {"type": "DataSize", "unit": "mb", "value": "10"} — value is a string rather than a JSON number.
Common situations: Hand-writing annotations and quoting the number; custom generators serializing sizes as formatted strings like "10.5mb"; YAML-to-JSON conversions turning numbers into strings.
Understand the failure class
Background: Type mismatch errors: IllegalArgumentException, TypeError and type guards across 150 open-source libraries — this error's family across 150 libraries.
Related errors
AI-assisted analysis of apple/pkl@f3efcbfc9b (2026-09-08).
Data as JSON: /api/errors/6f512738e76c1772.
Report an issue: GitHub.