Quantcast

Issues with default type conversion in 1.5

classic Classic list List threaded Threaded
10 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Issues with default type conversion in 1.5

Alec Swan
Hello,

I decided to extract this issue into a separate thread.

I keep running into issues with default type converters in 1.5. I also
think I found a bug in
org.apache.wicket.util.lang.Objects#convertValue. A call to
convertValue(nonNullNonArrayValue, Object.class) will always return
null if nonNullNonArrayValue is a value that is not null and not an
array! Shouldn't it always return the first parameter when the second
parameter is Object.class?

Is this a legitimate bug?

Thanks,

Alec

---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: Issues with default type conversion in 1.5

Paul Bors
Can you please put together a quick start for us?

~ Thank you,
   Paul C Bors

On Sep 7, 2012, at 14:39, Alec Swan <[hidden email]> wrote:

> Hello,
>
> I decided to extract this issue into a separate thread.
>
> I keep running into issues with default type converters in 1.5. I also
> think I found a bug in
> org.apache.wicket.util.lang.Objects#convertValue. A call to
> convertValue(nonNullNonArrayValue, Object.class) will always return
> null if nonNullNonArrayValue is a value that is not null and not an
> array! Shouldn't it always return the first parameter when the second
> parameter is Object.class?
>
> Is this a legitimate bug?
>
> Thanks,
>
> Alec
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [hidden email]
> For additional commands, e-mail: [hidden email]
>

---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

~ Thank you,
    Paul@Bors.ws
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: Issues with default type conversion in 1.5

Alec Swan
I attached a quickstart with a test in TestHomePage#formSubmitsSuccessfully.

The test throws "'NEW VALUE' is not a valid Serializable" error when
"NEW VALUE" string in "value" textField is submitted as a part of
myForm ajax submission.

This bug should have a high priority in 1.5 because this used to work
in 1.4 and there is no clear way to track down all places where this
needs to be fixed in the existing code base.

Thanks,

Alec

On Sat, Sep 8, 2012 at 12:16 AM, Paul Bors <[hidden email]> wrote:

> Can you please put together a quick start for us?
>
> ~ Thank you,
>    Paul C Bors
>
> On Sep 7, 2012, at 14:39, Alec Swan <[hidden email]> wrote:
>
>> Hello,
>>
>> I decided to extract this issue into a separate thread.
>>
>> I keep running into issues with default type converters in 1.5. I also
>> think I found a bug in
>> org.apache.wicket.util.lang.Objects#convertValue. A call to
>> convertValue(nonNullNonArrayValue, Object.class) will always return
>> null if nonNullNonArrayValue is a value that is not null and not an
>> array! Shouldn't it always return the first parameter when the second
>> parameter is Object.class?
>>
>> Is this a legitimate bug?
>>
>> Thanks,
>>
>> Alec
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: [hidden email]
>> For additional commands, e-mail: [hidden email]
>>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [hidden email]
> For additional commands, e-mail: [hidden email]
>


---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

invalidserializable.zip (55K) Download Attachment
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: Issues with default type conversion in 1.5

Alec Swan
An easy fix for this bug is to change the first line in
org.apache.wicket.util.lang.Objects#convertValue from
Object result = null;
to
Object result = value;

Thanks,

Alec

On Sat, Sep 8, 2012 at 1:02 PM, Alec Swan <[hidden email]> wrote:

> I attached a quickstart with a test in TestHomePage#formSubmitsSuccessfully.
>
> The test throws "'NEW VALUE' is not a valid Serializable" error when
> "NEW VALUE" string in "value" textField is submitted as a part of
> myForm ajax submission.
>
> This bug should have a high priority in 1.5 because this used to work
> in 1.4 and there is no clear way to track down all places where this
> needs to be fixed in the existing code base.
>
> Thanks,
>
> Alec
>
> On Sat, Sep 8, 2012 at 12:16 AM, Paul Bors <[hidden email]> wrote:
>> Can you please put together a quick start for us?
>>
>> ~ Thank you,
>>    Paul C Bors
>>
>> On Sep 7, 2012, at 14:39, Alec Swan <[hidden email]> wrote:
>>
>>> Hello,
>>>
>>> I decided to extract this issue into a separate thread.
>>>
>>> I keep running into issues with default type converters in 1.5. I also
>>> think I found a bug in
>>> org.apache.wicket.util.lang.Objects#convertValue. A call to
>>> convertValue(nonNullNonArrayValue, Object.class) will always return
>>> null if nonNullNonArrayValue is a value that is not null and not an
>>> array! Shouldn't it always return the first parameter when the second
>>> parameter is Object.class?
>>>
>>> Is this a legitimate bug?
>>>
>>> Thanks,
>>>
>>> Alec
>>>
>>> ---------------------------------------------------------------------
>>> To unsubscribe, e-mail: [hidden email]
>>> For additional commands, e-mail: [hidden email]
>>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: [hidden email]
>> For additional commands, e-mail: [hidden email]
>>

---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: Issues with default type conversion in 1.5

Sven Meier
Hi,

Objects#convertValue()'s javadoc states that it returns null, if the
value can not be converted, thus your proposed change isn't valid for
most cases.

You could easily fix this issue in your application by registering a
custom converter for Serializable.

Since Objects#convertValue() does more actually than "convert[ing]
numerically" (as stated in the javadoc, it handles booleans and Strings
too), I think the method could be improved, e.g by adding another
if-statement to it:

                 if (toType.isInstance(value))
                 {
                     result = toType.cast(value);
                 }

Please open an issue in Jira.

Sven


On 09/08/2012 09:11 PM, Alec Swan wrote:

> An easy fix for this bug is to change the first line in
> org.apache.wicket.util.lang.Objects#convertValue from
> Object result = null;
> to
> Object result = value;
>
> Thanks,
>
> Alec
>
> On Sat, Sep 8, 2012 at 1:02 PM, Alec Swan <[hidden email]> wrote:
>> I attached a quickstart with a test in TestHomePage#formSubmitsSuccessfully.
>>
>> The test throws "'NEW VALUE' is not a valid Serializable" error when
>> "NEW VALUE" string in "value" textField is submitted as a part of
>> myForm ajax submission.
>>
>> This bug should have a high priority in 1.5 because this used to work
>> in 1.4 and there is no clear way to track down all places where this
>> needs to be fixed in the existing code base.
>>
>> Thanks,
>>
>> Alec
>>
>> On Sat, Sep 8, 2012 at 12:16 AM, Paul Bors <[hidden email]> wrote:
>>> Can you please put together a quick start for us?
>>>
>>> ~ Thank you,
>>>     Paul C Bors
>>>
>>> On Sep 7, 2012, at 14:39, Alec Swan <[hidden email]> wrote:
>>>
>>>> Hello,
>>>>
>>>> I decided to extract this issue into a separate thread.
>>>>
>>>> I keep running into issues with default type converters in 1.5. I also
>>>> think I found a bug in
>>>> org.apache.wicket.util.lang.Objects#convertValue. A call to
>>>> convertValue(nonNullNonArrayValue, Object.class) will always return
>>>> null if nonNullNonArrayValue is a value that is not null and not an
>>>> array! Shouldn't it always return the first parameter when the second
>>>> parameter is Object.class?
>>>>
>>>> Is this a legitimate bug?
>>>>
>>>> Thanks,
>>>>
>>>> Alec
>>>>
>>>> ---------------------------------------------------------------------
>>>> To unsubscribe, e-mail: [hidden email]
>>>> For additional commands, e-mail: [hidden email]
>>>>
>>> ---------------------------------------------------------------------
>>> To unsubscribe, e-mail: [hidden email]
>>> For additional commands, e-mail: [hidden email]
>>>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [hidden email]
> For additional commands, e-mail: [hidden email]
>


---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: Issues with default type conversion in 1.5

Alec Swan
Here is a new JIRA https://issues.apache.org/jira/browse/WICKET-4755

I added the following code in my application class to implement what
you recommended as a fix. Maybe this will help other people who run
into this problem. Does this look good to you?

    @Override
    protected IConverterLocator newConverterLocator() {
        ConverterLocator locator = (ConverterLocator)
super.newConverterLocator();
        locator.set(Object.class, new BasicConverter());
        locator.set(Serializable.class, new BasicConverter());
        return locator;
    }

    private static class BasicConverter implements IConverter
    {
        @Override
        public Object convertToObject(String value, Locale locale) {
            return value;
        }

        @Override
        public String convertToString(Object value, Locale locale) {
            return value == null ? null : value.toString();
        }
    }


Thanks,

Alec

On Sat, Sep 8, 2012 at 3:47 PM, Sven Meier <[hidden email]> wrote:

