hadoop-common-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cutt...@apache.org
Subject svn commit: r397593 - in /lucene/hadoop/trunk/src: java/org/apache/hadoop/io/ObjectWritable.java test/org/apache/hadoop/ipc/TestRPC.java
Date Thu, 27 Apr 2006 17:23:34 GMT
Author: cutting
Date: Thu Apr 27 10:23:32 2006
New Revision: 397593

URL: http://svn.apache.org/viewcvs?rev=397593&view=rev
Log:
Fix bug introduced yesterday.  NullInstance really is still required!

Modified:
    lucene/hadoop/trunk/src/java/org/apache/hadoop/io/ObjectWritable.java
    lucene/hadoop/trunk/src/test/org/apache/hadoop/ipc/TestRPC.java

Modified: lucene/hadoop/trunk/src/java/org/apache/hadoop/io/ObjectWritable.java
URL: http://svn.apache.org/viewcvs/lucene/hadoop/trunk/src/java/org/apache/hadoop/io/ObjectWritable.java?rev=397593&r1=397592&r2=397593&view=diff
==============================================================================
--- lucene/hadoop/trunk/src/java/org/apache/hadoop/io/ObjectWritable.java (original)
+++ lucene/hadoop/trunk/src/java/org/apache/hadoop/io/ObjectWritable.java Thu Apr 27 10:23:32
2006
@@ -77,13 +77,36 @@
     PRIMITIVE_NAMES.put("void", Void.TYPE);
   }
 
+  private static class NullInstance implements Writable {
+    private Class declaredClass;
+    public NullInstance() {}
+    public NullInstance(Class declaredClass) {
+      this.declaredClass = declaredClass;
+    }
+    public void readFields(DataInput in) throws IOException {
+      String className = UTF8.readString(in);
+      declaredClass = (Class)PRIMITIVE_NAMES.get(className);
+      if (declaredClass == null) {
+        try {
+          declaredClass = Class.forName(className);
+        } catch (ClassNotFoundException e) {
+          throw new RuntimeException(e.toString());
+        }
+      }
+    }
+    public void write(DataOutput out) throws IOException {
+      UTF8.writeString(out, declaredClass.getName());
+    }
+  }
+
   /** Write a {@link Writable}, {@link String}, primitive type, or an array of
    * the preceding. */
   public static void writeObject(DataOutput out, Object instance,
                                  Class declaredClass) throws IOException {
 
     if (instance == null) {                       // null
-      instance = NullWritable.get();
+      instance = new NullInstance(declaredClass);
+      declaredClass = Writable.class;
     }
 
     UTF8.writeString(out, declaredClass.getName()); // always write declared
@@ -197,15 +220,16 @@
         throw new RuntimeException(e.toString());
       }
       
-      if (instanceClass == NullWritable.class) {  // null
+      Writable writable = WritableFactories.newInstance(instanceClass);
+      if(writable instanceof Configurable) {
+        ((Configurable) writable).setConf(conf);
+      }
+      writable.readFields(in);
+      instance = writable;
+
+      if (instanceClass == NullInstance.class) {  // null
+        declaredClass = ((NullInstance)instance).declaredClass;
         instance = null;
-      } else {
-        Writable writable = WritableFactories.newInstance(instanceClass);
-        if(writable instanceof Configurable) {
-          ((Configurable) writable).setConf(conf);
-        }
-        writable.readFields(in);
-        instance = writable;
       }
     }
 

Modified: lucene/hadoop/trunk/src/test/org/apache/hadoop/ipc/TestRPC.java
URL: http://svn.apache.org/viewcvs/lucene/hadoop/trunk/src/test/org/apache/hadoop/ipc/TestRPC.java?rev=397593&r1=397592&r2=397593&view=diff
==============================================================================
--- lucene/hadoop/trunk/src/test/org/apache/hadoop/ipc/TestRPC.java (original)
+++ lucene/hadoop/trunk/src/test/org/apache/hadoop/ipc/TestRPC.java Thu Apr 27 10:23:32 2006
@@ -109,11 +109,20 @@
     String stringResult = proxy.echo("foo");
     assertEquals(stringResult, "foo");
 
+    stringResult = proxy.echo((String)null);
+    assertEquals(stringResult, null);
+
     String[] stringResults = proxy.echo(new String[]{"foo","bar"});
     assertTrue(Arrays.equals(stringResults, new String[]{"foo","bar"}));
 
+    stringResults = proxy.echo((String[])null);
+    assertTrue(Arrays.equals(stringResults, null));
+
     UTF8 utf8Result = (UTF8)proxy.echo(new UTF8("hello world"));
     assertEquals(utf8Result, new UTF8("hello world"));
+
+    utf8Result = (UTF8)proxy.echo((UTF8)null);
+    assertEquals(utf8Result, null);
 
     int intResult = proxy.add(1, 2);
     assertEquals(intResult, 3);



Mime
View raw message