Henning P. Schmiedehausen writes:
Stephen Colebourne <[EMAIL PROTECTED]> writes:
My -1 will change to -0 if there is no public API
dependency on [lang] (as the dependency can then be
removed in v1.1). Which means changing the superclass
of EmailException, and following the pattern of
[collections] FunctorException.

Give us a patch. Code before words. As I said, I've looked into this
and I might do some work for 1.1. Not for 1.0.

        Regards 
                Henning


The patch is in the attachment, followed by the Java code itself, and there is nothing special: it does the same things, but without dependency exposed in public API.

There will be not so good idea to apply this after release 1.0, since that will mean breaking binary compatibility.

--Andrei Polushin
/*
 * Copyright 2001-2005 The Apache Software Foundation
 *
 * Licensed 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.commons.mail;

import java.io.PrintStream;
import java.io.PrintWriter;

/**
 * EmailException
 * @author jakarta-commons
 * @since 1.0
 */
public class EmailException extends Exception
{
    /** serialization version */
    static final long serialVersionUID = 5550674499282474616L;

    /** Does [EMAIL PROTECTED] Throwable} support nested exceptions. */
    private static final boolean HAVE_THROWABLE_CAUSE = haveThrowableCause();

    private static boolean haveThrowableCause()
    {
        try {
            Throwable.class.getDeclaredMethod("getCause", new Class[0]);
            return true;
        } catch (NoSuchMethodException ex) {
            return false;
        }
    }

    /** The exception or error that caused this exception to be thrown. */
    private Throwable cause = null;

    /**
     * Create a new EmailException with no message and no cause.
     * Note: This constructor should only be used as a last resort. Please
     * provide at least a message.
     * @since 1.0
     */
    public EmailException()
    {
        super();
    }

    /**
     * Create a new EmailException with a message but no other cause.
     * @param msg the reason for this exception.
     * @since 1.0
     */
    public EmailException(String msg)
    {
        super(msg);
    }

    /**
     * Create a new EmailException with a message and a cause.
     * @param msg the reason for this exception.
     * @param cause the contributing Throwable (e.g. some other Exception)
     * @since 1.0
     */
    public EmailException(String msg, Throwable cause)
    {
        super(msg);
        this.cause = cause;
    }

    /**
     * Create a new EmailException with a cause but no message.
     * @param cause the contributing Throwable (e.g. some other Exception)
     * @since 1.0
     */
    public EmailException(Throwable cause)
    {
        super(cause == null ? null : cause.getMessage());
        this.cause = cause;
    }

    /**
     * Returns the exception or error that caused this exception to be thrown.
     * @return the cause of this exception or <code>null</code> if the
     *         cause is nonexistent or unknown.
     * @since 1.0
     */
    public Throwable getCause()
    {
        return cause;
    }

    /**
     * Prints the stack trace of this exception to the standard error stream.
     */
    public void printStackTrace()
    {
        printStackTrace(System.err);
    }

    /**
     * Prints the stack trace of this exception to the specified stream.
     *
     * @param out the <code>PrintStream</code> to use for output
     */
    public void printStackTrace(PrintStream out)
    {
        synchronized (out)
        {
            PrintWriter pw = new PrintWriter(out, false);
            printStackTrace(pw);
            pw.flush();
        }
    }

    /**
     * Prints the stack trace of this exception to the specified writer.
     *
     * @param out the <code>PrintWriter</code> to use for output
     */
    public void printStackTrace(PrintWriter out)
    {
        synchronized (out)
        {
            super.printStackTrace(out);
            if (cause != null && !HAVE_THROWABLE_CAUSE)
            {
                out.print("Caused by: ");
                cause.printStackTrace(out);
            }
        }
    }

}
diff -d -r -C2 
commons-email.orig/src/java/org/apache/commons/mail/EmailException.java 
commons-email/src/java/org/apache/commons/mail/EmailException.java
*** commons-email.orig/src/java/org/apache/commons/mail/EmailException.java     
Fri Sep 02 18:38:56 2005
--- commons-email/src/java/org/apache/commons/mail/EmailException.java  Sat Sep 
03 18:20:56 2005
***************
*** 16,20 ****
  package org.apache.commons.mail;
  