> Hi,
>
> Objects#convertValue()'s javadoc states that it returns null, if the value
> can not be converted, thus your proposed change isn't valid for most cases.
>
> You could easily fix this issue in your application by registering a custom
> converter for Serializable.
>
> Since Objects#convertValue() does more actually than "convert[ing]
> numerically" (as stated in the javadoc, it handles booleans and Strings
> too), I think the method could be improved, e.g by adding another
> if-statement to it:
>
>                 if (toType.isInstance(value))
>                 {
>                     result = toType.cast(value);
>                 }
>
> Please open an issue in Jira.
>
> Sven
>
>
>
> On 09/08/2012 09:11 PM, Alec Swan wrote:
>>
>> An easy fix for this bug is to change the first line in
>> org.apache.wicket.util.lang.Objects#convertValue from
>> Object result = null;
>> to
>> Object result = value;
>>
>> Thanks,
>>
>> Alec
>>
>> On Sat, Sep 8, 2012 at 1:02 PM, Alec Swan <[hidden email]> wrote:
>>>
>>> I attached a quickstart with a test in
>>> TestHomePage#formSubmitsSuccessfully.
>>>
>>> The test throws "'NEW VALUE' is not a valid Serializable" error when
>>> "NEW VALUE" string in "value" textField is submitted as a part of
>>> myForm ajax submission.
>>>
>>> This bug should have a high priority in 1.5 because this used to work
>>> in 1.4 and there is no clear way to track down all places where this
>>> needs to be fixed in the existing code base.
>>>
>>> Thanks,
>>>
>>> Alec
>>>
>>> On Sat, Sep 8, 2012 at 12:16 AM, Paul Bors <[hidden email]> wrote:
>>>>
>>>> Can you please put together a quick start for us?
>>>>
>>>> ~ Thank you,
>>>>     Paul C Bors
>>>>
>>>> On Sep 7, 2012, at 14:39, Alec Swan <[hidden email]> wrote:
>>>>
>>>>> Hello,
>>>>>
>>>>> I decided to extract this issue into a separate thread.
>>>>>
>>>>> I keep running into issues with default type converters in 1.5. I also
>>>>> think I found a bug in
>>>>> org.apache.wicket.util.lang.Objects#convertValue. A call to
>>>>> convertValue(nonNullNonArrayValue, Object.class) will always return
>>>>> null if nonNullNonArrayValue is a value that is not null and not an
>>>>> array! Shouldn't it always return the first parameter when the second
>>>>> parameter is Object.class?
>>>>>
>>>>> Is this a legitimate bug?
>>>>>
>>>>> Thanks,
>>>>>
>>>>> Alec
>>>>>
>>>>> ---------------------------------------------------------------------
>>>>> To unsubscribe, e-mail: [hidden email]
>>>>> For additional commands, e-mail: [hidden email]
>>>>>
>>>> ---------------------------------------------------------------------
>>>> To unsubscribe, e-mail: [hidden email]
>>>> For additional commands, e-mail: [hidden email]
>>>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: [hidden email]
>> For additional commands, e-mail: [hidden email]
>>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [hidden email]
> For additional commands, e-mail: [hidden email]
>

---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: Issues with default type conversion in 1.5

Sven Meier
 > public Object convertToObject(String value, Locale locale) { return
value; }

That might fail badly causing a ClassCastException but as long as it works for you ;).

Thanks for creating the issue.
Sven


On 09/09/2012 09:22 AM, Alec Swan wrote:

