jackrabbit-oak-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mdue...@apache.org
Subject svn commit: r1387939 - /jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/api/CommitFailedException.java
Date Thu, 20 Sep 2012 10:03:11 GMT
Author: mduerig
Date: Thu Sep 20 10:03:11 2012
New Revision: 1387939

URL: http://svn.apache.org/viewvc?rev=1387939&view=rev
Log:
OAK-316: CommitFailedException.throwRepositoryException swallows parts of the stack traces
throwRepositoryException needs to throw the actual type of its cause

Modified:
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/api/CommitFailedException.java

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/api/CommitFailedException.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/api/CommitFailedException.java?rev=1387939&r1=1387938&r2=1387939&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/api/CommitFailedException.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/api/CommitFailedException.java
Thu Sep 20 10:03:11 2012
@@ -39,10 +39,31 @@ public class CommitFailedException exten
     }
 
     /**
-     * Throw this exception wrapped into a {@link RepositoryException}
+     * Rethrow this exception cast into a {@link RepositoryException}: if the cause
+     * for this exception already is a {@code RepositoryException}, this exception is
+     * wrapped into the actual type of the cause and rethrown. If creating an instance
+     * of the actual type of the cause fails, cause is simply re-thrown.
+     * If the cause for this exception is not a {@code RepositoryException} then  a
+     * new {@code RepositoryException} instance with this {@code CommitFailedException}
+     * is thrown.
      * @throws RepositoryException
      */
     public void throwRepositoryException() throws RepositoryException {
-        throw new RepositoryException(this);
+        Throwable cause = getCause();
+        if (cause instanceof RepositoryException) {
+            RepositoryException e;
+            try {
+                e = (RepositoryException) cause.getClass().getConstructor().newInstance();
+                e.initCause(this);
+            }
+            catch (Exception ex) {
+                e = (RepositoryException) cause;
+            }
+
+            throw e;
+        }
+        else {
+            throw new RepositoryException(cause);
+        }
     }
 }



Mime
View raw message