[
https://issues.apache.org/jira/browse/AVRO-4150?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17956820#comment-17956820
]
Chad Parry commented on AVRO-4150:
----------------------------------
The following complete test case illustrates how this issue leads to data
corruption. Note that the implementation neither detects the ambiguity nor
resolves it with a leading dot in the type name.
{{ @Test }}
{{ void testAmbiguousReference() { }}
{{ final Schema target = SchemaBuilder.builder() }}
{{ .record("Target") }}
{{ .doc("right") }}
{{ .fields() }}
{{ .endRecord(); }}
{{ final Schema decoy = SchemaBuilder.builder() }}
{{ .record(target.getName()) }}
{{ .namespace("org.apache.avro") }}
{{ .doc("wrong") }}
{{ .fields() }}
{{ .endRecord(); }}
{{ final Schema ambiguous = SchemaBuilder.builder() }}
{{ .record("Ambiguous") }}
{{ .fields() }}
{{ .name("definition") }}
{{ .type(target) }}
{{ .noDefault() }}
{{ .name("working") }}
{{ .type(target) }}
{{ .noDefault() }}
{{ .name("enclosing") }}
{{ .type(SchemaBuilder.builder() }}
{{ .record("Enclosing") }}
{{ .namespace("org.apache.avro") }}
{{ .fields() }}
{{ .name("decoy") }}
{{ .type(decoy) }}
{{ .noDefault() }}
{{ .name("working") }}
{{ .type(decoy) }}
{{ .noDefault() }}
{{ .name("broken") }}
{{ .type(target) }}
{{ .noDefault() }}
{{ .endRecord()) }}
{{ .noDefault() }}
{{ .endRecord(); }}
{{ final Schema parsed = new Schema.Parser().parse( }}
{{ ambiguous.toString()); }}
{{ // This assertion succeeds. }}
{{ Assertions.assertEquals( }}
{{ ambiguous.getField("working").schema(), }}
{{ parsed.getField("working").schema()); }}
{{ // This assertion succeeds but the specification is unclear. }}
{{ Assertions.assertEquals( }}
{{ ambiguous.getField("enclosing").schema() }}
{{ .getField("working").schema(), }}
{{ parsed.getField("enclosing").schema() }}
{{ .getField("working").schema()); }}
{{ // This assertion FAILS. }}
{{ Assertions.assertEquals( }}
{{ ambiguous.getField("enclosing").schema() }}
{{ .getField("broken").schema(), }}
{{ parsed.getField("enclosing").schema() }}
{{ .getField("broken").schema()); }}
{{ } }}
The assertion failure message complains:
{{expected: <\{"type":"record","name":"Target","doc":"right","fields":[]}> but
was
<\{"type":"record","name":"Target","namespace":"org.apache.avro","doc":"wrong","fields":[]}>}}
> The Java API
> -------------
>
> Key: AVRO-4150
> URL: https://issues.apache.org/jira/browse/AVRO-4150
> Project: Apache Avro
> Issue Type: Bug
> Reporter: Chad Parry
> Priority: Minor
>
> The Java API's org.apache.avro.Schema.toString implementation does not
> correctly serialize references into the null namespace. It always serializes
> such references as a name without a dot. That creates ambiguity, since it
> could be interpreted as a simple name that refers to a type in the same
> namespace as the enclosing type. One way to resolve the ambiguity would be to
> add a leading dot to the type name—assuming the specification is amended to
> allow that construction in AVRO-4149. The org.apache.avro.Schema.Parser
> implementation already accepts full names with a leading dot, so this would
> just make serialization consistent.
--
This message was sent by Atlassian Jira
(v8.20.10#820010)