You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@wicket.apache.org by jWeekend <jw...@cabouge.com> on 2008/12/01 02:29:22 UTC

Re: Bug of Wicket when iterate the form using iterator()?

MarkupContainer's children field is declared as an Object and can refer to 

a ChildList - which is a List, hopefully (until it's genericised) of
Components, 
an Object[] - again, hopefully of Components,
a Component - ie a single child, or, even  
a ComponentSourceEntry - a bare-bones representation of only the
"essentials" of a Component from which it can be reconstructed.

I assume MarkupContainer's implementation was refactored (_from_ something
much more straight-forward) as an optimisation, in particular related to
serialisation, with the argument probably along the lines of: it is common
for a MarkupContainer to have just a single child, so we don't want the
luggage of a List in those cases etc ... 

All this can make MarkupContainer pretty fragile, easy to accidentally
break. If the optimisation argument is really strong enough (I expect it
must have been at the time and may still be), at the very least, all the
messy operations on "children" could be encapsulated in a class (perhaps
called FunkyChildren, possibly as an inner class if it necessarily needs
access to its owning MarkupContainer instance's guts and is never used
outside this context) that exposes only friendly methods like 
set(int index,Component child) and
remove(Component child) 
etc ...

Apart from simplifying MarkupContainer, the above design would also have the
benefit of making it possible to address the problem in hand (with the
illegal runtime array cast), mend what's broken and test this funky,
edge-case(?) behaviour without having to interfere with MarkupContainer.
And, if there's a simpler/better/more efficient FunkyChildren possible for
1.5 just plug in the new implementation. Importantly, as this an internal
change (internal to MarkupContainer), there will be no API break (neither
within Wicket nor in the public API).

Regards - Cemal
http://www.jWeekend.co.uk http://jWeekend.co.uk 