> Here is a new JIRA https://issues.apache.org/jira/browse/WICKET-4755
>
> I added the following code in my application class to implement what
> you recommended as a fix. Maybe this will help other people who run
> into this problem. Does this look good to you?
>
>      @Override
>      protected IConverterLocator newConverterLocator() {
>          ConverterLocator locator = (ConverterLocator)
> super.newConverterLocator();
>          locator.set(Object.class, new BasicConverter());
>          locator.set(Serializable.class, new BasicConverter());
>          return locator;
>      }
>
>      private static class BasicConverter implements IConverter
>      {
>          @Override
>          public Object convertToObject(String value, Locale locale) {
>              return value;
>          }
>
>          @Override
>          public String convertToString(Object value, Locale locale) {
>              return value == null ? null : value.toString();
>          }
>      }
>
>
> Thanks,
>
> Alec
>
> On Sat, Sep 8, 2012 at 3:47 PM, Sven Meier <[hidden email]> wrote:
>> Hi,
>>
>> Objects#convertValue()'s javadoc states that it returns null, if the value
>> can not be converted, thus your proposed change isn't valid for most cases.
>>
>> You could easily fix this issue in your application by registering a custom
>> converter for Serializable.
>>
>> Since Objects#convertValue() does more actually than "convert[ing]
>> numerically" (as stated in the javadoc, it handles booleans and Strings
>> too), I think the method could be improved, e.g by adding another
>> if-statement to it:
>>
>>                  if (toType.isInstance(value))
>>                  {
>>                      result = toType.cast(value);
>>                  }
>>
>> Please open an issue in Jira.
>>
>> Sven
>>
>>
>>
>> On 09/08/2012 09:11 PM, Alec Swan wrote:
>>> An easy fix for this bug is to change the first line in
>>> org.apache.wicket.util.lang.Objects#convertValue from
>>> Object result = null;
>>> to
>>> Object result = value;
>>>
>>> Thanks,
>>>
>>> Alec
>>>
>>> On Sat, Sep 8, 2012 at 1:02 PM, Alec Swan <[hidden email]> wrote:
>>>> I attached a quickstart with a test in
>>>> TestHomePage#formSubmitsSuccessfully.
>>>>
>>>> The test throws "'NEW VALUE' is not a valid Serializable" error when
>>>> "NEW VALUE" string in "value" textField is submitted as a part of
>>>> myForm ajax submission.
>>>>
>>>> This bug should have a high priority in 1.5 because this used to work
>>>> in 1.4 and there is no clear way to track down all places where this
>>>> needs to be fixed in the existing code base.
>>>>
>>>> Thanks,
>>>>
>>>> Alec
>>>>
>>>> On Sat, Sep 8, 2012 at 12:16 AM, Paul Bors <[hidden email]> wrote:
>>>>> Can you please put together a quick start for us?
>>>>>
>>>>> ~ Thank you,
>>>>>      Paul C Bors
>>>>>
>>>>> On Sep 7, 2012, at 14:39, Alec Swan <[hidden email]> wrote:
>>>>>
>>>>>> Hello,
>>>>>>
>>>>>> I decided to extract this issue into a separate thread.
>>>>>>
>>>>>> I keep running into issues with default type converters in 1.5. I also
>>>>>> think I found a bug in
>>>>>> org.apache.wicket.util.lang.Objects#convertValue. A call to
>>>>>> convertValue(nonNullNonArrayValue, Object.class) will always return
>>>>>> null if nonNullNonArrayValue is a value that is not null and not an
>>>>>> array! Shouldn't it always return the first parameter when the second
>>>>>> parameter is Object.class?
>>>>>>
>>>>>> Is this a legitimate bug?
>>>>>>
>>>>>> Thanks,
>>>>>>
>>>>>> Alec
>>>>>>
>>>>>> ---------------------------------------------------------------------
>>>>>> To unsubscribe, e-mail: [hidden email]
>>>>>> For additional commands, e-mail: [hidden email]
>>>>>>
>>>>> ---------------------------------------------------------------------
>>>>> To unsubscribe, e-mail: [hidden email]
>>>>> For additional commands, e-mail: [hidden email]
>>>>>
>>> ---------------------------------------------------------------------
>>> To unsubscribe, e-mail: [hidden email]
>>> For additional commands, e-mail: [hidden email]
>>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: [hidden email]
>> For additional commands, e-mail: [hidden email]
>>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [hidden email]
> For additional commands, e-mail: [hidden email]
>


---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: Issues with default type conversion in 1.5

Alec Swan
In which case can it cause a ClassCastException?

On Sun, Sep 9, 2012 at 6:25 AM, Sven Meier <[hidden email]> wrote:

