hbase-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From st...@apache.org
Subject svn commit: r1504591 - in /hbase/trunk: hbase-client/src/main/java/org/apache/hadoop/hbase/protobuf/ProtobufUtil.java hbase-server/src/test/java/org/apache/hadoop/hbase/protobuf/TestProtobufUtil.java
Date Thu, 18 Jul 2013 18:37:54 GMT
Author: stack
Date: Thu Jul 18 18:37:53 2013
New Revision: 1504591

URL: http://svn.apache.org/r1504591
Log:
HBASE-8987 ProtobufUtil.toException doesn't handle plain RemoteException, gets a NoSuchMethodException

Modified:
    hbase/trunk/hbase-client/src/main/java/org/apache/hadoop/hbase/protobuf/ProtobufUtil.java
    hbase/trunk/hbase-server/src/test/java/org/apache/hadoop/hbase/protobuf/TestProtobufUtil.java

Modified: hbase/trunk/hbase-client/src/main/java/org/apache/hadoop/hbase/protobuf/ProtobufUtil.java
URL: http://svn.apache.org/viewvc/hbase/trunk/hbase-client/src/main/java/org/apache/hadoop/hbase/protobuf/ProtobufUtil.java?rev=1504591&r1=1504590&r2=1504591&view=diff
==============================================================================
--- hbase/trunk/hbase-client/src/main/java/org/apache/hadoop/hbase/protobuf/ProtobufUtil.java
(original)
+++ hbase/trunk/hbase-client/src/main/java/org/apache/hadoop/hbase/protobuf/ProtobufUtil.java
Thu Jul 18 18:37:53 2013
@@ -1204,17 +1204,22 @@ public final class ProtobufUtil {
    * @throws IOException if failed to deserialize the parameter
    */
   @SuppressWarnings("unchecked")
-  public static Throwable toException(
-      final NameBytesPair parameter) throws IOException {
+  public static Throwable toException(final NameBytesPair parameter) throws IOException {
     if (parameter == null || !parameter.hasValue()) return null;
     String desc = parameter.getValue().toStringUtf8();
     String type = parameter.getName();
     try {
       Class<? extends Throwable> c =
         (Class<? extends Throwable>)Class.forName(type, true, CLASS_LOADER);
-      Constructor<? extends Throwable> cn =
-        c.getDeclaredConstructor(String.class);
-      return cn.newInstance(desc);
+      Constructor<? extends Throwable> cn = null;
+      try {
+        cn = c.getDeclaredConstructor(String.class);
+        return cn.newInstance(desc);
+      } catch (NoSuchMethodException e) {
+        // Could be a raw RemoteException. See HBASE-8987.
+        cn = c.getDeclaredConstructor(String.class, String.class);
+        return cn.newInstance(type, desc);
+      }
     } catch (Exception e) {
       throw new IOException(e);
     }

Modified: hbase/trunk/hbase-server/src/test/java/org/apache/hadoop/hbase/protobuf/TestProtobufUtil.java
URL: http://svn.apache.org/viewvc/hbase/trunk/hbase-server/src/test/java/org/apache/hadoop/hbase/protobuf/TestProtobufUtil.java?rev=1504591&r1=1504590&r2=1504591&view=diff
==============================================================================
--- hbase/trunk/hbase-server/src/test/java/org/apache/hadoop/hbase/protobuf/TestProtobufUtil.java
(original)
+++ hbase/trunk/hbase-server/src/test/java/org/apache/hadoop/hbase/protobuf/TestProtobufUtil.java
Thu Jul 18 18:37:53 2013
@@ -36,6 +36,7 @@ import org.apache.hadoop.hbase.protobuf.
 import org.apache.hadoop.hbase.protobuf.generated.ClientProtos.MutationProto.ColumnValue.QualifierValue;
 import org.apache.hadoop.hbase.protobuf.generated.ClientProtos.MutationProto.DeleteType;
 import org.apache.hadoop.hbase.protobuf.generated.ClientProtos.MutationProto.MutationType;
+import org.apache.hadoop.hbase.protobuf.generated.HBaseProtos.NameBytesPair;
 import org.apache.hadoop.hbase.util.Bytes;
 import org.junit.Test;
 import org.junit.experimental.categories.Category;
@@ -47,6 +48,20 @@ import com.google.protobuf.ByteString;
  */
 @Category(SmallTests.class)
 public class TestProtobufUtil {
+  @Test
+  public void testException() throws IOException {
+    NameBytesPair.Builder builder = NameBytesPair.newBuilder();
+    final String omg = "OMG!!!";
+    builder.setName("java.io.IOException");
+    builder.setValue(ByteString.copyFrom(Bytes.toBytes(omg)));
+    Throwable t = ProtobufUtil.toException(builder.build());
+    assertEquals(omg, t.getMessage());
+    builder.clear();
+    builder.setName("org.apache.hadoop.ipc.RemoteException");
+    builder.setValue(ByteString.copyFrom(Bytes.toBytes(omg)));
+    t = ProtobufUtil.toException(builder.build());
+    assertEquals(omg, t.getMessage());
+  }
 
   /**
    * Test basic Get conversions.



Mime
View raw message