commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From pro...@apache.org
Subject cvs commit: jakarta-commons/jexl/src/java/org/apache/commons/jexl/util/introspection UberspectImpl.java
Date Sun, 22 Jun 2003 19:40:40 GMT
proyal      2003/06/22 12:40:40

  Modified:    jexl/src/java/org/apache/commons/jexl/parser ASTMethod.java
               jexl/src/java/org/apache/commons/jexl/util/introspection
                        UberspectImpl.java
  Log:
  Fix 20729 - Rethrow exceptions from method execution rather than printing
  to console.
  
  Revision  Changes    Path
  1.3       +15 -26    jakarta-commons/jexl/src/java/org/apache/commons/jexl/parser/ASTMethod.java
  
  Index: ASTMethod.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/jexl/src/java/org/apache/commons/jexl/parser/ASTMethod.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- ASTMethod.java	5 Aug 2002 12:41:08 -0000	1.2
  +++ ASTMethod.java	22 Jun 2003 19:40:40 -0000	1.3
  @@ -28,40 +28,29 @@
        *  returns the value of itself applied to the object.
        *   We assume that an identifier can be gotten via a get(String)
        */
  -    public Object execute(Object obj, JexlContext jc)
  +    public Object execute(Object obj, JexlContext jc) throws Exception
       {
           String methodName = ((ASTIdentifier)jjtGetChild(0)).val;
   
  -        try
  -        {
  -            int paramCount = jjtGetNumChildren()-1;
  -
  -            /*
  -             *  get our params
  -             */
  -
  -            Object params[] = new Object[paramCount];
  -
  -            for (int i=0; i<paramCount; i++)
  -            {
  -                params[i] = ( (SimpleNode) jjtGetChild(i+1)).value(jc);
  -            }
  +        int paramCount = jjtGetNumChildren()-1;
   
  -            VelMethod vm = Introspector.getUberspect().getMethod(obj, methodName,
  -                params, new Info("",1,1));
  +        /*
  +         *  get our params
  +         */
   
  -            if (vm == null)
  -                return null;
  +        Object params[] = new Object[paramCount];
   
  -            return vm.invoke(obj, params);
  -        }
  -        catch(Exception e)
  +        for (int i=0; i<paramCount; i++)
           {
  -            System.out.println("ASTIdentifier : "+ e);
  -            e.printStackTrace();;
  +            params[i] = ( (SimpleNode) jjtGetChild(i+1)).value(jc);
           }
   
  -        return null;
  -    }
  +        VelMethod vm = Introspector.getUberspect().getMethod(obj, methodName,
  +            params, new Info("",1,1));
   
  +        if (vm == null)
  +            return null;
  +
  +        return vm.invoke(obj, params);
  +    }
   }
  
  
  
  1.3       +23 -2     jakarta-commons/jexl/src/java/org/apache/commons/jexl/util/introspection/UberspectImpl.java
  
  Index: UberspectImpl.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/jexl/src/java/org/apache/commons/jexl/util/introspection/UberspectImpl.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- UberspectImpl.java	9 Aug 2002 13:57:04 -0000	1.2
  +++ UberspectImpl.java	22 Jun 2003 19:40:40 -0000	1.3
  @@ -63,6 +63,7 @@
   import org.apache.commons.logging.Log;
   
   import java.lang.reflect.Method;
  +import java.lang.reflect.InvocationTargetException;
   import java.util.Iterator;
   import java.util.Collection;
   import java.util.Map;
  @@ -301,7 +302,27 @@
           public Object invoke(Object o, Object[] params)
               throws Exception
           {
  -            return method.invoke(o, params);
  +            try
  +            {
  +                return method.invoke(o, params);
  +            }
  +            catch( InvocationTargetException e )
  +            {
  +                final Throwable t = e.getTargetException();
  +
  +                if( t instanceof Exception )
  +                {
  +                    throw (Exception)t;
  +                }
  +                else if (t instanceof Error)
  +                {
  +                    throw (Error)t;
  +                }
  +                else
  +                {
  +                    throw e;
  +                }
  +            }
           }
   
           public boolean isCacheable()
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org


Mime
View raw message