avro-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tomwh...@apache.org
Subject svn commit: r1572912 - in /avro/trunk: CHANGES.txt lang/java/avro/src/main/java/org/apache/avro/reflect/FieldAccessUnsafe.java lang/java/avro/src/test/java/org/apache/avro/reflect/TestReflect.java
Date Fri, 28 Feb 2014 10:44:10 GMT
Author: tomwhite
Date: Fri Feb 28 10:44:09 2014
New Revision: 1572912

URL: http://svn.apache.org/r1572912
Log:
AVRO-1458. Java: Setting char record field via reflection affects other fields

Modified:
    avro/trunk/CHANGES.txt
    avro/trunk/lang/java/avro/src/main/java/org/apache/avro/reflect/FieldAccessUnsafe.java
    avro/trunk/lang/java/avro/src/test/java/org/apache/avro/reflect/TestReflect.java

Modified: avro/trunk/CHANGES.txt
URL: http://svn.apache.org/viewvc/avro/trunk/CHANGES.txt?rev=1572912&r1=1572911&r2=1572912&view=diff
==============================================================================
--- avro/trunk/CHANGES.txt (original)
+++ avro/trunk/CHANGES.txt Fri Feb 28 10:44:09 2014
@@ -31,6 +31,9 @@ Trunk (not yet released)
 
     AVRO-1436. C#: Fix tests to run multiple times. (David Taylor via cutting)
 
+    AVRO-1458. Java: Setting char record field via reflection affects other
+    fields. (tomwhite)
+
 Avro 1.7.6 (15 January 2014)
 
   NEW FEATURES

Modified: avro/trunk/lang/java/avro/src/main/java/org/apache/avro/reflect/FieldAccessUnsafe.java
URL: http://svn.apache.org/viewvc/avro/trunk/lang/java/avro/src/main/java/org/apache/avro/reflect/FieldAccessUnsafe.java?rev=1572912&r1=1572911&r2=1572912&view=diff
==============================================================================
--- avro/trunk/lang/java/avro/src/main/java/org/apache/avro/reflect/FieldAccessUnsafe.java
(original)
+++ avro/trunk/lang/java/avro/src/main/java/org/apache/avro/reflect/FieldAccessUnsafe.java
Fri Feb 28 10:44:09 2014
@@ -236,7 +236,7 @@ class FieldAccessUnsafe extends FieldAcc
 
     @Override
     protected void set(Object object, Object value) {
-      UNSAFE.putInt(object, offset, (Character) value);
+      UNSAFE.putChar(object, offset, (Character) value);
     }
 
     @Override

Modified: avro/trunk/lang/java/avro/src/test/java/org/apache/avro/reflect/TestReflect.java
URL: http://svn.apache.org/viewvc/avro/trunk/lang/java/avro/src/test/java/org/apache/avro/reflect/TestReflect.java?rev=1572912&r1=1572911&r2=1572912&view=diff
==============================================================================
--- avro/trunk/lang/java/avro/src/test/java/org/apache/avro/reflect/TestReflect.java (original)
+++ avro/trunk/lang/java/avro/src/test/java/org/apache/avro/reflect/TestReflect.java Fri Feb
28 10:44:09 2014
@@ -79,6 +79,11 @@ public class TestReflect {
     check(Short.class, "{\"type\":\"int\",\"java-class\":\"java.lang.Short\"}");
   }
 
+  @Test public void testChar() {
+    check(Character.TYPE, "{\"type\":\"int\",\"java-class\":\"java.lang.Character\"}");
+    check(Character.class, "{\"type\":\"int\",\"java-class\":\"java.lang.Character\"}");
+  }
+
   @Test public void testLong() {
     check(Long.TYPE, "\"long\"");
     check(Long.class, "\"long\"");
@@ -208,6 +213,7 @@ public class TestReflect {
     public short value;
     public short[] shorts;
     public byte b;
+    public char c;
     
     @Override
     public boolean equals(Object o) {
@@ -215,7 +221,8 @@ public class TestReflect {
       R4 that = (R4)o;
       return this.value == that.value
         && Arrays.equals(this.shorts, that.shorts)
-        && this.b == that.b;
+        && this.b == that.b
+        && this.c == that.c;
     }
   }
 
@@ -226,6 +233,7 @@ public class TestReflect {
     r5.value = 1;
     r5.shorts = new short[] {3,255,256,Short.MAX_VALUE,Short.MIN_VALUE};
     r5.b = 99;
+    r5.c = 'a';
     checkReadWrite(r5);
   }
 
@@ -457,6 +465,16 @@ public class TestReflect {
       reader.read(null, DecoderFactory.get().binaryDecoder(
           out.toByteArray(), null));
     assertEquals(object, after);
+
+    // check reflective setField works for records
+    if (s.getType().equals(Schema.Type.RECORD)) {
+      Object copy = object.getClass().newInstance();
+      for (Field f : s.getFields()) {
+        Object val = ReflectData.get().getField(object, f.name(), f.pos());
+        ReflectData.get().setField(copy, f.name(), f.pos(), val);
+      }
+      assertEquals("setField", object, copy);
+    }
   }
 
   public static enum E { A, B };



Mime
View raw message