Uploaded image for project: 'Wicket'
  1. Wicket
  2. WICKET-4390

MarkupParser#add(IMarkupFilter filter,Class beforeFilter) doesn't add the filter into the correct place.

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Resolved
    • Minor
    • Resolution: Fixed
    • 1.5.4, 6.0.0-beta1
    • 1.5.5, 6.0.0-beta1
    • wicket
    • None
    • any platform

    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 a Class<? extends IMarkupFilter>.

      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.

      Attachments

        1. wicket-bug.tar.gz
          21 kB
          Tsutomu YANO
        2. fix-WICKET-4390.patch
          1 kB
          Tsutomu YANO

        Activity

          People

            mgrigorov Martin Tzvetanov Grigorov
            t_yano Tsutomu YANO
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: