[
https://issues.apache.org/jira/browse/AVRO-1851?focusedWorklogId=676282&page=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-676282
]
ASF GitHub Bot logged work on AVRO-1851:
----------------------------------------
Author: ASF GitHub Bot
Created on: 04/Nov/21 09:25
Start Date: 04/Nov/21 09:25
Worklog Time Spent: 10m
Work Description: martin-g commented on a change in pull request #1391:
URL: https://github.com/apache/avro/pull/1391#discussion_r742660938
##########
File path: lang/java/avro/src/main/java/org/apache/avro/reflect/ReflectData.java
##########
@@ -666,6 +666,9 @@ protected Schema createSchema(Type type, Map<String,
Schema> names) {
return result;
} else if (type instanceof Class) { // Class
Class<?> c = (Class<?>) type;
+ while (c.isAnonymousClass()) {
+ c = c.getSuperclass();
+ }
Review comment:
This is the main improvement for this issue.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
Issue Time Tracking
-------------------
Worklog Id: (was: 676282)
Time Spent: 0.5h (was: 20m)
> Serialization of anonymous enum fails with nullable union
> ---------------------------------------------------------
>
> Key: AVRO-1851
> URL: https://issues.apache.org/jira/browse/AVRO-1851
> Project: Apache Avro
> Issue Type: Bug
> Components: java
> Affects Versions: 1.7.7
> Reporter: Zack Kobza
> Assignee: Martin Tzvetanov Grigorov
> Priority: Minor
> Labels: pull-request-available
> Time Spent: 0.5h
> Remaining Estimate: 0h
>
> Error received when serializing an object containing a nullable anonymous
> enum:
> {noformat}
> org.apache.avro.SchemaParseException: Empty name
> at org.apache.avro.Schema.validateName(Schema.java:1108)
> at org.apache.avro.Schema.access$200(Schema.java:80)
> at org.apache.avro.Schema$Name.<init>(Schema.java:468)
> at org.apache.avro.Schema.createRecord(Schema.java:151)
> at
> org.apache.avro.reflect.ReflectData.createSchema(ReflectData.java:466)
> at
> org.apache.avro.specific.SpecificData.getSchema(SpecificData.java:189)
> at org.apache.avro.reflect.ReflectData.isRecord(ReflectData.java:168)
> at
> org.apache.avro.generic.GenericData.getSchemaName(GenericData.java:613)
> at
> org.apache.avro.specific.SpecificData.getSchemaName(SpecificData.java:265)
> at
> org.apache.avro.generic.GenericData.resolveUnion(GenericData.java:602)
> at
> org.apache.avro.generic.GenericDatumWriter.resolveUnion(GenericDatumWriter.java:151)
> at
> org.apache.avro.generic.GenericDatumWriter.write(GenericDatumWriter.java:71)
> at
> org.apache.avro.reflect.ReflectDatumWriter.write(ReflectDatumWriter.java:143)
> at
> org.apache.avro.generic.GenericDatumWriter.writeField(GenericDatumWriter.java:114)
> at
> org.apache.avro.reflect.ReflectDatumWriter.writeField(ReflectDatumWriter.java:175)
> at
> org.apache.avro.generic.GenericDatumWriter.writeRecord(GenericDatumWriter.java:104)
> at
> org.apache.avro.generic.GenericDatumWriter.write(GenericDatumWriter.java:66)
> at
> org.apache.avro.reflect.ReflectDatumWriter.write(ReflectDatumWriter.java:143)
> at
> org.apache.avro.generic.GenericDatumWriter.write(GenericDatumWriter.java:58)
> at
> org.apache.avro.reflect.TestReflectDatumReader.serializeWithReflectDatumWriter(TestReflectDatumReader.java:45)
> at
> org.apache.avro.reflect.TestReflectDatumReader.testWrite_AnonymousEnum(TestReflectDatumReader.java:53)
> at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
> at
> sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
> at
> sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
> at java.lang.reflect.Method.invoke(Method.java:497)
> at
> org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:45)
> at
> org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
> at
> org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:42)
> at
> org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:20)
> at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:263)
> at
> org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:68)
> at
> org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:47)
> at org.junit.runners.ParentRunner$3.run(ParentRunner.java:231)
> at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:60)
> at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:229)
> at org.junit.runners.ParentRunner.access$000(ParentRunner.java:50)
> at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:222)
> at org.junit.runners.ParentRunner.run(ParentRunner.java:300)
> at org.junit.runner.JUnitCore.run(JUnitCore.java:157)
> at
> com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:117)
> at
> com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:234)
> at
> com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:74)
> at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
> at
> sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
> at
> sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
> at java.lang.reflect.Method.invoke(Method.java:497)
> at com.intellij.rt.execution.application.AppMain.main(AppMain.java:144)
> {noformat}
> Here is a unit test derived from TestReflectDatumReader to reproduce:
> {code}
> @Test
> public void testWrite_AnonymousEnum() throws IOException {
> byte[] serializedBytes =
> serializeWithReflectDatumWriter(new
> MyObject(AnonymousEnum.A), MyObject.class, AllowNull.get());
> assertNotNull(serializedBytes);
> }
> enum AnonymousEnum {
> A {
> @Override
> public String doSomething() {
> return "A is doing something";
> }
> };
> public abstract String doSomething();
> }
> public static class MyObject {
> private final AnonymousEnum ae;
> public MyObject(AnonymousEnum ae) {
> this.ae = ae;
> }
> }
> {code}
--
This message was sent by Atlassian Jira
(v8.3.4#803005)