geronimo-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From xuhaih...@apache.org
Subject svn commit: r1489683 - in /geronimo/specs/trunk/geronimo-javamail_1.4_spec/src: main/java/javax/mail/MessagingException.java test/java/javax/mail/MessagingExceptionTest.java
Date Wed, 05 Jun 2013 01:45:54 GMT
Author: xuhaihong
Date: Wed Jun  5 01:45:53 2013
New Revision: 1489683

URL: http://svn.apache.org/r1489683
Log:
GERONIMO-6471 IllegalStateException : Cause already initialized is thrown while mail provider
failed to connect or sent the messages

Modified:
    geronimo/specs/trunk/geronimo-javamail_1.4_spec/src/main/java/javax/mail/MessagingException.java
    geronimo/specs/trunk/geronimo-javamail_1.4_spec/src/test/java/javax/mail/MessagingExceptionTest.java

Modified: geronimo/specs/trunk/geronimo-javamail_1.4_spec/src/main/java/javax/mail/MessagingException.java
URL: http://svn.apache.org/viewvc/geronimo/specs/trunk/geronimo-javamail_1.4_spec/src/main/java/javax/mail/MessagingException.java?rev=1489683&r1=1489682&r2=1489683&view=diff
==============================================================================
--- geronimo/specs/trunk/geronimo-javamail_1.4_spec/src/main/java/javax/mail/MessagingException.java
(original)
+++ geronimo/specs/trunk/geronimo-javamail_1.4_spec/src/main/java/javax/mail/MessagingException.java
Wed Jun  5 01:45:53 2013
@@ -23,9 +23,9 @@ package javax.mail;
  * @version $Rev$ $Date$
  */
 public class MessagingException extends Exception {
-	
-	private static final long serialVersionUID = -7569192289819959253L;
-	
+
+    private static final long serialVersionUID = -7569192289819959253L;
+
     // Required because serialization expects it to be here
     private Exception next;
 
@@ -42,13 +42,12 @@ public class MessagingException extends 
         next = cause;
     }
 
-    public Exception getNextException() {
+    public synchronized Exception getNextException() {
         return next;
     }
 
     public synchronized boolean setNextException(Exception cause) {
         if (next == null) {
-            initCause(cause);
             next = cause;
             return true;
         } else if (next instanceof MessagingException) {
@@ -71,4 +70,12 @@ public class MessagingException extends 
                     + ")";
         }
     }
+    
+    /**
+     * MessagingException uses the nextException to provide a legacy chained throwable.
+     * override the getCause method to return the nextException.
+     */
+    public synchronized  Throwable getCause() {
+        return next;
+    }
 }

Modified: geronimo/specs/trunk/geronimo-javamail_1.4_spec/src/test/java/javax/mail/MessagingExceptionTest.java
URL: http://svn.apache.org/viewvc/geronimo/specs/trunk/geronimo-javamail_1.4_spec/src/test/java/javax/mail/MessagingExceptionTest.java?rev=1489683&r1=1489682&r2=1489683&view=diff
==============================================================================
--- geronimo/specs/trunk/geronimo-javamail_1.4_spec/src/test/java/javax/mail/MessagingExceptionTest.java
(original)
+++ geronimo/specs/trunk/geronimo-javamail_1.4_spec/src/test/java/javax/mail/MessagingExceptionTest.java
Wed Jun  5 01:45:53 2013
@@ -25,29 +25,51 @@ import junit.framework.TestCase;
  * @version $Revision $ $Date$
  */
 public class MessagingExceptionTest extends TestCase {
-    private RuntimeException d;
+    private RuntimeException e;
+    private MessagingException d;
     private MessagingException c;
     private MessagingException b;
     private MessagingException a;
     public MessagingExceptionTest(String name) {
         super(name);
     }
+    
     protected void setUp() throws Exception {
         super.setUp();
-        a = new MessagingException("A");
+        
+        //Initialize cause with null, make sure the getCause will not be affected
+        a = new MessagingException("A", null);
         b = new MessagingException("B");
         c = new MessagingException("C");
-        d = new RuntimeException("D");
+        d = new MessagingException("D");
+        e = new RuntimeException("E");
     }
+    
     public void testMessagingExceptionString() {
         assertEquals("A", a.getMessage());
     }
+    
     public void testNextException() {
         assertTrue(a.setNextException(b));
         assertEquals(b, a.getNextException());
+        assertEquals(b, a.getCause());
+        
         assertTrue(a.setNextException(c));
         assertEquals(b, a.getNextException());
         assertEquals(c, b.getNextException());
+        assertEquals(c, b.getCause());
+        
+        assertTrue(a.setNextException(d));
+        
+        assertEquals(b, a.getNextException());
+        assertEquals(b, a.getCause());
+        
+        assertEquals(c, b.getNextException());
+        assertEquals(c, b.getCause());
+        
+        assertEquals(d, c.getNextException());
+        assertEquals(d, c.getCause());
+        
         String message = a.getMessage();
         int ap = message.indexOf("A");
         int bp = message.indexOf("B");
@@ -56,14 +78,17 @@ public class MessagingExceptionTest exte
         assertTrue("B does not contain 'B'", bp != -1);
         assertTrue("C does not contain 'C'", cp != -1);
     }
+    
     public void testNextExceptionWrong() {
-        assertTrue(a.setNextException(d));
+        assertTrue(a.setNextException(e));
         assertFalse(a.setNextException(b));
     }
+    
     public void testNextExceptionWrong2() {
-        assertTrue(a.setNextException(d));
+        assertTrue(a.setNextException(e));
         assertFalse(a.setNextException(b));
     }
+    
     public void testMessagingExceptionStringException() {
         MessagingException x = new MessagingException("X", a);
         assertEquals("X (javax.mail.MessagingException: A)", x.getMessage());



Mime
View raw message