>> public Object convertToObject(String value, Locale locale) { return value;
>> }
>
> That might fail badly causing a ClassCastException but as long as it works
> for you ;).
>
> Thanks for creating the issue.
> Sven
>
>
>
> On 09/09/2012 09:22 AM, Alec Swan wrote:
>>
>> Here is a new JIRA https://issues.apache.org/jira/browse/WICKET-4755
>>
>> I added the following code in my application class to implement what
>> you recommended as a fix. Maybe this will help other people who run
>> into this problem. Does this look good to you?
>>
>>      @Override
>>      protected IConverterLocator newConverterLocator() {
>>          ConverterLocator locator = (ConverterLocator)
>> super.newConverterLocator();
>>          locator.set(Object.class, new BasicConverter());
>>          locator.set(Serializable.class, new BasicConverter());
>>          return locator;
>>      }
>>
>>      private static class BasicConverter implements IConverter
>>      {
>>          @Override
>>          public Object convertToObject(String value, Locale locale) {
>>              return value;
>>          }
>>
>>          @Override
>>          public String convertToString(Object value, Locale locale) {
>>              return value == null ? null : value.toString();
>>          }
>>      }
>>
>>
>> Thanks,
>>
>> Alec
>>
>> On Sat, Sep 8, 2012 at 3:47 PM, Sven Meier <[hidden email]> wrote:
>>>
>>> Hi,
>>>
>>> Objects#convertValue()'s javadoc states that it returns null, if the
>>> value
>>> can not be converted, thus your proposed change isn't valid for most
>>> cases.
>>>
>>> You could easily fix this issue in your application by registering a
>>> custom
>>> converter for Serializable.
>>>
>>> Since Objects#convertValue() does more actually than "convert[ing]
>>> numerically" (as stated in the javadoc, it handles booleans and Strings
>>> too), I think the method could be improved, e.g by adding another
>>> if-statement to it:
>>>
>>>                  if (toType.isInstance(value))
>>>                  {
>>>                      result = toType.cast(value);
>>>                  }
>>>
>>> Please open an issue in Jira.
>>>
>>> Sven
>>>
>>>
>>>
>>> On 09/08/2012 09:11 PM, Alec Swan wrote:
>>>>
>>>> An easy fix for this bug is to change the first line in
>>>> org.apache.wicket.util.lang.Objects#convertValue from
>>>> Object result = null;
>>>> to
>>>> Object result = value;
>>>>
>>>> Thanks,
>>>>
>>>> Alec
>>>>
>>>> On Sat, Sep 8, 2012 at 1:02 PM, Alec Swan <[hidden email]> wrote:
>>>>>
>>>>> I attached a quickstart with a test in
>>>>> TestHomePage#formSubmitsSuccessfully.
>>>>>
>>>>> The test throws "'NEW VALUE' is not a valid Serializable" error when
>>>>> "NEW VALUE" string in "value" textField is submitted as a part of
>>>>> myForm ajax submission.
>>>>>
>>>>> This bug should have a high priority in 1.5 because this used to work
>>>>> in 1.4 and there is no clear way to track down all places where this
>>>>> needs to be fixed in the existing code base.
>>>>>
>>>>> Thanks,
>>>>>
>>>>> Alec
>>>>>
>>>>> On Sat, Sep 8, 2012 at 12:16 AM, Paul Bors <[hidden email]> wrote:
>>>>>>
>>>>>> Can you please put together a quick start for us?
>>>>>>
>>>>>> ~ Thank you,
>>>>>>      Paul C Bors
>>>>>>
>>>>>> On Sep 7, 2012, at 14:39, Alec Swan <[hidden email]> wrote:
>>>>>>
>>>>>>> Hello,
>>>>>>>
>>>>>>> I decided to extract this issue into a separate thread.
>>>>>>>
>>>>>>> I keep running into issues with default type converters in 1.5. I
>>>>>>> also
>>>>>>> think I found a bug in
>>>>>>> org.apache.wicket.util.lang.Objects#convertValue. A call to
>>>>>>> convertValue(nonNullNonArrayValue, Object.class) will always return
>>>>>>> null if nonNullNonArrayValue is a value that is not null and not an
>>>>>>> array! Shouldn't it always return the first parameter when the second
>>>>>>> parameter is Object.class?
>>>>>>>
>>>>>>> Is this a legitimate bug?
>>>>>>>
>>>>>>> Thanks,
>>>>>>>
>>>>>>> Alec
>>>>>>>
>>>>>>> ---------------------------------------------------------------------
>>>>>>> To unsubscribe, e-mail: [hidden email]
>>>>>>> For additional commands, e-mail: [hidden email]
>>>>>>>
>>>>>> ---------------------------------------------------------------------
>>>>>> To unsubscribe, e-mail: [hidden email]
>>>>>> For additional commands, e-mail: [hidden email]
>>>>>>
>>>> ---------------------------------------------------------------------
>>>> To unsubscribe, e-mail: [hidden email]
>>>> For additional commands, e-mail: [hidden email]
>>>>
>>>
>>> ---------------------------------------------------------------------
>>> To unsubscribe, e-mail: [hidden email]
>>> For additional commands, e-mail: [hidden email]
>>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: [hidden email]
>> For additional commands, e-mail: [hidden email]
>>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [hidden email]
> For additional commands, e-mail: [hidden email]
>

