[ 
https://issues.apache.org/jira/browse/WICKET-4390?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
 ]

Tsutomu YANO updated WICKET-4390:
---------------------------------

    Description: 
The documentation comment of MarkupParser#add(IMarkupFilter filter,Class<? 
extends IMarkupFilter> beforeFilter) says that 'filter' will be added before 
the 'beforeFilter', but the filter passed is always added as the last element 
of MarkupFilterList.

Technically, MarkupParser#add() internally uses an inner-class MarkupFilterList 
for managing filters. But the MarkupFilterList#add(IMarkupFilter filter,Class<? 
extends IMarkupFilter> beforeFilter) does not implemented correctly.

The method uses 'indexOf' of ArrayList for finding the matched instance of 
IMarkupFilter, though the parameter is not an instance of IMarkupFilter, but <? 
extends IMarkupFilter> beforeFilter).

We must iterate all registered IMarkupFilters and check if the Class of the 
IMarkupFilter matches with the parameter Class object for finding the index of 
'beforeFilter'.


** HOW TO REPRODUCE

Unpack, build and run the attached project 'wicket-bug.tar.gz'. 
jp.javelindev.wicket.MyMarkupFactory will log all registered filters with 
source below:

<pre>
    @Override
    public MarkupParser newMarkupParser(MarkupResourceStream resource) {
        MarkupParser parser = super.newMarkupParser(resource);
        parser.add(new MyMarkupFilter(), WicketTagIdentifier.class);
        parser.add(new MyMarkupFilter2());

        for (IMarkupFilter filter : parser.getMarkupFilters()) {
            LOGGER.info("filter class: {}", filter.getClass());
        }

        return parser;
    }
</pre>

If MarkupParser add filters at correct place, 

- MyMarkupFilter must be displayed at first (because WicketTagIdentifier is the 
first filter in default implementation) and 
- MyMarkupFilter2 must be displayed before RelativePathPrefixHandler (because 
the default implementation of add() of MarkupFilterList is like 'add(filter, 
RelativePathPrefixHandler.class)').

But with trunk and wicket-1.5.4, both filters is displayed at last.

** WORK AROUND **

I can avoid this issue by getting raw MarkupFilterList through 
getMarkupFilters() and writing code manually to find correct place for add().

** PATCH **

I attached a patch to fix this issue. see the source of MarkupParser.


  was:
The documentation comment of MarkupParser#add(IMarkupFilter filter,Class<? 
extends IMarkupFilter> beforeFilter) says that 'filter' will be added before 
the 'beforeFilter', but the filter passed is always added as the last element 
of MarkupList.

Technically, MarkupParser#add() internally uses an inner-class MarkupFilterList 
for managing filters. But the MarkupFilterList#add(IMarkupFilter filter,Class<? 
extends IMarkupFilter> beforeFilter) does not implemented correctly.

The method uses 'indexOf' of ArrayList for finding the matched instance of 
IMarkupFilter, though the parameter is not an instance of IMarkupFilter, but <? 
extends IMarkupFilter> beforeFilter).

We must iterate all registered IMarkupFilters and check if the Class of the 
IMarkupFilter matches with the parameter Class object for finding the index of 
'beforeFilter'.


** HOW TO REPRODUCE

Unpack, build and run the attached project 'wicket-bug.tar.gz'. 
jp.javelindev.wicket.MyMarkupFactory will log all registered filters with 
source below:

<pre>
    @Override
    public MarkupParser newMarkupParser(MarkupResourceStream resource) {
        MarkupParser parser = super.newMarkupParser(resource);
        parser.add(new MyMarkupFilter(), WicketTagIdentifier.class);
        parser.add(new MyMarkupFilter2());

        for (IMarkupFilter filter : parser.getMarkupFilters()) {
            LOGGER.info("filter class: {}", filter.getClass());
        }

        return parser;
    }
</pre>

If MarkupParser add filters at correct place, 

- MyMarkupFilter must be displayed at first (because WicketTagIdentifier is the 
first filter in default implementation) and 
- MyMarkupFilter2 must be displayed before RelativePathPrefixHandler (because 
the default implementation of add() of MarkupFilterList is like 'add(filter, 
RelativePathPrefixHandler.class)').

But with trunk and wicket-1.5.4, both filters is displayed at last.

** WORK AROUND **

I can avoid this issue by getting raw MarkupFilterList through 
getMarkupFilters() and writing code manually to find correct place for add().

** PATCH **

I attached a patch to fix this issue. see the source of MarkupParser.


    
> MarkupParser#add(IMarkupFilter filter,Class beforeFilter) doesn't add the 
> filter into the correct place.
> --------------------------------------------------------------------------------------------------------
>
>                 Key: WICKET-4390
>                 URL: https://issues.apache.org/jira/browse/WICKET-4390
>             Project: Wicket
>          Issue Type: Bug
>          Components: wicket
>    Affects Versions: 1.5.4, 6.0.0
>         Environment: any platform
>            Reporter: Tsutomu YANO
>            Priority: Minor
>         Attachments: fix-WICKET-4390.patch, wicket-bug.tar.gz
>
>
> The documentation comment of MarkupParser#add(IMarkupFilter filter,Class<? 
> extends IMarkupFilter> beforeFilter) says that 'filter' will be added before 
> the 'beforeFilter', but the filter passed is always added as the last element 
> of MarkupFilterList.
> Technically, MarkupParser#add() internally uses an inner-class 
> MarkupFilterList for managing filters. But the 
> MarkupFilterList#add(IMarkupFilter filter,Class<? extends IMarkupFilter> 
> beforeFilter) does not implemented correctly.
> The method uses 'indexOf' of ArrayList for finding the matched instance of 
> IMarkupFilter, though the parameter is not an instance of IMarkupFilter, but 
> <? extends IMarkupFilter> beforeFilter).
> We must iterate all registered IMarkupFilters and check if the Class of the 
> IMarkupFilter matches with the parameter Class object for finding the index 
> of 'beforeFilter'.
> ** HOW TO REPRODUCE
> Unpack, build and run the attached project 'wicket-bug.tar.gz'. 
> jp.javelindev.wicket.MyMarkupFactory will log all registered filters with 
> source below:
> <pre>
>     @Override
>     public MarkupParser newMarkupParser(MarkupResourceStream resource) {
>         MarkupParser parser = super.newMarkupParser(resource);
>         parser.add(new MyMarkupFilter(), WicketTagIdentifier.class);
>         parser.add(new MyMarkupFilter2());
>         for (IMarkupFilter filter : parser.getMarkupFilters()) {
>             LOGGER.info("filter class: {}", filter.getClass());
>         }
>         return parser;
>     }
> </pre>
> If MarkupParser add filters at correct place, 
> - MyMarkupFilter must be displayed at first (because WicketTagIdentifier is 
> the first filter in default implementation) and 
> - MyMarkupFilter2 must be displayed before RelativePathPrefixHandler (because 
> the default implementation of add() of MarkupFilterList is like 'add(filter, 
> RelativePathPrefixHandler.class)').
> But with trunk and wicket-1.5.4, both filters is displayed at last.
> ** WORK AROUND **
> I can avoid this issue by getting raw MarkupFilterList through 
> getMarkupFilters() and writing code manually to find correct place for add().
> ** PATCH **
> I attached a patch to fix this issue. see the source of MarkupParser.

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators: 
https://issues.apache.org/jira/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

Reply via email to