martin-g commented on a change in pull request #1391:
URL: https://github.com/apache/avro/pull/1391#discussion_r742965473
##########
File path:
lang/java/avro/src/main/java/org/apache/avro/reflect/ReflectDatumWriter.java
##########
@@ -81,8 +81,7 @@ protected void writeArray(Schema schema, Object datum,
Encoder out) throws IOExc
out.writeArrayStart();
switch (type) {
case BOOLEAN:
- if (elementClass.isPrimitive())
Review comment:
Removed because there is already a check that the elementClass is a
primitive one at line 79.
##########
File path:
lang/java/avro/src/main/java/org/apache/avro/reflect/ReflectionUtil.java
##########
@@ -118,10 +118,8 @@ private boolean validate(FieldAccess access) throws
Exception {
}
private boolean validField(FieldAccess access, String name, Object
original, Object toSet) throws Exception {
- FieldAccessor a;
- boolean valid = true;
- a = accessor(access, name);
- valid &= original.equals(a.get(this));
+ FieldAccessor a = accessor(access, name);
Review comment:
No functional change. Just simplification
##########
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:
I am not sure this test is needed here. Most probably this functionality
is already covered in another test. It has nothing to do with "anonymous
enums". It just checks that a non-nullable field (Person#name) cannot have a
null value with non-union schema.
--
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]