---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: Issues with default type conversion in 1.5

Sven Meier
Sorry, my statement was wrong:
If you register your converter for Object and Serializable, everything
should be fine.

Sven

On 09/09/2012 07:21 PM, Alec Swan wrote:

> In which case can it cause a ClassCastException?
>
> On Sun, Sep 9, 2012 at 6:25 AM, Sven Meier <[hidden email]> wrote:
>>> public Object convertToObject(String value, Locale locale) { return value;
>>> }
>> That might fail badly causing a ClassCastException but as long as it works
>> for you ;).
>>
>> Thanks for creating the issue.
>> Sven
>>
>>
>>
>> On 09/09/2012 09:22 AM, Alec Swan wrote:
>>> Here is a new JIRA https://issues.apache.org/jira/browse/WICKET-4755
>>>
>>> I added the following code in my application class to implement what
>>> you recommended as a fix. Maybe this will help other people who run
>>> into this problem. Does this look good to you?
>>>
>>>       @Override
>>>       protected IConverterLocator newConverterLocator() {
>>>           ConverterLocator locator = (ConverterLocator)
>>> super.newConverterLocator();
>>>           locator.set(Object.class, new BasicConverter());
>>>           locator.set(Serializable.class, new BasicConverter());
>>>           return locator;
>>>       }
>>>
>>>       private static class BasicConverter implements IConverter
>>>       {
>>>           @Override
>>>           public Object convertToObject(String value, Locale locale) {
>>>               return value;
>>>           }
>>>
>>>           @Override
>>>           public String convertToString(Object value, Locale locale) {
>>>               return value == null ? null : value.toString();
>>>           }
>>>       }
>>>
>>>
>>> Thanks,
>>>
>>> Alec
>>>
>>> On Sat, Sep 8, 2012 at 3:47 PM, Sven Meier <[hidden email]> wrote:
>>>> Hi,
>>>>
>>>> Objects#convertValue()'s javadoc states that it returns null, if the
>>>> value
>>>> can not be converted, thus your proposed change isn't valid for most
>>>> cases.
>>>>
>>>> You could easily fix this issue in your application by registering a
>>>> custom
>>>> converter for Serializable.
>>>>
>>>> Since Objects#convertValue() does more actually than "convert[ing]
>>>> numerically" (as stated in the javadoc, it handles booleans and Strings
>>>> too), I think the method could be improved, e.g by adding another
>>>> if-statement to it:
>>>>
>>>>                   if (toType.isInstance(value))
>>>>                   {
>>>>                       result = toType.cast(value);
>>>>                   }
>>>>
>>>> Please open an issue in Jira.
>>>>
>>>> Sven
>>>>
>>>>
>>>>
>>>> On 09/08/2012 09:11 PM, Alec Swan wrote:
>>>>> An easy fix for this bug is to change the first line in
>>>>> org.apache.wicket.util.lang.Objects#convertValue from
>>>>> Object result = null;
>>>>> to
>>>>> Object result = value;
>>>>>
>>>>> Thanks,
>>>>>
>>>>> Alec
>>>>>
>>>>> On Sat, Sep 8, 2012 at 1:02 PM, Alec Swan <[hidden email]> wrote:
>>>>>> I attached a quickstart with a test in
>>>>>> TestHomePage#formSubmitsSuccessfully.
>>>>>>
>>>>>> The test throws "'NEW VALUE' is not a valid Serializable" error when
>>>>>> "NEW VALUE" string in "value" textField is submitted as a part of
>>>>>> myForm ajax submission.
>>>>>>
>>>>>> This bug should have a high priority in 1.5 because this used to work
>>>>>> in 1.4 and there is no clear way to track down all places where this
>>>>>> needs to be fixed in the existing code base.
>>>>>>
>>>>>> Thanks,
>>>>>>
>>>>>> Alec
>>>>>>
>>>>>> On Sat, Sep 8, 2012 at 12:16 AM, Paul Bors <[hidden email]> wrote:
>>>>>>> Can you please put together a quick start for us?
>>>>>>>
>>>>>>> ~ Thank you,
>>>>>>>       Paul C Bors
>>>>>>>
>>>>>>> On Sep 7, 2012, at 14:39, Alec Swan <[hidden email]> wrote:
>>>>>>>
>>>>>>>> Hello,
>>>>>>>>
>>>>>>>> I decided to extract this issue into a separate thread.
>>>>>>>>
>>>>>>>> I keep running into issues with default type converters in 1.5. I
>>>>>>>> also
>>>>>>>> think I found a bug in
>>>>>>>> org.apache.wicket.util.lang.Objects#convertValue. A call to
>>>>>>>> convertValue(nonNullNonArrayValue, Object.class) will always return
>>>>>>>> null if nonNullNonArrayValue is a value that is not null and not an
>>>>>>>> array! Shouldn't it always return the first parameter when the second
>>>>>>>> parameter is Object.class?
>>>>>>>>
>>>>>>>> Is this a legitimate bug?
>>>>>>>>
>>>>>>>> Thanks,
>>>>>>>>
>>>>>>>> Alec
>>>>>>>>
>>>>>>>> ---------------------------------------------------------------------
>>>>>>>> To unsubscribe, e-mail: [hidden email]
>>>>>>>> For additional commands, e-mail: [hidden email]
>>>>>>>>
>>>>>>> ---------------------------------------------------------------------
>>>>>>> To unsubscribe, e-mail: [hidden email]
>>>>>>> For additional commands, e-mail: [hidden email]
>>>>>>>
>>>>> ---------------------------------------------------------------------
>>>>> To unsubscribe, e-mail: [hidden email]
>>>>> For additional commands, e-mail: [hidden email]
>>>>>
>>>> ---------------------------------------------------------------------
>>>> To unsubscribe, e-mail: [hidden email]
>>>> For additional commands, e-mail: [hidden email]
>>>>
>>> ---------------------------------------------------------------------
>>> To unsubscribe, e-mail: [hidden email]
>>> For additional commands, e-mail: [hidden email]
>>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: [hidden email]
>> For additional commands, e-mail: [hidden email]
>>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [hidden email]
> For additional commands, e-mail: [hidden email]
>


