You are viewing a plain text version of this content. The canonical link for it is here.
Posted to java-dev@axis.apache.org by Edward Wertz <ed...@mindreef.com> on 2003/05/17 00:52:21 UTC

Fatal Bug in Call.java JavaUtils.convert(long, long[]) fails

JDK 1.4 and up.
Used last nights build of Axis. 

The scenerio is that I'm using a Doc-Literal webservice.  In the return message I'm expecting back a long[].  The problem comes in when the message has a single item in the array.  When the message has an array of length > 1 the JavaUtils.convert is invoked to convert from an ArrayList to long[].  When there is a single long in the message the JavaUtils.convert is invoked to convert from long to long[].  The conversion is not happening from long to long[].  I followed the axis code in my debugger and nowhere else is the long converted to a long[].   My wsdl2java generated stub code is expecting a long[] from the call.invoke, but it is getting a long back because it was not put inside of an array.  This causes a cast exception to occur.

It looks like the problem is that JavaUtils.convert doesn't make arrays out of single values.  Tracing the convert function returns in a section of code saying there was no mapping between the two types.  

This is the comment on the JavaUtils.convert function:

    /** Utility function to convert an Object to some desired Class.
     *
     * Right now this works for:
     *     arrays <-> Lists,
     *     Holders <-> held values
     * @param arg the array to convert
     * @param destClass the actual class we want
     */

This is the section of code that causes the convert function to return. 

        // Return if no conversion is available
        if (!(arg instanceof Collection ||
              (arg != null && arg.getClass().isArray())) &&
            ((destHeldType == null && argHeldType == null) ||
             (destHeldType != null && argHeldType != null))) {
            return arg;
        }



The Axis Code: Call.java Line 2303 


    /** Invoke an RPC service with a pre-constructed RPCElement.
     *
     * Note: Not part of JAX-RPC specification.
     *
     * @param body an RPCElement containing all the information about
     *             this call.
     * @return a deserialized Java Object containing the return value
     * @exception AxisFault
     */
    public Object invoke( RPCElement body ) throws AxisFault {

    .
    .
    .
                // The following loop looks at the resargs and
                // converts the value to the appropriate return/out parameter
                // value.  If the return value is found, is value is
                // placed in result.  The remaining resargs are
                // placed in the outParams list (note that if a resArg
                // is found that does not match a operation parameter qname,
                // it is still placed in the outParms list).
                for (int i = outParamStart; i < resArgs.size(); i++) {
                    RPCParam param = (RPCParam) resArgs.get(i);

                    Class javaType = getJavaTypeForQName(param.getQName());
                    Object value = param.getValue();

                    // Convert type if needed
                    if (javaType != null && value != null &&
                           !javaType.isAssignableFrom(value.getClass())) {
-------->                 value = JavaUtils.convert(value, javaType);
                    }
    .
    .
    .

Line 2365 
        // Convert type if needed
        if (operation != null && operation.getReturnClass() != null) {
-------->   result = JavaUtils.convert(result, operation.getReturnClass());  
        }
 
        return( result );
    }