Matej Knopp-2 wrote:
> 
> this
> 
> sorted = Arrays.asList((Component[])children);
> 
> doesn't look right. I think it should have been (Object[])children
> although a type check would be appropriate.
> 
> -Matej
> 
> On Fri, Nov 28, 2008 at 7:30 PM, jWeekend <jw...@cabouge.com>
> wrote:
>>
>> Not quite.
>> String[] bO = (String[])(new Object[]{"yes","we","can"});
>> compiles but fails at run time.
>>
>> Regards - Cemal
>> http://www.jWeekend.co.uk  http://jWeekend.co.uk
>>
>>
>>
>> Valentine2008 wrote:
>>>
>>> It will bring the compilation error when trying to cast arrays in Java.
>>>
>>> So you mean it is a bug in Wicket?
>>>
>>>
>>> Timo Rantalaiho wrote:
>>>>
>>>> On Thu, 27 Nov 2008, Valentine2008 wrote:
>>>>> java.lang.ClassCastException: [Ljava.lang.Object; cannot be cast to
>>>>> [Lorg.apache
>>>>> .wicket.Component;
>>>>>         at
>>>>> org.apache.wicket.MarkupContainer.iterator(MarkupContainer.java:478)
>>>>> .........
>>>>>
>>>>> The code on line 478 of MarkupContainer.java is:
>>>>> sorted = Arrays.asList((Component[])children);
>>>>>
>>>>> Is it a bug of Wicket?
>>>>
>>>> No, I think it's a limitation of Java. You cannnot cast
>>>> arrays.
>>>>
>>>> Best wishes,
>>>> Timo
>>>>
>>>> --
>>>> Timo Rantalaiho
>>>> Reaktor Innovations Oy    <URL: http://www.ri.fi/ >
>>>>
>>>> ---------------------------------------------------------------------
>>>> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
>>>> For additional commands, e-mail: users-help@wicket.apache.org
>>>>
>>>>
>>>>
>>>
>>>
>>
>> --
>> View this message in context:
>> http://www.nabble.com/Bug-of-Wicket-1.3.4-when-iterate-the-form-using-iterator%28Comparator%29--tp20723903p20738179.html
>> Sent from the Wicket - User mailing list archive at Nabble.com.
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
>> For additional commands, e-mail: users-help@wicket.apache.org
>>
>>
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
> 
> 
> 

-- 
View this message in context: http://www.nabble.com/Bug-of-Wicket-1.3.4-when-iterate-the-form-using-iterator%28Comparator%29--tp20723903p20764684.html
Sent from the Wicket - User mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org


Re: Bug of Wicket when iterate the form using iterator()?

Posted by Johan Compagner <jc...@gmail.com>.
fixed

On Mon, Dec 1, 2008 at 16:48, Johan Compagner <jc...@gmail.com> wrote:

> i am busy fixing it
> but it is not as straightforward as just replacing it with Object[]
>
>
> On Mon, Dec 1, 2008 at 16:38, jWeekend <jw...@cabouge.com>wrote:
>
>>
>> Yes, your suggestion should stop that runtime exception being thrown. A
>> new
>> (or more comprehensive) test for that method could confirm this.
>>
>> What I described addresses a not totally unrelated but slightly broader
>> concern, and would not impact on any optimisations; it is not more
>> important
>> than fixing a known bug that is disturbing a user.
>>
>> Regards - Cemal
>> http://www.jWeekend.co.uk http://jWeekend.co.uk
>>
>>
>>
>> Matej Knopp-2 wrote:
>> >
>> > The only problem right now is the cast to Component[]. The fix is
>> > easy, just change it to Object[]. The optimization makes a lot of
>> > sense and there is reason why it can't really be simple.
>> >
>> > -Matej
>> >
>> > On Mon, Dec 1, 2008 at 2:29 AM, jWeekend <jw...@cabouge.com>
>> > wrote:
>> >>
>> >> MarkupContainer's children field is declared as an Object and can refer
>> >> to
>> >>
>> >> a ChildList - which is a List, hopefully (until it's genericised) of
>> >> Components,
>> >> an Object[] - again, hopefully of Components,
>> >> a Component - ie a single child, or, even
>> >> a ComponentSourceEntry - a bare-bones representation of only the
>> >> "essentials" of a Component from which it can be reconstructed.
>> >>
>> >> I assume MarkupContainer's implementation was refactored (_from_
>> >> something
>> >> much more straight-forward) as an optimisation, in particular related
>> to
>> >> serialisation, with the argument probably along the lines of: it is
>> >> common
>> >> for a MarkupContainer to have just a single child, so we don't want the
>> >> luggage of a List in those cases etc ...
>> >>
>> >> All this can make MarkupContainer pretty fragile, easy to accidentally
>> >> break. If the optimisation argument is really strong enough (I expect
>> it
>> >> must have been at the time and may still be), at the very least, all
>> the
>> >> messy operations on "children" could be encapsulated in a class
>> (perhaps
>> >> called FunkyChildren, possibly as an inner class if it necessarily
>> needs
>> >> access to its owning MarkupContainer instance's guts and is never used
>> >> outside this context) that exposes only friendly methods like
>> >> set(int index,Component child) and
>> >> remove(Component child)
>> >> etc ...
>> >>
>> >> Apart from simplifying MarkupContainer, the above design would also
>> have
>> >> the
>> >> benefit of making it possible to address the problem in hand (with the
>> >> illegal runtime array cast), mend what's broken and test this funky,
>> >> edge-case(?) behaviour without having to interfere with
>> MarkupContainer.
>> >> And, if there's a simpler/better/more efficient FunkyChildren possible
>> >> for
>> >> 1.5 just plug in the new implementation. Importantly, as this an
>> internal
>> >> change (internal to MarkupContainer), there will be no API break
>> (neither
>> >> within Wicket nor in the public API).
>> >>
>> >> Regards - Cemal
>> >> http://www.jWeekend.co.uk http://jWeekend.co.uk
>> >>
>> >>
>> >>
>> >> Matej Knopp-2 wrote:
>> >>>
>> >>> this
>> >>>
>> >>> sorted = Arrays.asList((Component[])children);
>> >>>
>> >>> doesn't look right. I think it should have been (Object[])children
>> >>> although a type check would be appropriate.
>> >>>
>> >>> -Matej
>> >>>
>> >>> On Fri, Nov 28, 2008 at 7:30 PM, jWeekend <
>> jweekend_forums@cabouge.com>
>> >>> wrote:
>> >>>>
>> >>>> Not quite.
>> >>>> String[] bO = (String[])(new Object[]{"yes","we","can"});
>> >>>> compiles but fails at run time.
>> >>>>
>> >>>> Regards - Cemal
>> >>>> http://www.jWeekend.co.uk  http://jWeekend.co.uk
>> >>>>
>> >>>>
>> >>>>
>> >>>> Valentine2008 wrote:
>> >>>>>
>> >>>>> It will bring the compilation error when trying to cast arrays in
>> >>>>> Java.
>> >>>>>
>> >>>>> So you mean it is a bug in Wicket?
>> >>>>>
>> >>>>>
>> >>>>> Timo Rantalaiho wrote:
>> >>>>>>
>> >>>>>> On Thu, 27 Nov 2008, Valentine2008 wrote:
>> >>>>>>> java.lang.ClassCastException: [Ljava.lang.Object; cannot be cast
>> to
>> >>>>>>> [Lorg.apache
>> >>>>>>> .wicket.Component;
>> >>>>>>>         at
>> >>>>>>>
>> org.apache.wicket.MarkupContainer.iterator(MarkupContainer.java:478)
>> >>>>>>> .........
>> >>>>>>>
>> >>>>>>> The code on line 478 of MarkupContainer.java is:
>> >>>>>>> sorted = Arrays.asList((Component[])children);
>> >>>>>>>
>> >>>>>>> Is it a bug of Wicket?
>> >>>>>>
>> >>>>>> No, I think it's a limitation of Java. You cannnot cast
>> >>>>>> arrays.
>> >>>>>>
>> >>>>>> Best wishes,
>> >>>>>> Timo
>> >>>>>>
>> >>>>>> --
>> >>>>>> Timo Rantalaiho
>> >>>>>> Reaktor Innovations Oy    <URL: http://www.ri.fi/ >
>> >>>>>>
>> >>>>>>
>> ---------------------------------------------------------------------
>> >>>>>> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
>> >>>>>> For additional commands, e-mail: users-help@wicket.apache.org
>> >>>>>>
>> >>>>>>
>> >>>>>>
>> >>>>>
>> >>>>>
>> >>>>
>> >>>> --
>> >>>> View this message in context:
>> >>>>
>> http://www.nabble.com/Bug-of-Wicket-1.3.4-when-iterate-the-form-using-iterator%28Comparator%29--tp20723903p20738179.html
>> >>>> Sent from the Wicket - User mailing list archive at Nabble.com.
>> >>>>
>> >>>>
>> >>>> ---------------------------------------------------------------------
>> >>>> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
>> >>>> For additional commands, e-mail: users-help@wicket.apache.org
>> >>>>
>> >>>>
>> >>>
>> >>> ---------------------------------------------------------------------
>> >>> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
>> >>> For additional commands, e-mail: users-help@wicket.apache.org
>> >>>
>> >>>
>> >>>
>> >>
>> >> --
>> >> View this message in context:
>> >>
>> http://www.nabble.com/Bug-of-Wicket-1.3.4-when-iterate-the-form-using-iterator%28Comparator%29--tp20723903p20764684.html
>> >> Sent from the Wicket - User mailing list archive at Nabble.com.
>> >>
>> >>
>> >> ---------------------------------------------------------------------
>> >> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
>> >> For additional commands, e-mail: users-help@wicket.apache.org
>> >>
>> >>
>> >
>> > ---------------------------------------------------------------------
>> > To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
>> > For additional commands, e-mail: users-help@wicket.apache.org
>> >
>> >
>> >
>>
>> --
>> View this message in context:
>> http://www.nabble.com/Bug-of-Wicket-1.3.4-when-iterate-the-form-using-iterator%28Comparator%29--tp20723903p20774302.html
>> Sent from the Wicket - User mailing list archive at Nabble.com.
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
>> For additional commands, e-mail: users-help@wicket.apache.org
>>
>>
>

Re: Bug of Wicket when iterate the form using iterator()?

Posted by Johan Compagner <jc...@gmail.com>.
i am busy fixing it
but it is not as straightforward as just replacing it with Object[]

On Mon, Dec 1, 2008 at 16:38, jWeekend <jw...@cabouge.com> wrote:

>
> Yes, your suggestion should stop that runtime exception being thrown. A new
> (or more comprehensive) test for that method could confirm this.
>
> What I described addresses a not totally unrelated but slightly broader
> concern, and would not impact on any optimisations; it is not more
> important
> than fixing a known bug that is disturbing a user.
>
> Regards - Cemal
> http://www.jWeekend.co.uk http://jWeekend.co.uk
>
>
>
> Matej Knopp-2 wrote:
> >
> > The only problem right now is the cast to Component[]. The fix is
> > easy, just change it to Object[]. The optimization makes a lot of
> > sense and there is reason why it can't really be simple.
> >
> > -Matej
> >
> > On Mon, Dec 1, 2008 at 2:29 AM, jWeekend <jw...@cabouge.com>
> > wrote:
> >>
> >> MarkupContainer's children field is declared as an Object and can refer
> >> to
> >>
> >> a ChildList - which is a List, hopefully (until it's genericised) of
> >> Components,
> >> an Object[] - again, hopefully of Components,
> >> a Component - ie a single child, or, even
> >> a ComponentSourceEntry - a bare-bones representation of only the
> >> "essentials" of a Component from which it can be reconstructed.
> >>
> >> I assume MarkupContainer's implementation was refactored (_from_
> >> something
> >> much more straight-forward) as an optimisation, in particular related to
> >> serialisation, with the argument probably along the lines of: it is
> >> common
> >> for a MarkupContainer to have just a single child, so we don't want the
> >> luggage of a List in those cases etc ...
> >>
> >> All this can make MarkupContainer pretty fragile, easy to accidentally
> >> break. If the optimisation argument is really strong enough (I expect it
> >> must have been at the time and may still be), at the very least, all the
> >> messy operations on "children" could be encapsulated in a class (perhaps
> >> called FunkyChildren, possibly as an inner class if it necessarily needs
> >> access to its owning MarkupContainer instance's guts and is never used
> >> outside this context) that exposes only friendly methods like
> >> set(int index,Component child) and
> >> remove(Component child)
> >> etc ...
> >>
> >> Apart from simplifying MarkupContainer, the above design would also have
> >> the
> >> benefit of making it possible to address the problem in hand (with the
> >> illegal runtime array cast), mend what's broken and test this funky,
> >> edge-case(?) behaviour without having to interfere with MarkupContainer.
> >> And, if there's a simpler/better/more efficient FunkyChildren possible
> >> for
> >> 1.5 just plug in the new implementation. Importantly, as this an
> internal
> >> change (internal to MarkupContainer), there will be no API break
> (neither
> >> within Wicket nor in the public API).
> >>
> >> Regards - Cemal
> >> http://www.jWeekend.co.uk http://jWeekend.co.uk
> >>
> >>
> >>
> >> Matej Knopp-2 wrote:
> >>>
> >>> this
> >>>
> >>> sorted = Arrays.asList((Component[])children);
> >>>
> >>> doesn't look right. I think it should have been (Object[])children
> >>> although a type check would be appropriate.
> >>>
> >>> -Matej
> >>>
> >>> On Fri, Nov 28, 2008 at 7:30 PM, jWeekend <jweekend_forums@cabouge.com
> >
> >>> wrote:
> >>>>
> >>>> Not quite.
> >>>> String[] bO = (String[])(new Object[]{"yes","we","can"});
> >>>> compiles but fails at run time.
> >>>>
> >>>> Regards - Cemal
> >>>> http://www.jWeekend.co.uk  http://jWeekend.co.uk
> >>>>
> >>>>
> >>>>
> >>>> Valentine2008 wrote:
> >>>>>
> >>>>> It will bring the compilation error when trying to cast arrays in
> >>>>> Java.
> >>>>>
> >>>>> So you mean it is a bug in Wicket?
> >>>>>
> >>>>>
> >>>>> Timo Rantalaiho wrote:
> >>>>>>
> >>>>>> On Thu, 27 Nov 2008, Valentine2008 wrote:
> >>>>>>> java.lang.ClassCastException: [Ljava.lang.Object; cannot be cast to
> >>>>>>> [Lorg.apache
> >>>>>>> .wicket.Component;
> >>>>>>>         at
> >>>>>>>
> org.apache.wicket.MarkupContainer.iterator(MarkupContainer.java:478)
> >>>>>>> .........
> >>>>>>>
> >>>>>>> The code on line 478 of MarkupContainer.java is:
> >>>>>>> sorted = Arrays.asList((Component[])children);
> >>>>>>>
> >>>>>>> Is it a bug of Wicket?
> >>>>>>
> >>>>>> No, I think it's a limitation of Java. You cannnot cast
> >>>>>> arrays.
> >>>>>>
> >>>>>> Best wishes,
> >>>>>> Timo
> >>>>>>
> >>>>>> --
> >>>>>> Timo Rantalaiho
> >>>>>> Reaktor Innovations Oy    <URL: http://www.ri.fi/ >
> >>>>>>
> >>>>>>
> ---------------------------------------------------------------------
> >>>>>> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> >>>>>> For additional commands, e-mail: users-help@wicket.apache.org
> >>>>>>
> >>>>>>
> >>>>>>
> >>>>>
> >>>>>
> >>>>
> >>>> --
> >>>> View this message in context:
> >>>>
> http://www.nabble.com/Bug-of-Wicket-1.3.4-when-iterate-the-form-using-iterator%28Comparator%29--tp20723903p20738179.html
> >>>> Sent from the Wicket - User mailing list archive at Nabble.com.
> >>>>
> >>>>
> >>>> ---------------------------------------------------------------------
> >>>> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> >>>> For additional commands, e-mail: users-help@wicket.apache.org
> >>>>
> >>>>
> >>>
> >>> ---------------------------------------------------------------------
> >>> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> >>> For additional commands, e-mail: users-help@wicket.apache.org
> >>>
> >>>
> >>>
> >>
> >> --
> >> View this message in context:
> >>
> http://www.nabble.com/Bug-of-Wicket-1.3.4-when-iterate-the-form-using-iterator%28Comparator%29--tp20723903p20764684.html
> >> Sent from the Wicket - User mailing list archive at Nabble.com.
> >>
> >>
> >> ---------------------------------------------------------------------
> >> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> >> For additional commands, e-mail: users-help@wicket.apache.org
> >>
> >>
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> > For additional commands, e-mail: users-help@wicket.apache.org
> >
> >
> >
>
> --
> View this message in context:
> http://www.nabble.com/Bug-of-Wicket-1.3.4-when-iterate-the-form-using-iterator%28Comparator%29--tp20723903p20774302.html
> Sent from the Wicket - User mailing list archive at Nabble.com.
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
>
>

Re: Bug of Wicket when iterate the form using iterator()?

Posted by jWeekend <jw...@cabouge.com>.
Yes, your suggestion should stop that runtime exception being thrown. A new
(or more comprehensive) test for that method could confirm this.

What I described addresses a not totally unrelated but slightly broader
concern, and would not impact on any optimisations; it is not more important
than fixing a known bug that is disturbing a user.

Regards - Cemal
http://www.jWeekend.co.uk http://jWeekend.co.uk 



Matej Knopp-2 wrote:
> 
> The only problem right now is the cast to Component[]. The fix is
> easy, just change it to Object[]. The optimization makes a lot of
> sense and there is reason why it can't really be simple.
> 
> -Matej
> 
> On Mon, Dec 1, 2008 at 2:29 AM, jWeekend <jw...@cabouge.com>
> wrote:
>>
>> MarkupContainer's children field is declared as an Object and can refer
>> to
>>
>> a ChildList - which is a List, hopefully (until it's genericised) of
>> Components,
>> an Object[] - again, hopefully of Components,
>> a Component - ie a single child, or, even
>> a ComponentSourceEntry - a bare-bones representation of only the
>> "essentials" of a Component from which it can be reconstructed.
>>
>> I assume MarkupContainer's implementation was refactored (_from_
>> something
>> much more straight-forward) as an optimisation, in particular related to
>> serialisation, with the argument probably along the lines of: it is
>> common
>> for a MarkupContainer to have just a single child, so we don't want the
>> luggage of a List in those cases etc ...
>>
>> All this can make MarkupContainer pretty fragile, easy to accidentally
>> break. If the optimisation argument is really strong enough (I expect it
>> must have been at the time and may still be), at the very least, all the
>> messy operations on "children" could be encapsulated in a class (perhaps
>> called FunkyChildren, possibly as an inner class if it necessarily needs
>> access to its owning MarkupContainer instance's guts and is never used
>> outside this context) that exposes only friendly methods like
>> set(int index,Component child) and
>> remove(Component child)
>> etc ...
>>
>> Apart from simplifying MarkupContainer, the above design would also have
>> the
>> benefit of making it possible to address the problem in hand (with the
>> illegal runtime array cast), mend what's broken and test this funky,
>> edge-case(?) behaviour without having to interfere with MarkupContainer.
>> And, if there's a simpler/better/more efficient FunkyChildren possible
>> for
>> 1.5 just plug in the new implementation. Importantly, as this an internal
>> change (internal to MarkupContainer), there will be no API break (neither
>> within Wicket nor in the public API).
>>
>> Regards - Cemal
>> http://www.jWeekend.co.uk http://jWeekend.co.uk
>>
>>
>>
>> Matej Knopp-2 wrote:
>>>
>>> this
>>>
>>> sorted = Arrays.asList((Component[])children);
>>>
>>> doesn't look right. I think it should have been (Object[])children
>>> although a type check would be appropriate.
>>>
>>> -Matej
>>>
>>> On Fri, Nov 28, 2008 at 7:30 PM, jWeekend <jw...@cabouge.com>
>>> wrote:
>>>>
>>>> Not quite.
>>>> String[] bO = (String[])(new Object[]{"yes","we","can"});
>>>> compiles but fails at run time.
>>>>
>>>> Regards - Cemal
>>>> http://www.jWeekend.co.uk  http://jWeekend.co.uk
>>>>
>>>>
>>>>
>>>> Valentine2008 wrote:
>>>>>
>>>>> It will bring the compilation error when trying to cast arrays in
>>>>> Java.
>>>>>
>>>>> So you mean it is a bug in Wicket?
>>>>>
>>>>>
>>>>> Timo Rantalaiho wrote:
>>>>>>
>>>>>> On Thu, 27 Nov 2008, Valentine2008 wrote:
>>>>>>> java.lang.ClassCastException: [Ljava.lang.Object; cannot be cast to
>>>>>>> [Lorg.apache
>>>>>>> .wicket.Component;
>>>>>>>         at
>>>>>>> org.apache.wicket.MarkupContainer.iterator(MarkupContainer.java:478)
>>>>>>> .........
>>>>>>>
>>>>>>> The code on line 478 of MarkupContainer.java is:
>>>>>>> sorted = Arrays.asList((Component[])children);
>>>>>>>
>>>>>>> Is it a bug of Wicket?
>>>>>>
>>>>>> No, I think it's a limitation of Java. You cannnot cast
>>>>>> arrays.
>>>>>>
>>>>>> Best wishes,
>>>>>> Timo
>>>>>>
>>>>>> --
>>>>>> Timo Rantalaiho
>>>>>> Reaktor Innovations Oy    <URL: http://www.ri.fi/ >
>>>>>>
>>>>>> ---------------------------------------------------------------------
>>>>>> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
>>>>>> For additional commands, e-mail: users-help@wicket.apache.org
>>>>>>
>>>>>>
>>>>>>
>>>>>
>>>>>
>>>>
>>>> --
>>>> View this message in context:
>>>> http://www.nabble.com/Bug-of-Wicket-1.3.4-when-iterate-the-form-using-iterator%28Comparator%29--tp20723903p20738179.html
>>>> Sent from the Wicket - User mailing list archive at Nabble.com.
>>>>
>>>>
>>>> ---------------------------------------------------------------------
>>>> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
>>>> For additional commands, e-mail: users-help@wicket.apache.org
>>>>
>>>>
>>>
>>> ---------------------------------------------------------------------
>>> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
>>> For additional commands, e-mail: users-help@wicket.apache.org
>>>
>>>
>>>
>>
>> --
>> View this message in context:
>> http://www.nabble.com/Bug-of-Wicket-1.3.4-when-iterate-the-form-using-iterator%28Comparator%29--tp20723903p20764684.html
>> Sent from the Wicket - User mailing list archive at Nabble.com.
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
>> For additional commands, e-mail: users-help@wicket.apache.org
>>
>>
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
> 
> 
> 

-- 
View this message in context: http://www.nabble.com/Bug-of-Wicket-1.3.4-when-iterate-the-form-using-iterator%28Comparator%29--tp20723903p20774302.html
Sent from the Wicket - User mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org


SV: Bug of Wicket when iterate the form using iterator()?

Posted by Wilhelmsen Tor Iver <To...@arrive.no>.
> The only problem right now is the cast to Component[]. The 
> fix is easy, just change it to Object[]. The optimization 
> makes a lot of sense and there is reason why it can't really 
> be simple.

The simplest explanation is that the (synthetic) array "classes" both
extend Object but are not in the same inheritance tree:

       "[L.../Component;"
      /
java.lang.Object
      \
       "[Ljava/lang/Object;"

Thus the casting fails (at runtime).

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org


Re: Bug of Wicket when iterate the form using iterator()?

Posted by Matej Knopp <ma...@gmail.com>.
The only problem right now is the cast to Component[]. The fix is
easy, just change it to Object[]. The optimization makes a lot of
sense and there is reason why it can't really be simple.

-Matej

On Mon, Dec 1, 2008 at 2:29 AM, jWeekend <jw...@cabouge.com> wrote:
>
> MarkupContainer's children field is declared as an Object and can refer to
>
> a ChildList - which is a List, hopefully (until it's genericised) of
> Components,
> an Object[] - again, hopefully of Components,
> a Component - ie a single child, or, even
> a ComponentSourceEntry - a bare-bones representation of only the
> "essentials" of a Component from which it can be reconstructed.
>
> I assume MarkupContainer's implementation was refactored (_from_ something
> much more straight-forward) as an optimisation, in particular related to
> serialisation, with the argument probably along the lines of: it is common
> for a MarkupContainer to have just a single child, so we don't want the
> luggage of a List in those cases etc ...
>
> All this can make MarkupContainer pretty fragile, easy to accidentally
> break. If the optimisation argument is really strong enough (I expect it
> must have been at the time and may still be), at the very least, all the
> messy operations on "children" could be encapsulated in a class (perhaps
> called FunkyChildren, possibly as an inner class if it necessarily needs
> access to its owning MarkupContainer instance's guts and is never used
> outside this context) that exposes only friendly methods like
> set(int index,Component child) and
> remove(Component child)
> etc ...
>
> Apart from simplifying MarkupContainer, the above design would also have the
> benefit of making it possible to address the problem in hand (with the
> illegal runtime array cast), mend what's broken and test this funky,
> edge-case(?) behaviour without having to interfere with MarkupContainer.
> And, if there's a simpler/better/more efficient FunkyChildren possible for
> 1.5 just plug in the new implementation. Importantly, as this an internal
> change (internal to MarkupContainer), there will be no API break (neither
> within Wicket nor in the public API).
>
> Regards - Cemal
> http://www.jWeekend.co.uk http://jWeekend.co.uk
>
>
>
> Matej Knopp-2 wrote:
>>
>> this
>>
>> sorted = Arrays.asList((Component[])children);
>>
>> doesn't look right. I think it should have been (Object[])children
>> although a type check would be appropriate.
>>
>> -Matej
>>
>> On Fri, Nov 28, 2008 at 7:30 PM, jWeekend <jw...@cabouge.com>
>> wrote:
>>>
>>> Not quite.
>>> String[] bO = (String[])(new Object[]{"yes","we","can"});
>>> compiles but fails at run time.
>>>
>>> Regards - Cemal
>>> http://www.jWeekend.co.uk  http://jWeekend.co.uk
>>>
>>>
>>>
>>> Valentine2008 wrote:
>>>>
>>>> It will bring the compilation error when trying to cast arrays in Java.
>>>>
>>>> So you mean it is a bug in Wicket?
>>>>
>>>>
>>>> Timo Rantalaiho wrote:
>>>>>
>>>>> On Thu, 27 Nov 2008, Valentine2008 wrote:
>>>>>> java.lang.ClassCastException: [Ljava.lang.Object; cannot be cast to
>>>>>> [Lorg.apache
>>>>>> .wicket.Component;
>>>>>>         at
>>>>>> org.apache.wicket.MarkupContainer.iterator(MarkupContainer.java:478)
>>>>>> .........
>>>>>>
>>>>>> The code on line 478 of MarkupContainer.java is:
>>>>>> sorted = Arrays.asList((Component[])children);
>>>>>>
>>>>>> Is it a bug of Wicket?
>>>>>
>>>>> No, I think it's a limitation of Java. You cannnot cast
>>>>> arrays.
>>>>>
>>>>> Best wishes,
>>>>> Timo
>>>>>
>>>>> --
>>>>> Timo Rantalaiho
>>>>> Reaktor Innovations Oy    <URL: http://www.ri.fi/ >
>>>>>
>>>>> ---------------------------------------------------------------------
>>>>> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
>>>>> For additional commands, e-mail: users-help@wicket.apache.org
>>>>>
>>>>>
>>>>>
>>>>
>>>>
>>>
>>> --
>>> View this message in context:
>>> http://www.nabble.com/Bug-of-Wicket-1.3.4-when-iterate-the-form-using-iterator%28Comparator%29--tp20723903p20738179.html
>>> Sent from the Wicket - User mailing list archive at Nabble.com.
>>>
>>>
>>> ---------------------------------------------------------------------
>>> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
>>> For additional commands, e-mail: users-help@wicket.apache.org
>>>
>>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
>> For additional commands, e-mail: users-help@wicket.apache.org
>>
>>
>>
>
> --
> View this message in context: http://www.nabble.com/Bug-of-Wicket-1.3.4-when-iterate-the-form-using-iterator%28Comparator%29--tp20723903p20764684.html
> Sent from the Wicket - User mailing list archive at Nabble.com.
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org