Mmuzaf commented on code in PR #2133:
URL: https://github.com/apache/cassandra/pull/2133#discussion_r1149871406


##########
src/java/org/apache/cassandra/config/DatabaseDescriptor.java:
##########
@@ -4676,4 +4729,41 @@ public static void 
setClientRequestSizeMetricsEnabled(boolean enabled)
     {
         return Objects.requireNonNull(sstableFormatFactories, "Forgot to 
initialize DatabaseDescriptor?");
     }
+
+    /**
+     * Set configuration property for the given name to {@link #confRegistry} 
if a safe manner
+     * with handling internal Cassandra exceptions.
+     *
+     * @param name Property name.
+     * @param value Property value.
+     */
+    private static void setProperty(String name, Object value)
+    {
+        runExceptionally(() -> confRegistry.set(name, value), new 
SearchInternalCauseForPublicAPI());
+    }
+
+    private static <T> T getProperty(Class<T> cls, String name)
+    {
+        return callExceptionally(() -> confRegistry.get(cls, name), new 
SearchInternalCauseForPublicAPI());
+    }
+
+    private static class SearchInternalCauseForPublicAPI implements 
Function<Exception, RuntimeException>
+    {
+        @Override
+        public RuntimeException apply(Exception e)
+        {
+            RuntimeException rt;
+            if ((rt = cause(e, IllegalArgumentException.class)) != null)
+                return new IllegalArgumentException(rt.getMessage());
+            else if ((rt = cause(e, IllegalStateException.class)) != null)
+                return new IllegalStateException(rt.getMessage());
+            else if ((rt = cause(e, UnsupportedOperationException.class)) != 
null)
+                return new UnsupportedOperationException(rt.getMessage());
+            else
+            {
+                logger.error("Unexpected exception", e);
+                return new RuntimeException(e.getMessage());
+            }
+        }
+    }

Review Comment:
   The reason for this exception conversion is that, for example, the JMX 
client may not know about Cassandra classes (missing in its classpath), so it 
will fail if the `ConfigurationRegistry` throws an exception that has them. 
   
   Here is an example of a potential issues:
   https://issues.apache.org/jira/browse/CASSANDRA-17527
   
   I just re-think the usage once will find a common ground for the properties 
validation process on the ML. 



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to