cassandra-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mish...@apache.org
Subject git commit: Don't swallow useful exceptions. patch by Ding Yuan; reviewed by Mikhail Stepura for CASSANDRA-6656
Date Fri, 07 Feb 2014 05:11:16 GMT
Updated Branches:
  refs/heads/trunk c3670e4f8 -> 7a3e697d8


Don't swallow useful exceptions.
patch by Ding Yuan; reviewed by Mikhail Stepura for CASSANDRA-6656


Project: http://git-wip-us.apache.org/repos/asf/cassandra/repo
Commit: http://git-wip-us.apache.org/repos/asf/cassandra/commit/7a3e697d
Tree: http://git-wip-us.apache.org/repos/asf/cassandra/tree/7a3e697d
Diff: http://git-wip-us.apache.org/repos/asf/cassandra/diff/7a3e697d

Branch: refs/heads/trunk
Commit: 7a3e697d836ca6fd7f41215678c977cb48a2ce1f
Parents: c3670e4
Author: Ding Yuan <yuan@eecg.toronto.edu>
Authored: Thu Feb 6 19:28:36 2014 -0800
Committer: Mikhail Stepura <mishail@apache.org>
Committed: Thu Feb 6 20:58:58 2014 -0800

----------------------------------------------------------------------
 .../db/marshal/DynamicCompositeType.java        | 21 ++++++++++++++++++--
 .../org/apache/cassandra/tools/NodeProbe.java   | 10 ++++++++--
 src/java/org/apache/cassandra/utils/Hex.java    | 11 ++++++++++
 3 files changed, 38 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cassandra/blob/7a3e697d/src/java/org/apache/cassandra/db/marshal/DynamicCompositeType.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/cassandra/db/marshal/DynamicCompositeType.java b/src/java/org/apache/cassandra/db/marshal/DynamicCompositeType.java
index 35e6e33..faa1955 100644
--- a/src/java/org/apache/cassandra/db/marshal/DynamicCompositeType.java
+++ b/src/java/org/apache/cassandra/db/marshal/DynamicCompositeType.java
@@ -22,6 +22,9 @@ import java.nio.ByteBuffer;
 import java.util.HashMap;
 import java.util.Map;
 
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
 import org.apache.cassandra.exceptions.ConfigurationException;
 import org.apache.cassandra.exceptions.SyntaxException;
 import org.apache.cassandra.serializers.TypeSerializer;
@@ -49,6 +52,8 @@ import org.apache.cassandra.utils.ByteBufferUtil;
  */
 public class DynamicCompositeType extends AbstractCompositeType
 {
+    private static final Logger logger = LoggerFactory.getLogger(DynamicCompositeType.class);
+
     private final Map<Byte, AbstractType<?>> aliases;
 
     // interning instances
@@ -185,13 +190,25 @@ public class DynamicCompositeType extends AbstractCompositeType
                 throw new MarshalException("Not enough bytes to read comparator name of component
" + i);
 
             ByteBuffer value = getBytes(bb, header);
+            String valueStr = null;
             try
             {
-                comparator = TypeParser.parse(ByteBufferUtil.string(value));
+                valueStr = ByteBufferUtil.string(value);
+                comparator = TypeParser.parse(valueStr);
+            }
+            catch (CharacterCodingException ce) 
+            {
+                // ByteBufferUtil.string failed. 
+                // Log it here and we'll further throw an exception below since comparator
== null
+                logger.error("Failed with [{}] when decoding the byte buffer in ByteBufferUtil.string()",

+                   ce.toString());
             }
             catch (Exception e)
             {
-                // we'll deal with this below since comparator == null
+                // parse failed. 
+                // Log it here and we'll further throw an exception below since comparator
== null
+                logger.error("Failed to parse value string \"{}\" with exception: [{}]",

+                   valueStr, e.toString());
             }
         }
         else

http://git-wip-us.apache.org/repos/asf/cassandra/blob/7a3e697d/src/java/org/apache/cassandra/tools/NodeProbe.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/cassandra/tools/NodeProbe.java b/src/java/org/apache/cassandra/tools/NodeProbe.java
index d874ef0..a342866 100644
--- a/src/java/org/apache/cassandra/tools/NodeProbe.java
+++ b/src/java/org/apache/cassandra/tools/NodeProbe.java
@@ -237,7 +237,10 @@ public class NodeProbe implements AutoCloseable
                 ssProxy.removeNotificationListener(runner);
                 jmxc.removeConnectionNotificationListener(runner);
             }
-            catch (Throwable ignored) {}
+            catch (Throwable e) 
+            {
+                out.println("Exception occurred during clean-up. " + e);
+            }
         }
     }
 
@@ -262,7 +265,10 @@ public class NodeProbe implements AutoCloseable
                 ssProxy.removeNotificationListener(runner);
                 jmxc.removeConnectionNotificationListener(runner);
             }
-            catch (Throwable ignored) {}
+            catch (Throwable e)
+            {
+                out.println("Exception occurred during clean-up. " + e);
+            }
         }
     }
 

http://git-wip-us.apache.org/repos/asf/cassandra/blob/7a3e697d/src/java/org/apache/cassandra/utils/Hex.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/cassandra/utils/Hex.java b/src/java/org/apache/cassandra/utils/Hex.java
index 463c49a..5ba0b1a 100644
--- a/src/java/org/apache/cassandra/utils/Hex.java
+++ b/src/java/org/apache/cassandra/utils/Hex.java
@@ -18,11 +18,16 @@
 package org.apache.cassandra.utils;
 
 import java.lang.reflect.Constructor;
+import java.lang.reflect.InvocationTargetException;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 
 public class Hex
 {
     private static final Constructor<String> stringConstructor = getProtectedConstructor(String.class,
int.class, int.class, char[].class);
     private final static byte[] charToByte = new byte[256];
+    private static final Logger logger = LoggerFactory.getLogger(Hex.class);
 
     // package protected for use by ByteBufferUtil. Do not modify this array !!
     static final char[] byteToChar = new char[16];
@@ -91,6 +96,12 @@ public class Hex
             try
             {
                 s = stringConstructor.newInstance(0, c.length, c);
+            } 
+            catch (InvocationTargetException ite) {
+                // The underlying constructor failed. Unwrapping the exception.
+                Throwable cause = ite.getCause();
+                logger.error("Underlying string constructor threw an error: {}",
+                    cause == null ? ite.getMessage() : cause.getMessage());
             }
             catch (Exception e)
             {


Mime
View raw message