avro-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cutt...@apache.org
Subject svn commit: r1173842 - in /avro/trunk: CHANGES.txt lang/java/avro/src/main/java/org/apache/avro/reflect/ReflectData.java lang/java/avro/src/test/java/org/apache/avro/TestReflect.java
Date Wed, 21 Sep 2011 20:44:42 GMT
Author: cutting
Date: Wed Sep 21 20:44:41 2011
New Revision: 1173842

URL: http://svn.apache.org/viewvc?rev=1173842&view=rev
Log:
AVRO-887. Java: Improve reflection error message when a field is not found in a class.

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

Modified: avro/trunk/CHANGES.txt
URL: http://svn.apache.org/viewvc/avro/trunk/CHANGES.txt?rev=1173842&r1=1173841&r2=1173842&view=diff
==============================================================================
--- avro/trunk/CHANGES.txt (original)
+++ avro/trunk/CHANGES.txt Wed Sep 21 20:44:41 2011
@@ -63,6 +63,9 @@ Avro 1.6.0 (unreleased)
     AVRO-888. Java: Add SeekableByteArrayInput, a utility to permit
     use of memory-based AvroDataFiles.  (Saleem Shafi via cutting)
 
+    AVRO-887. Java: Improve reflection error message when a field is
+    not found in a class.  (cutting)
+
   BUG FIXES
 
     AVRO-824. Java: Fix usage message of BinaryFragmentToJsonTool.

Modified: avro/trunk/lang/java/avro/src/main/java/org/apache/avro/reflect/ReflectData.java
URL: http://svn.apache.org/viewvc/avro/trunk/lang/java/avro/src/main/java/org/apache/avro/reflect/ReflectData.java?rev=1173842&r1=1173841&r2=1173842&view=diff
==============================================================================
--- avro/trunk/lang/java/avro/src/main/java/org/apache/avro/reflect/ReflectData.java (original)
+++ avro/trunk/lang/java/avro/src/main/java/org/apache/avro/reflect/ReflectData.java Wed Sep
21 20:44:41 2011
@@ -163,7 +163,8 @@ public class ReflectData extends Specifi
     return f;
   }
 
-  private static Field findField(Class c, String name) {
+  private static Field findField(Class original, String name) {
+    Class c = original;
     do {
       try {
         Field f = c.getDeclaredField(name);
@@ -172,7 +173,7 @@ public class ReflectData extends Specifi
       } catch (NoSuchFieldException e) {}
       c = c.getSuperclass();
     } while (c != null);
-    throw new AvroRuntimeException("No field named "+name+" in: "+c);
+    throw new AvroRuntimeException("No field named "+name+" in: "+original);
   }
 
   static final String CLASS_PROP = "java-class";

Modified: avro/trunk/lang/java/avro/src/test/java/org/apache/avro/TestReflect.java
URL: http://svn.apache.org/viewvc/avro/trunk/lang/java/avro/src/test/java/org/apache/avro/TestReflect.java?rev=1173842&r1=1173841&r2=1173842&view=diff
==============================================================================
--- avro/trunk/lang/java/avro/src/test/java/org/apache/avro/TestReflect.java (original)
+++ avro/trunk/lang/java/avro/src/test/java/org/apache/avro/TestReflect.java Wed Sep 21 20:44:41
2011
@@ -579,6 +579,16 @@ public class TestReflect {
     assertEquals(0, ReflectData.get().compare(datum, decoded, schema));
   }
 
+  /** Test that the error message contains the name of the class. */
+  @Test
+  public void testReflectFieldError() throws Exception {
+    Object datum = "";
+    try {
+      ReflectData.get().getField(datum, "notAFieldOfString", 0);
+    } catch (AvroRuntimeException e) {
+      assertTrue(e.getMessage().contains(datum.getClass().getName()));
+    }
+  }
 
 
 }



Mime
View raw message