Michael Metzinger created AVRO-4198:
---------------------------------------
Summary: Generated SpecificRecord.equals() fails to compare String
fields in complex types after round-trip serialization
Key: AVRO-4198
URL: https://issues.apache.org/jira/browse/AVRO-4198
Project: Apache Avro
Issue Type: Bug
Components: java
Affects Versions: 1.12.1
Reporter: Michael Metzinger
After upgrading to 1.12.1 from 1.12.0, the generated equals() method in
SpecificRecords does not properly handle String comparison for complex types
(arrays, maps, unions) containing string values.
Reproduction steps:
1. Use avro-maven-plugin 1.12.1 to create a SpecificRecord for this schema
{code:java}
{"namespace": "some.namespace",
"type": "record",
"name": "SomeSpecificType",
"fields": [
{"name": "str", "type": "string"},
{
"name": "array",
"type": {
"type": "array",
"items": "string"
}
},
{ "name": "map",
"type": {
"type": "map",
"values": "string"
}
},
{ "name": "union", "type" : ["int", "string"] }
]
} {code}
2. Then running the following JUnit test case will fail
{code:java}
@Test
void testRoundTripEquality() throws IOException {
Map<CharSequence, CharSequence> map = new HashMap<>();
map.put("key1", "1");
map.put("key2", "2");
map.put("key3", "3");
SomeSpecificType before = new SomeSpecificType("some string",
Arrays.asList("a", "b", "c"), map, "str val");
ByteBuffer buffer = SomeSpecificType.getEncoder().encode(before);
SomeSpecificType after = SomeSpecificType.getDecoder().decode(buffer);
assertEquals(before, after); //Fails in 1.12.1 but works in 1.12.0
} {code}
If we instead use 1.12.0 to generate the class, and run the test, it works as
expected. but with 1.12.1 it fails.
--
This message was sent by Atlassian Jira
(v8.20.10#820010)