[
https://issues.apache.org/jira/browse/AVRO-4149?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17956818#comment-17956818
]
Chad Parry commented on AVRO-4149:
----------------------------------
In case the text description is unclear, the following complete test case
illustrates how this issue leads to data corruption with the Java API.
{{ @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 specification should allow explicit references into the null namespace
> --------------------------------------------------------------------------
>
> Key: AVRO-4149
> URL: https://issues.apache.org/jira/browse/AVRO-4149
> Project: Apache Avro
> Issue Type: Bug
> Reporter: Chad Parry
> Priority: Minor
>
> If the enclosing type has a namespace, and if that namespace contains a type
> "Target", and if the null namespace also has a type "Target", then it is
> impossible to reference the one in the null namespace. The type name "Target"
> would be interpreted as a simple name that refers to the namespaced "Target"
> type. The specification should be amended so that ".Target" is a legal
> reference into the null namespace. Other sections of the specification that
> forbid that should be amended, (e.g., ""The null namespace may not be used in
> a dot-separated sequence of names").
--
This message was sent by Atlassian Jira
(v8.20.10#820010)