[
https://issues.apache.org/jira/browse/AVRO-1442?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
]
Jim Pivarski updated AVRO-1442:
-------------------------------
Affects Version/s: (was: 1.7.5)
1.7.6
Release Note: This bug-fix does not introduce any backwards
incompatibilities. In practice, it replaces one error message
(RuntimeException) with another (an ErrorSymbol that eventually leads to an
AvroTypeException).
Status: Patch Available (was: Open)
Not sure if I'm using this form correctly, but here it goes. Here's the patch,
generated by git diff with respect to a clone of the repository I made an hour
ago:
{code}
diff --git
a/lang/java/avro/src/main/java/org/apache/avro/io/parsing/ResolvingGrammarGenerator.java
b/lang/java/avro/src/main/java/org/apache/avro/io/parsing/ResolvingGrammarGenerator.java
index 298910c..a705409 100644
---
a/lang/java/avro/src/main/java/org/apache/avro/io/parsing/ResolvingGrammarGenerator.java
+++
b/lang/java/avro/src/main/java/org/apache/avro/io/parsing/ResolvingGrammarGenerator.java
@@ -167,6 +167,7 @@ public class ResolvingGrammarGenerator extends
ValidatingGrammarGenerator {
case ARRAY:
case MAP:
case RECORD:
+ case FIXED:
break;
default:
throw new RuntimeException("Unexpected schema type: " + readerType);
{code}
(Yes, it's just one line.)
And here is a test that is sensitive to the bug. With the bug, it raises a
RuntimeException and therefore fails; without the bug, it passes with no
exceptions. (I don't want to make it too specific with an assertEquals because
the ErrorSymbols are probably implementation details.) Also, I didn't know
where to put it in the existing test hierarchy, so I made it a stand-alone
class that could be put anywhere.
{code}
package org.apache.avro;
import org.apache.avro.io.parsing.ResolvingGrammarGenerator;
import org.apache.avro.Schema;
import org.junit.Test;
public class TestBug1442 {
@Test
public void testBug1442() throws java.io.IOException {
new ResolvingGrammarGenerator().generate(Schema.createFixed("MyFixed",
null, null, 10), Schema.create(Schema.Type.BYTES));
new
ResolvingGrammarGenerator().generate(Schema.create(Schema.Type.BYTES),
Schema.createFixed("MyFixed", null, null, 10));
}
}
{code}
Whether you try to interpret a bytes as a fixed or a fixed as a bytes, it
should note the incompatibility, but not raise a RuntimeException. Without
this patch, the behavior is asymmetric.
> Case "FIXED" not handled in ResolvingGrammarGenerator
> -----------------------------------------------------
>
> Key: AVRO-1442
> URL: https://issues.apache.org/jira/browse/AVRO-1442
> Project: Avro
> Issue Type: Bug
> Components: java
> Affects Versions: 1.7.6
> Reporter: Jim Pivarski
> Labels: exceptions
>
> Symptom: Attempts to match reader = FIXED against writer != FIXED results in
> a RuntimeException ("Unexpected schema type: FIXED"), rather than an
> appropriate Symbol.ErrorAction.
> Reason: In the ResolvingGrammarGenerator.generate method, there are two
> switch statements, one for writerType == readerType and the other for
> writerType != readerType. In the latter, "case FIXED:" is missing.
> This is true in the GitHub version (HEAD?) as well:
> https://github.com/apache/avro/blob/branch-1.3/lang/java/src/java/org/apache/avro/io/parsing/ResolvingGrammarGenerator.java#L155
--
This message was sent by Atlassian JIRA
(v6.2#6252)