avro-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cutt...@apache.org
Subject svn commit: r944035 - in /avro/trunk/lang/java/src: java/org/apache/avro/reflect/ReflectData.java test/java/org/apache/avro/TestReflect.java
Date Thu, 13 May 2010 22:26:43 GMT
Author: cutting
Date: Thu May 13 22:26:42 2010
New Revision: 944035

URL: http://svn.apache.org/viewvc?rev=944035&view=rev
Log:
AVRO-499. Java: Fix protocol reflection to reject interfaces with multiple methods of the
same name.

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

Modified: avro/trunk/lang/java/src/java/org/apache/avro/reflect/ReflectData.java
URL: http://svn.apache.org/viewvc/avro/trunk/lang/java/src/java/org/apache/avro/reflect/ReflectData.java?rev=944035&r1=944034&r2=944035&view=diff
==============================================================================
--- avro/trunk/lang/java/src/java/org/apache/avro/reflect/ReflectData.java (original)
+++ avro/trunk/lang/java/src/java/org/apache/avro/reflect/ReflectData.java Thu May 13 22:26:42
2010
@@ -355,10 +355,14 @@ public class ReflectData extends Specifi
     Protocol protocol =
       new Protocol(iface.getSimpleName(), iface.getPackage().getName()); 
     Map<String,Schema> names = new LinkedHashMap<String,Schema>();
+    Map<String,Message> messages = protocol.getMessages();
     for (Method method : iface.getMethods())
-      if ((method.getModifiers() & Modifier.STATIC) == 0)
-        protocol.getMessages().put(method.getName(),
-                                   getMessage(method, protocol, names));
+      if ((method.getModifiers() & Modifier.STATIC) == 0) {
+        String name = method.getName();
+        if (messages.containsKey(name))
+          throw new AvroTypeException("Two methods with same name: "+name);
+        messages.put(name, getMessage(method, protocol, names));
+      }
 
     // reverse types, since they were defined in reference order
     List<Schema> types = new ArrayList<Schema>();

Modified: avro/trunk/lang/java/src/test/java/org/apache/avro/TestReflect.java
URL: http://svn.apache.org/viewvc/avro/trunk/lang/java/src/test/java/org/apache/avro/TestReflect.java?rev=944035&r1=944034&r2=944035&view=diff
==============================================================================
--- avro/trunk/lang/java/src/test/java/org/apache/avro/TestReflect.java (original)
+++ avro/trunk/lang/java/src/test/java/org/apache/avro/TestReflect.java Thu May 13 22:26:42
2010
@@ -501,4 +501,15 @@ public class TestReflect {
     assert(reparsed.getTypes().contains(data.getSchema(X.class)));
   }
 
+  public static interface P3 {
+    void m1();
+    void m1(int x);
+  }
+
+  @Test(expected=AvroTypeException.class)
+  public void testOverloadedMethod() { 
+    ReflectData.get().getProtocol(P3.class);
+  }
+
+
 }



Mime
View raw message