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

Jesse Bonzo commented on WICKET-4906:
-------------------------------------

The method signature suggests that is about visiting FormComponents and 
subclasses of FormComponents because of the type parameter <? extends 
FormComponent<?> which allows subclasses of FormComponents. I would go back to 
my original suggestion and change the method signature to
public final <R> R visitFormComponents(final IVisitor<FormComponent<?>, R> 
visitor) 
That would better reflect what the method is actually doing. I would argue that 
this doesn't break the API since anyone who was passing in IVisitor<CheckBox> 
(or some other subclass) would get a ClassCastException at runtime. It would be 
better for the compiler to report this error.
                
> Form#visitFormComponents can cause ClassCastException
> -----------------------------------------------------
>
>                 Key: WICKET-4906
>                 URL: https://issues.apache.org/jira/browse/WICKET-4906
>             Project: Wicket
>          Issue Type: Bug
>          Components: wicket
>    Affects Versions: 6.3.0
>            Reporter: Jesse Bonzo
>            Priority: Minor
>              Labels: form, visit, wicket
>         Attachments: detectVisitorComponentClass.patch, 
> visitFormComponentsfix.patch, WicketQuickStart.zip
>
>
> The current method signature of Form#visitComponents allows for passing in an 
> implementation of IVisitor that will cause a ClassCastException. 
> Example
> Add a CheckBox and TextField to the Form. Pass in an IVisitor<CheckBox> to 
> visitComponents. There will be a ClassCastException when the 
> IVisitor<CheckBox> attempts to visit the TextField.
> The method signature should be changed to
> public final <R> R visitFormComponents(final IVisitor<FormComponent<?>, R> 
> visitor)
> or the method should be removed to prevent confusion.

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see: http://www.atlassian.com/software/jira

Reply via email to