Details
-
Bug
-
Status: Open
-
Minor
-
Resolution: Unresolved
-
None
-
None
-
None
Description
It appears that for default value for Byte type (and Decimal logical type if it uses underlying Bytes type) value rendered with getDefaultValue is cached. This leads to bugs when you read the same value (for example if converted with DecimalConversion). For single thread environment workaround would be to reset ByteBuffer after read, but in concurrent environment we should not cache mutable objects.
@Test(expected=NumberFormatException.class) public void testReuse() { Conversions.DecimalConversion decimalConversion = new Conversions.DecimalConversion(); LogicalType logicalDecimal = LogicalTypes.decimal(38, 9); ByteBuffer defaultValue = decimalConversion.toBytes( BigDecimal.valueOf(42L).setScale(9), null, logicalDecimal); Schema schema = SchemaBuilder .record("test") .fields() .name("decimal") .type(logicalDecimal.addToSchema(SchemaBuilder.builder().bytesType())) .withDefault(defaultValue) .endRecord(); BigDecimal firstRead = decimalConversion .fromBytes( (ByteBuffer) GenericData.get().getDefaultValue(schema.getField("decimal")), null, logicalDecimal); BigDecimal secondRead = decimalConversion .fromBytes( (ByteBuffer) GenericData.get().getDefaultValue(schema.getField("decimal")), null, logicalDecimal); }
Attachments
Issue Links
- is related to
-
AVRO-2592 Avro decimal fails on certain conditions - ByteBuffer.position() is the root cause
- Resolved