[ 
https://issues.apache.org/jira/browse/AVRO-1851?focusedWorklogId=677282&page=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-677282
 ]

ASF GitHub Bot logged work on AVRO-1851:
----------------------------------------

                Author: ASF GitHub Bot
            Created on: 05/Nov/21 19:32
            Start Date: 05/Nov/21 19:32
    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_r743468730



##########
File path: 
lang/java/avro/src/test/java/org/apache/avro/reflect/TestReflectDatumWithAnonymousEnum.java
##########
@@ -0,0 +1,185 @@
+package org.apache.avro.reflect;
+
+import static org.junit.Assert.assertEquals;
+
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+
+import org.apache.avro.Schema;
+import org.apache.avro.io.Decoder;
+import org.apache.avro.io.DecoderFactory;
+import org.apache.avro.io.Encoder;
+import org.apache.avro.io.EncoderFactory;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+/**
+ * https://issues.apache.org/jira/browse/AVRO-1851
+ */
+public class TestReflectDatumWithAnonymousEnum {
+  private static Pojo pojo;
+
+  @BeforeClass
+  public static void init() {
+    pojo = new Pojo();
+    Person person = new Person();
+    person.setAddress("Address");
+    pojo.setTestEnum(TestEnum.V);
+    pojo.setPerson(person);
+  }
+
+  // Properly serializes and deserializes a POJO with an enum instance 
(TestEnum#V)
+  @Test
+  public void handleProperlyEnumInstances() throws IOException {
+    byte[] output = serialize(pojo);
+    Pojo deserializedPojo = deserialize(output);
+    assertEquals(pojo, deserializedPojo);
+  }
+
+  // The test fails because the Schema doesn't support null value for the 
Person's name
+  @Test(expected = NullPointerException.class)
+  public void avroEnumWithNotNullTest() throws IOException {

Review comment:
       Removed it!
   And made the test more fancy by using anonymous instances for Pojo and 
Person too.




-- 
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: 677282)
    Time Spent: 1h 10m  (was: 1h)

> 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, 1.11.0
>            Reporter: Zack Kobza
>            Assignee: Martin Tzvetanov Grigorov
>            Priority: Minor
>              Labels: pull-request-available
>          Time Spent: 1h 10m
>  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)

Reply via email to