! import org.apache.commons.lang.exception.NestableException;
  
  /**
--- 16,21 ----
  package org.apache.commons.mail;
  
! import java.io.PrintStream;
! import java.io.PrintWriter;
  
  /**
***************
*** 23,31 ****
   * @since 1.0
   */
! public class EmailException extends NestableException
  {
      /** serialization version */
      static final long serialVersionUID = 5550674499282474616L;
  
      /**
       * Create a new EmailException with no message and no cause.
--- 24,48 ----
   * @since 1.0
   */
! public class EmailException extends Exception
  {
      /** serialization version */
      static final long serialVersionUID = 5550674499282474616L;
  
+     /** Does [EMAIL PROTECTED] Throwable} support nested exceptions. */
+     private static final boolean HAVE_THROWABLE_CAUSE = haveThrowableCause();
+ 
+     private static boolean haveThrowableCause()
+     {
+         try {
+             Throwable.class.getDeclaredMethod("getCause", new Class[0]);
+             return true;
+         } catch (NoSuchMethodException ex) {
+             return false;
+         }
+     }
+ 
+     /** The exception or error that caused this exception to be thrown. */
+     private Throwable cause = null;
+ 
      /**
       * Create a new EmailException with no message and no cause.
***************
*** 57,61 ****
      public EmailException(String msg, Throwable cause)
      {
!         super(msg, cause);
      }
  
--- 74,79 ----
      public EmailException(String msg, Throwable cause)
      {
!         super(msg);
!         this.cause = cause;
      }
  
***************
*** 67,71 ****
      public EmailException(Throwable cause)
      {
!         super(cause);
      }
  
--- 85,142 ----
      public EmailException(Throwable cause)
      {
!         super(cause == null ? null : cause.getMessage());
!         this.cause = cause;
!     }
! 
!     /**
!      * Returns the exception or error that caused this exception to be thrown.
!      * @return the cause of this exception or <code>null</code> if the
!      *         cause is nonexistent or unknown.
!      * @since 1.0
!      */
!     public Throwable getCause()
!     {
!         return cause;
!     }
! 
!     /**
!      * Prints the stack trace of this exception to the standard error stream.
!      */
!     public void printStackTrace()
!     {
!         printStackTrace(System.err);
!     }
! 
!     /**
!      * Prints the stack trace of this exception to the specified stream.
!      *
!      * @param out the <code>PrintStream</code> to use for output
!      */
!     public void printStackTrace(PrintStream out)
!     {
!         synchronized (out)
!         {
!             PrintWriter pw = new PrintWriter(out, false);
!             printStackTrace(pw);
!             pw.flush();
!         }
!     }
! 
!     /**
!      * Prints the stack trace of this exception to the specified writer.
!      *
!      * @param out the <code>PrintWriter</code> to use for output
!      */
!     public void printStackTrace(PrintWriter out)
!     {
!         synchronized (out)
!         {
!             super.printStackTrace(out);
!             if (cause != null && !HAVE_THROWABLE_CAUSE)
!             {
!                 out.print("Caused by: ");
!                 cause.printStackTrace(out);
!             }
!         }
      }
  
/*
 * Copyright 2001-2005 The Apache Software Foundation
 *
 * Licensed 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.commons.mail;

import org.apache.commons.lang.exception.NestableException;

/**
 * EmailException
 * @author jakarta-commons
 * @since 1.0
 */
public class EmailException extends NestableException
{
    /** serialization version */
    static final long serialVersionUID = 5550674499282474616L;

    /**
     * Create a new EmailException with no message and no cause.
     * Note: This constructor should only be used as a last resort. Please
     * provide at least a message.
     * @since 1.0
     */
    public EmailException()
    {
        super();
    }

    /**
     * Create a new EmailException with a message but no other cause.
     * @param msg the reason for this exception.
     * @since 1.0
     */
    public EmailException(String msg)
    {
        super(msg);
    }

    /**
     * Create a new EmailException with a message and a cause.
     * @param msg the reason for this exception.
     * @param cause the contributing Throwable (e.g. some other Exception)
     * @since 1.0
     */
    public EmailException(String msg, Throwable cause)
    {
        super(msg, cause);
    }

    /**
     * Create a new EmailException with a cause but no message.
     * @param cause the contributing Throwable (e.g. some other Exception)
     * @since 1.0
     */
    public EmailException(Throwable cause)
    {
        super(cause);
    }

}

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to