Details
-
Bug
-
Status: Closed
-
Major
-
Resolution: Fixed
-
None
Description
Validation of numeric default values is incorrect and results in API inconsistencies. Below are a few examples.
Double value as int default value:
public void testDoubleAsIntDefaultValue() { Schema.Field field = new Schema.Field("myField", Schema.create(Schema.Type.INT), "doc", 1.1); field.hasDefaultValue(); // true field.defaultValue(); // internal DoubleNode (1.1) field.defaultVal(); // null GenericData.get().getDefaultValue(field); // Integer (1) field = new Schema.Field("myField", Schema.create(Schema.Type.INT), "doc", 1.0); field.hasDefaultValue(); // true field.defaultValue(); // internal DoubleNode (1.0) field.defaultVal(); // null GenericData.get().getDefaultValue(field); // Integer (1) }
Invalid long as int default value:
public void testInvalidLongAsIntDefault() { Schema.Field field = new Schema.Field("myField", Schema.create(Schema.Type.INT), "doc", Integer.MAX_VALUE + 1L); field.hasDefaultValue(); // true field.defaultValue(); // internal LongNode (2147483648) field.defaultVal(); // Long (2147483648) GenericData.get().getDefaultValue(field); // Integer (-2147483648) }
Additionally, since the underlying Schema.FIeld.defaultValue() is no longer public it's not possible for users to disable default value validation and reliably validate schemas independently.
Attachments
Issue Links
- links to