You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@commons.apache.org by dl...@apache.org on 2002/08/21 09:22:48 UTC

cvs commit: jakarta-commons/lang/src/java/org/apache/commons/lang/exception NestableDelegate.java

dlr         2002/08/21 00:22:47

  Modified:    lang/src/java/org/apache/commons/lang/exception
                        NestableDelegate.java
  Log:
  o Changed type of "cause" instance field from Nestable to Throwable.
  Since implementation of Throwable is already required, this doesn't
  change the interface, but does simplify the internals.
  
  o Simplified code in getThrowableCount() method by removing extraneous
  null check and extra reference.
  
  o Implemented suggestion by Joachim.Sauer@tp-soft.com to use
  ExceptionUtils where Nestable.getCause() was previously called.
  
  Revision  Changes    Path
  1.3       +16 -34    jakarta-commons/lang/src/java/org/apache/commons/lang/exception/NestableDelegate.java
  
  Index: NestableDelegate.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/lang/src/java/org/apache/commons/lang/exception/NestableDelegate.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -u -r1.2 -r1.3
  --- NestableDelegate.java	26 Jul 2002 20:30:10 -0000	1.2
  +++ NestableDelegate.java	21 Aug 2002 07:22:47 -0000	1.3
  @@ -79,10 +79,10 @@
           + "constructor must extend java.lang.Throwable";
   
       /**
  -     * Holds the reference to the exception or error that caused
  -     * this exception to be thrown.
  +     * Holds the reference to the exception or error that caused this
  +     * exception to be thrown.
        */
  -    private Nestable cause = null;
  +    private Throwable cause = null;
   
       /**
        * Constructs a new <code>NestableDelegate</code> instance to manage the
  @@ -95,7 +95,7 @@
       {
           if (cause instanceof Throwable)
           {
  -            this.cause = cause;
  +            this.cause = (Throwable) cause;
           }
           else
           {
  @@ -148,7 +148,7 @@
               msg.append(baseMsg);
           }
   
  -        Throwable nestedCause = cause.getCause();
  +        Throwable nestedCause = ExceptionUtils.getCause(this.cause);
           if (nestedCause != null)
           {
               String causeMsg = nestedCause.getMessage();
  @@ -177,7 +177,7 @@
        */
       String[] getMessages() // package
       {
  -        Throwable throwables[] = this.getThrowables();
  +        Throwable[] throwables = this.getThrowables();
           String[] msgs = new String[throwables.length];
           for(int i = 0; i < throwables.length; i++)
           {
  @@ -201,7 +201,7 @@
       {
           if(index == 0)
           {
  -            return (Throwable) this.cause;
  +            return this.cause;
           }
           Throwable[] throwables = this.getThrowables();
           return throwables[index];
  @@ -218,22 +218,11 @@
           // Count the number of throwables
           int count = 1;
           String msg = null;
  -        if(this.cause.getCause() == null)
  -        {
  -            return count;
  -        }
  -        Throwable t = this.cause.getCause();
  -        while(t != null)
  +        Throwable t = ExceptionUtils.getCause(this.cause);
  +        while (t != null)
           {
               ++count;
  -            if(Nestable.class.isInstance(t))
  -            {
  -                t = ((Nestable) t).getCause();
  -            }
  -            else
  -            {
  -                t = null;
  -            }
  +            t = ExceptionUtils.getCause(t);
           }
           return count;
       }
  @@ -253,19 +242,12 @@
           count = 0;
           if(cause != null)
           {
  -            throwables[count++] = (Throwable) this.cause;
  -            Throwable t = this.cause.getCause();
  +            throwables[count++] = this.cause;
  +            Throwable t = ExceptionUtils.getCause(this.cause);
               while(t != null)
               {
                   throwables[count++] = t;
  -                if(Nestable.class.isInstance(t))
  -                {
  -                    t = ((Nestable) t).getCause();
  -                }
  -                else
  -                {
  -                    t = null;
  -                }
  +                t = ExceptionUtils.getCause(t);
               }
           }
           return throwables;
  @@ -344,8 +326,8 @@
       {
           synchronized (out)
           {
  -            String[] st = decompose((Throwable) cause);
  -            Throwable nestedCause = cause.getCause();
  +            String[] st = decompose(this.cause);
  +            Throwable nestedCause = ExceptionUtils.getCause(this.cause);
               if (nestedCause != null)
               {
                   if (nestedCause instanceof Nestable)
  
  
  

--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>