You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sling.apache.org by kw...@apache.org on 2016/12/08 13:22:54 UTC

svn commit: r1773229 - in /sling/trunk/bundles/extensions/models: api/ api/src/main/java/org/apache/sling/models/factory/ api/src/test/ api/src/test/java/ api/src/test/java/org/ api/src/test/java/org/apache/ api/src/test/java/org/apache/sling/ api/src/...

Author: kwin
Date: Thu Dec  8 13:22:54 2016
New Revision: 1773229

URL: http://svn.apache.org/viewvc?rev=1773229&view=rev
Log:
SLING-6369 MissingElementsException should not hide any stack traces of contained exceptions

Rely on suppressed exceptions being introduced with Java7.

Added:
    sling/trunk/bundles/extensions/models/api/src/test/
    sling/trunk/bundles/extensions/models/api/src/test/java/
    sling/trunk/bundles/extensions/models/api/src/test/java/org/
    sling/trunk/bundles/extensions/models/api/src/test/java/org/apache/
    sling/trunk/bundles/extensions/models/api/src/test/java/org/apache/sling/
    sling/trunk/bundles/extensions/models/api/src/test/java/org/apache/sling/models/
    sling/trunk/bundles/extensions/models/api/src/test/java/org/apache/sling/models/factory/
    sling/trunk/bundles/extensions/models/api/src/test/java/org/apache/sling/models/factory/MissingElementsExceptionTest.java   (with props)
Modified:
    sling/trunk/bundles/extensions/models/api/pom.xml
    sling/trunk/bundles/extensions/models/api/src/main/java/org/apache/sling/models/factory/MissingElementsException.java
    sling/trunk/bundles/extensions/models/api/src/main/java/org/apache/sling/models/factory/package-info.java
    sling/trunk/bundles/extensions/models/impl/pom.xml
    sling/trunk/bundles/extensions/models/integration-tests/pom.xml

Modified: sling/trunk/bundles/extensions/models/api/pom.xml
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/extensions/models/api/pom.xml?rev=1773229&r1=1773228&r2=1773229&view=diff
==============================================================================
--- sling/trunk/bundles/extensions/models/api/pom.xml (original)
+++ sling/trunk/bundles/extensions/models/api/pom.xml Thu Dec  8 13:22:54 2016
@@ -37,6 +37,9 @@
         <url>http://svn.apache.org/viewvc/sling/trunk/bundles/extensions/models/api</url>
     </scm>
     
+    <properties>
+        <sling.java.version>7</sling.java.version>
+    </properties>
     <build>
         <plugins>
             <plugin>
@@ -79,5 +82,17 @@
             <groupId>javax.servlet</groupId>
             <artifactId>servlet-api</artifactId>
         </dependency>
+        <!-- testing dependencies -->
+        <dependency>
+            <groupId>junit</groupId>
+            <artifactId>junit</artifactId>
+            <scope>test</scope>
+        </dependency>
+        <dependency>
+            <groupId>org.hamcrest</groupId>
+            <artifactId>hamcrest-junit</artifactId>
+            <version>2.0.0.0</version>
+            <scope>test</scope>
+        </dependency>
     </dependencies>
 </project>

Modified: sling/trunk/bundles/extensions/models/api/src/main/java/org/apache/sling/models/factory/MissingElementsException.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/extensions/models/api/src/main/java/org/apache/sling/models/factory/MissingElementsException.java?rev=1773229&r1=1773228&r2=1773229&view=diff
==============================================================================
--- sling/trunk/bundles/extensions/models/api/src/main/java/org/apache/sling/models/factory/MissingElementsException.java (original)
+++ sling/trunk/bundles/extensions/models/api/src/main/java/org/apache/sling/models/factory/MissingElementsException.java Thu Dec  8 13:22:54 2016
@@ -44,21 +44,9 @@ public final class MissingElementsExcept
         missingElements = new ArrayList<MissingElementException>();
     }
 
-    @Override
-    public String getMessage() {
-        StringBuilder message = new StringBuilder(super.getMessage());
-        for (MissingElementException e : missingElements) {
-            message.append('\n');
-            message.append(e.getMessage());
-            if (e.getCause() != null) {
-                message.append(" caused by ");
-                message.append(e.getCause().getMessage());
-            }
-        }
-        return message.toString();
-    }
-
     public void addMissingElementExceptions(MissingElementException e) {
+        // also add to suppressed list to make sure they appear as well with their full stack traces in the printStackTrace for this throwable
+        addSuppressed(e);
         missingElements.add(e);
     }
     

