struts-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Yasser Zamani (JIRA)" <j...@apache.org>
Subject [jira] [Commented] (WW-4216) Error in XWorkBasicConverter.convertValue()
Date Sun, 20 Oct 2013 08:00:47 GMT

    [ https://issues.apache.org/jira/browse/WW-4216?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13800096#comment-13800096
] 

Yasser Zamani commented on WW-4216:
-----------------------------------

[~patel.harigopal@gmail.com], I think XWork's behavior is more rational than what we expect
it to do, because, above code tries to set two values into status, one via POST and another
one via query string, so, status is more expected to be an array but in above code, it's setter
and getter are type of int, WDYT?

[~lukaszlenart], I carefully reviewed the convertValue revision's comments via SVN but I could
not find out what is the motivation of " || toType.isPrimitive()", did it mean " &&
toType.isPrimitive()"?

> Error in XWorkBasicConverter.convertValue()
> -------------------------------------------
>
>                 Key: WW-4216
>                 URL: https://issues.apache.org/jira/browse/WW-4216
>             Project: Struts 2
>          Issue Type: Bug
>    Affects Versions: 2.3.15.1
>            Reporter: Harigopal Patel
>             Fix For: 2.3.17
>
>
> if multiple name parameter in action then create string array
> ex :- abc.action?id=4&id=4&name=xyz
> Object value = string array [0=4,1=4]
> Class toType = int
> 2.0.7 branch :- no check Primitive data type
> {code:java}
> public Object convertValue(Map context, Object o, Member member, String s, Object value,
Class toType) {
>         Object result = null;
>         if (value == null || toType.isAssignableFrom(value.getClass())) {
>             return value;
>         }
>         if (toType == String.class) {
>             Class inputType = value.getClass();
>             if (Number.class.isAssignableFrom(inputType)) {
>                 result = doConvertFromNumberToString(context, value, inputType);
>                 if (result != null) {
>                     return result;
>                 }
>             }
>             result = doConvertToString(context, value);
>         } else if (toType == boolean.class) {
>             result = doConvertToBoolean(value);
>         } else if (toType == Boolean.class) {
>             result = doConvertToBoolean(value);
>         } else if (toType.isArray()) {
>             result = doConvertToArray(context, o, member, s, value, toType);
>         } else if (Date.class.isAssignableFrom(toType)) {
>             result = doConvertToDate(context, value, toType);
>         } else if (Collection.class.isAssignableFrom(toType)) {
>             result = doConvertToCollection(context, o, member, s, value, toType);
>         } else if (toType == Character.class) {
>             result = doConvertToCharacter(value);
>         } else if (toType == char.class) {
>             result = doConvertToCharacter(value);
>         } else if (Number.class.isAssignableFrom(toType)) {
>             result = doConvertToNumber(context, value, toType);
>         } else if (toType == Class.class) {
>             result = doConvertToClass(value);
>         }
>         if (result == null) {
>             if (value instanceof Object[]) {
>                 Object[] array = (Object[]) value;
>                 if (array.length >= 1) {
>                     value = array[0]; /************ call this code value = 4 ****************/
>                 }
>                 result = convertValue(context, o, member, s, value, toType);
>             } else if (!"".equals(value)) { // we've already tried the types we know
>                 result = super.convertValue(context, value, toType);
>             }
>             if (result == null && value != null && !"".equals(value))
{
>                 throw new XWorkException("Cannot create type " + toType + " from value
" + value);
>             }
>         }
>         return result;
>     }
> {code}
> 2.1.2 branch :- check Primitive data type
> {code:java}
> public Object convertValue(Map<String, Object> context, Object o, Member member,
String propertyName, Object value, Class toType) {
>         Object result = null;
>         if (value == null || toType.isAssignableFrom(value.getClass())) {
>             return value;
>         }
>         if (toType == String.class) {
>             Class inputType = value.getClass();
>             if (Number.class.isAssignableFrom(inputType)) {
>                 result = doConvertFromNumberToString(context, value, inputType);
>                 if (result != null) {
>                     return result;
>                 }
>             }
>             result = doConvertToString(context, value);
>         } else if (toType == boolean.class) {
>             result = doConvertToBoolean(value);
>         } else if (toType == Boolean.class) {
>             result = doConvertToBoolean(value);
>         } else if (toType.isArray()) {
>             result = doConvertToArray(context, o, member, propertyName, value, toType);
>         } else if (Date.class.isAssignableFrom(toType)) {
>             result = doConvertToDate(context, value, toType);
>         } else if (Calendar.class.isAssignableFrom(toType)) {
>             result = doConvertToCalendar(context, value);
>         } else if (Collection.class.isAssignableFrom(toType)) {
>             result = doConvertToCollection(context, o, member, propertyName, value, toType);
>         } else if (toType == Character.class) {
>             result = doConvertToCharacter(value);
>         } else if (toType == char.class) {
>             result = doConvertToCharacter(value);
>         } else if (Number.class.isAssignableFrom(toType) || toType.isPrimitive()) {
> /************ call this code because toType is a int data type but throws error because
value is a string array[0=4,1=4] ****************/
>             result = doConvertToNumber(context, value, toType);
>         } else if (toType == Class.class) {
>             result = doConvertToClass(value);
>         }
>         if (result == null) {
>             if (value instanceof Object[]) {
>                 Object[] array = (Object[]) value;
>                 if (array.length >= 1) {
>                     value = array[0];
>                 } else {
>                     value = null;
>                 }
>                 result = convertValue(context, o, member, propertyName, value, toType);
>             } else if (!"".equals(value)) { // we've already tried the types we know
>                 result = super.convertValue(context, value, toType);
>             }
>             if (result == null && value != null && !"".equals(value))
{
>                 throw new XWorkException("Cannot create type " + toType + " from value
" + value);
>             }
>         }
>         return result;
>     } 
> {code}



--
This message was sent by Atlassian JIRA
(v6.1#6144)

Mime
View raw message