---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: Issues with default type conversion in 1.5

Alec Swan
Perfect, thanks for your help!

On Sun, Sep 9, 2012 at 3:13 PM, Sven Meier <[hidden email]> wrote:

> Sorry, my statement was wrong:
> If you register your converter for Object and Serializable, everything
> should be fine.
>
> Sven
>
>
> On 09/09/2012 07:21 PM, Alec Swan wrote:
>>
>> In which case can it cause a ClassCastException?
>>
>> On Sun, Sep 9, 2012 at 6:25 AM, Sven Meier <[hidden email]> wrote:
>>>>
>>>> public Object convertToObject(String value, Locale locale) { return
>>>> value;
>>>> }
>>>
>>> That might fail badly causing a ClassCastException but as long as it
>>> works
>>> for you ;).
>>>
>>> Thanks for creating the issue.
>>> Sven
>>>
>>>
>>>
>>> On 09/09/2012 09:22 AM, Alec Swan wrote:
>>>>
>>>> Here is a new JIRA https://issues.apache.org/jira/browse/WICKET-4755
>>>>
>>>> I added the following code in my application class to implement what
>>>> you recommended as a fix. Maybe this will help other people who run
>>>> into this problem. Does this look good to you?
>>>>
>>>>       @Override
>>>>       protected IConverterLocator newConverterLocator() {
>>>>           ConverterLocator locator = (ConverterLocator)
>>>> super.newConverterLocator();
>>>>           locator.set(Object.class, new BasicConverter());
>>>>           locator.set(Serializable.class, new BasicConverter());
>>>>           return locator;
>>>>       }
>>>>
>>>>       private static class BasicConverter implements IConverter
>>>>       {
>>>>           @Override
>>>>           public Object convertToObject(String value, Locale locale) {
>>>>               return value;
>>>>           }
>>>>
>>>>           @Override
>>>>           public String convertToString(Object value, Locale locale) {
>>>>               return value == null ? null : value.toString();
>>>>           }
>>>>       }
>>>>
>>>>
>>>> Thanks,
>>>>
>>>> Alec
>>>>
>>>> On Sat, Sep 8, 2012 at 3:47 PM, Sven Meier <[hidden email]> wrote:
>>>>>
>>>>> Hi,
>>>>>
>>>>> Objects#convertValue()'s javadoc states that it returns null, if the
>>>>> value
>>>>> can not be converted, thus your proposed change isn't valid for most
>>>>> cases.
>>>>>
>>>>> You could easily fix this issue in your application by registering a
>>>>> custom
>>>>> converter for Serializable.
>>>>>
>>>>> Since Objects#convertValue() does more actually than "convert[ing]
>>>>> numerically" (as stated in the javadoc, it handles booleans and Strings
>>>>> too), I think the method could be improved, e.g by adding another
>>>>> if-statement to it:
>>>>>
>>>>>                   if (toType.isInstance(value))
>>>>>                   {
>>>>>                       result = toType.cast(value);
>>>>>                   }
>>>>>
>>>>> Please open an issue in Jira.
>>>>>
>>>>> Sven
>>>>>
>>>>>
>>>>>
>>>>> On 09/08/2012 09:11 PM, Alec Swan wrote:
>>>>>>
>>>>>> An easy fix for this bug is to change the first line in
>>>>>> org.apache.wicket.util.lang.Objects#convertValue from
>>>>>> Object result = null;
>>>>>> to
>>>>>> Object result = value;
>>>>>>
>>>>>> Thanks,
>>>>>>
>>>>>> Alec
>>>>>>
>>>>>> On Sat, Sep 8, 2012 at 1:02 PM, Alec Swan <[hidden email]> wrote:
>>>>>>>
>>>>>>> I attached a quickstart with a test in
>>>>>>> TestHomePage#formSubmitsSuccessfully.
>>>>>>>
>>>>>>> The test throws "'NEW VALUE' is not a valid Serializable" error when
>>>>>>> "NEW VALUE" string in "value" textField is submitted as a part of
>>>>>>> myForm ajax submission.
>>>>>>>
>>>>>>> This bug should have a high priority in 1.5 because this used to work
>>>>>>> in 1.4 and there is no clear way to track down all places where this
>>>>>>> needs to be fixed in the existing code base.
>>>>>>>
>>>>>>> Thanks,
>>>>>>>
>>>>>>> Alec
>>>>>>>
>>>>>>> On Sat, Sep 8, 2012 at 12:16 AM, Paul Bors <[hidden email]> wrote:
>>>>>>>>
>>>>>>>> Can you please put together a quick start for us?
>>>>>>>>
>>>>>>>> ~ Thank you,
>>>>>>>>       Paul C Bors
>>>>>>>>
>>>>>>>> On Sep 7, 2012, at 14:39, Alec Swan <[hidden email]> wrote:
>>>>>>>>
>>>>>>>>> Hello,
>>>>>>>>>
>>>>>>>>> I decided to extract this issue into a separate thread.
>>>>>>>>>
>>>>>>>>> I keep running into issues with default type converters in 1.5. I
>>>>>>>>> also
>>>>>>>>> think I found a bug in
>>>>>>>>> org.apache.wicket.util.lang.Objects#convertValue. A call to
>>>>>>>>> convertValue(nonNullNonArrayValue, Object.class) will always return
>>>>>>>>> null if nonNullNonArrayValue is a value that is not null and not an
>>>>>>>>> array! Shouldn't it always return the first parameter when the
>>>>>>>>> second
>>>>>>>>> parameter is Object.class?
>>>>>>>>>
>>>>>>>>> Is this a legitimate bug?
>>>>>>>>>
>>>>>>>>> Thanks,
>>>>>>>>>
>>>>>>>>> Alec
>>>>>>>>>
>>>>>>>>>
>>>>>>>>> ---------------------------------------------------------------------
>>>>>>>>> To unsubscribe, e-mail: [hidden email]
>>>>>>>>> For additional commands, e-mail: [hidden email]
>>>>>>>>>
>>>>>>>>
>>>>>>>> ---------------------------------------------------------------------
>>>>>>>> To unsubscribe, e-mail: [hidden email]
>>>>>>>> For additional commands, e-mail: [hidden email]
>>>>>>>>
>>>>>> ---------------------------------------------------------------------
>>>>>> To unsubscribe, e-mail: [hidden email]
>>>>>> For additional commands, e-mail: [hidden email]
>>>>>>
>>>>> ---------------------------------------------------------------------
>>>>> To unsubscribe, e-mail: [hidden email]
>>>>> For additional commands, e-mail: [hidden email]
>>>>>
>>>> ---------------------------------------------------------------------
>>>> To unsubscribe, e-mail: [hidden email]
>>>> For additional commands, e-mail: [hidden email]
>>>>
>>>
>>> ---------------------------------------------------------------------
>>> To unsubscribe, e-mail: [hidden email]
>>> For additional commands, e-mail: [hidden email]
>>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: [hidden email]
>> For additional commands, e-mail: [hidden email]
>>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [hidden email]
> For additional commands, e-mail: [hidden email]
>

---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Loading...