Modified: sling/trunk/bundles/extensions/models/api/src/main/java/org/apache/sling/models/factory/package-info.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/extensions/models/api/src/main/java/org/apache/sling/models/factory/package-info.java?rev=1773229&r1=1773228&r2=1773229&view=diff
==============================================================================
--- sling/trunk/bundles/extensions/models/api/src/main/java/org/apache/sling/models/factory/package-info.java (original)
+++ sling/trunk/bundles/extensions/models/api/src/main/java/org/apache/sling/models/factory/package-info.java Thu Dec  8 13:22:54 2016
@@ -14,7 +14,7 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-@Version("1.3.0")
+@Version("1.3.1")
 package org.apache.sling.models.factory;
 
 import aQute.bnd.annotation.Version;
\ No newline at end of file

Added: sling/trunk/bundles/extensions/models/api/src/test/java/org/apache/sling/models/factory/MissingElementsExceptionTest.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/extensions/models/api/src/test/java/org/apache/sling/models/factory/MissingElementsExceptionTest.java?rev=1773229&view=auto
==============================================================================
--- sling/trunk/bundles/extensions/models/api/src/test/java/org/apache/sling/models/factory/MissingElementsExceptionTest.java (added)
+++ sling/trunk/bundles/extensions/models/api/src/test/java/org/apache/sling/models/factory/MissingElementsExceptionTest.java Thu Dec  8 13:22:54 2016
@@ -0,0 +1,53 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.sling.models.factory;
+
+import java.io.PrintWriter;
+import java.io.StringWriter;
+
+import org.hamcrest.Matchers;
+import org.junit.Assert;
+import org.junit.Test;
+
+public class MissingElementsExceptionTest {
+
+    @Test
+    public void testMissingElementsExceptionStackTraceContainsTracesOfAggregatedExceptions() {
+        MissingElementsException wrapperException = new MissingElementsException("Test wrapper");
+        try {
+            try {
+                throw new IllegalStateException("Root exception");
+            } catch(IllegalStateException rootException) {
+                throw new MissingElementException(null, rootException);
+            }
+        } catch(MissingElementException e) {
+            wrapperException.addMissingElementExceptions(e);
+        }
+
+        // now evaluate exception message
+        Assert.assertThat(wrapperException.getMessage(), Matchers.not(Matchers.containsString("Root Exception")));
+        Assert.assertThat(wrapperException.getMessage(), Matchers.containsString("Test wrapper"));
+
+        // make sure the aggregated exceptions appear in the stack trace
+        StringWriter stringWriter = new StringWriter();
+        wrapperException.printStackTrace(new PrintWriter(stringWriter));
+        Assert.assertThat(stringWriter.toString(), Matchers.containsString("Root exception"));
+        Assert.assertThat(stringWriter.toString(), Matchers.containsString("Test wrapper"));
+    }
+}

Propchange: sling/trunk/bundles/extensions/models/api/src/test/java/org/apache/sling/models/factory/MissingElementsExceptionTest.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: sling/trunk/bundles/extensions/models/impl/pom.xml
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/extensions/models/impl/pom.xml?rev=1773229&r1=1773228&r2=1773229&view=diff
==============================================================================
--- sling/trunk/bundles/extensions/models/impl/pom.xml (original)
+++ sling/trunk/bundles/extensions/models/impl/pom.xml Thu Dec  8 13:22:54 2016
@@ -36,6 +36,9 @@
         <developerConnection> scm:svn:https://svn.apache.org/repos/asf/sling/trunk/bundles/extensions/models/impl</developerConnection>
         <url>http://svn.apache.org/viewvc/sling/trunk/bundles/extensions/models/impl</url>
     </scm>
+    <properties>
+        <sling.java.version>7</sling.java.version>
+    </properties>
     <build>
         <plugins>
             <plugin>
@@ -62,7 +65,7 @@
         <dependency>
             <groupId>org.apache.sling</groupId>
             <artifactId>org.apache.sling.models.api</artifactId>
-            <version>1.3.0</version>
+            <version>1.3.1-SNAPSHOT</version>
             <scope>provided</scope>
         </dependency>
         <dependency>

Modified: sling/trunk/bundles/extensions/models/integration-tests/pom.xml
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/extensions/models/integration-tests/pom.xml?rev=1773229&r1=1773228&r2=1773229&view=diff
==============================================================================
--- sling/trunk/bundles/extensions/models/integration-tests/pom.xml (original)
+++ sling/trunk/bundles/extensions/models/integration-tests/pom.xml Thu Dec  8 13:22:54 2016
@@ -52,6 +52,7 @@
         optionally using -Dmaven.surefire.debug to enable debugging.            
      -->
     <properties>
+        <sling.java.version>7</sling.java.version>
         <!-- Set this to run the server on a specific port
         <http.port></http.port>
          -->