You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@empire-db.apache.org by do...@apache.org on 2022/04/28 12:04:50 UTC

[empire-db] branch master updated: EMPIREDB-388 NotSupportedException: improved type name detection

This is an automated email from the ASF dual-hosted git repository.

doebele pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/empire-db.git


The following commit(s) were added to refs/heads/master by this push:
     new c9eadf03 EMPIREDB-388 NotSupportedException: improved type name detection
c9eadf03 is described below

commit c9eadf03c688554c4926316e4aecaf268e11e596
Author: Rainer Döbele <do...@apache.org>
AuthorDate: Thu Apr 28 14:04:46 2022 +0200

    EMPIREDB-388 NotSupportedException: improved type name detection
---
 .../empire/exceptions/NotImplementedException.java |  7 ++++++-
 .../empire/exceptions/NotSupportedException.java   | 22 +++++++++++++++++-----
 2 files changed, 23 insertions(+), 6 deletions(-)

diff --git a/empire-db/src/main/java/org/apache/empire/exceptions/NotImplementedException.java b/empire-db/src/main/java/org/apache/empire/exceptions/NotImplementedException.java
index fa989350..b131189b 100644
--- a/empire-db/src/main/java/org/apache/empire/exceptions/NotImplementedException.java
+++ b/empire-db/src/main/java/org/apache/empire/exceptions/NotImplementedException.java
@@ -26,9 +26,14 @@ public class NotImplementedException extends EmpireException
     
     public static final ErrorType errorType = new ErrorType("error.notImplemented", "The function {0} is not implemented for type {1}.");
     
+    public NotImplementedException(Class<?> type, String functionName)
+    {
+        super(errorType, new String[] { functionName, (type!=null ? type.getName() : "-") });
+    }
+    
     public NotImplementedException(Object object, String functionName)
     {
-        super(errorType, new String[] { functionName, (object!=null ? object.getClass().getName() : "{unknown}") });
+        this((object!=null ? object.getClass() : null), functionName);
     }
 
 }
diff --git a/empire-db/src/main/java/org/apache/empire/exceptions/NotSupportedException.java b/empire-db/src/main/java/org/apache/empire/exceptions/NotSupportedException.java
index fbf045a5..464d2867 100644
--- a/empire-db/src/main/java/org/apache/empire/exceptions/NotSupportedException.java
+++ b/empire-db/src/main/java/org/apache/empire/exceptions/NotSupportedException.java
@@ -24,16 +24,28 @@ public class NotSupportedException extends EmpireException
 {
     private static final long serialVersionUID = 1L;
     
-    public static final ErrorType errorType = new ErrorType("error.notSupported", "The function {0} is not supported for type {1}.");
+    public static final ErrorType errorType = new ErrorType("error.notSupported", "The operation {0} is not supported for type {1}.");
     
-    public NotSupportedException(Object object, String functionName, Exception e)
+    private static String typeFromObject(Object object) 
     {
-        super(errorType, new String[] { functionName, (object!=null ? object.getClass().getName() : "{unknown}") }, e);
+        if (object instanceof String)
+            return (String)object;
+        if (object instanceof Class<?>)
+            return ((Class<?>)object).getName();
+        if (object!=null)
+            return object.getClass().getName();
+        // null
+        return "-";
     }
     
-    public NotSupportedException(Object object, String functionName)
+    public NotSupportedException(Object object, String operationName, Exception e)
     {
-        super(errorType, new String[] { functionName, (object!=null ? object.getClass().getName() : "{unknown}") });
+        super(errorType, new String[] { operationName, typeFromObject(object) }, e);
+    }
+    
+    public NotSupportedException(Object object, String operationName)
+    {
+        this(object, operationName, null);
     }
 
 }