ソースを参照

HADOOP-507. Fix an IllegalAccessException in DFS. Contributed by Owen.

git-svn-id: https://svn.apache.org/repos/asf/lucene/hadoop/trunk@440866 13f79535-47bb-0310-9956-ffa450edef68
Doug Cutting 18 年 前
コミット
9c0c6ce04e

+ 3 - 0
CHANGES.txt

@@ -126,6 +126,9 @@ Trunk (unreleased changes)
 31. HADOOP-408.  Adjust some timeouts and remove some others so that
     unit tests run faster.  (cutting)
 
+32. HADOOP-507.  Fix an IllegalAccessException in DFS.
+    (omalley via cutting)
+
 
 Release 0.5.0 - 2006-08-04
 

+ 1 - 4
src/java/org/apache/hadoop/io/ObjectWritable.java

@@ -223,10 +223,7 @@ public class ObjectWritable implements Writable, Configurable {
         throw new RuntimeException("readObject can't find class", e);
       }
       
-      Writable writable = WritableFactories.newInstance(instanceClass);
-      if(writable instanceof Configurable) {
-        ((Configurable) writable).setConf(conf);
-      }
+      Writable writable = WritableFactories.newInstance(instanceClass, conf);
       writable.readFields(in);
       instance = writable;
 

+ 14 - 9
src/java/org/apache/hadoop/io/WritableFactories.java

@@ -16,6 +16,8 @@
 
 package org.apache.hadoop.io;
 
+import org.apache.hadoop.conf.*;
+import org.apache.hadoop.util.ReflectionUtils;
 import java.util.HashMap;
 
 /** Factories for non-public writables.  Defining a factory permits {@link
@@ -36,20 +38,23 @@ public class WritableFactories {
   }
 
   /** Create a new instance of a class with a defined factory. */
-  public static Writable newInstance(Class c) {
+  public static Writable newInstance(Class c, Configuration conf) {
     WritableFactory factory = WritableFactories.getFactory(c);
     if (factory != null) {
-      return factory.newInstance();
-    } else {
-      try {
-        return (Writable)c.newInstance();
-      } catch (InstantiationException e) {
-        throw new RuntimeException(e);
-      } catch (IllegalAccessException e) {
-        throw new RuntimeException(e);
+      Writable result = factory.newInstance();
+      if (result instanceof Configurable) {
+        ((Configurable) result).setConf(conf);
       }
+      return result;
+    } else {
+      return (Writable)ReflectionUtils.newInstance(c, conf);
     }
   }
+  
+  /** Create a new instance of a class with a defined factory. */
+  public static Writable newInstance(Class c) {
+    return newInstance(c, null);
+  }
 
 }