Uploaded image for project: 'Metadata Aggregator'
  1. Metadata Aggregator
  2. MDA-232

XPathFilteringStage should throw StageProcessingException on error

    XMLWordPrintable

    Details

    • Type: New Feature
    • Status: Resolved
    • Priority: Major
    • Resolution: Fixed
    • Affects Version/s: 0.9.2
    • Fix Version/s: 0.10.0
    • Component/s: DOM Metadata
    • Labels:
      None

      Description

      There are two situations in XPathFilteringStage where an XPathExpressionException is caught and essentially ignored:

      If the expression fails to compile, an error is logged and no filtering is performed:

              try {
                  compiledExpression = xpath.compile(xpathExpression);
              } catch (final XPathExpressionException e) {
                  log.error("error compiling XPath expression; no filtering performed", e);
                  return;
              }
      

      If an evaluation of the expression throws, the individual item is filtered out of the collection:

                  try {
                      final Boolean filterThis = (Boolean) compiledExpression.evaluate(item.unwrap(), XPathConstants.BOOLEAN);
                      if (filterThis) {
                          log.debug("removing item matching XPath condition");
                          iterator.remove();
                      }
                  } catch (final XPathExpressionException e) {
                      log.error("removing item due to XPath expression error", e);
                      iterator.remove();
                  }
      

      I think this is the wrong approach in both cases; if the expression is faulty at runtime, this should be a StageProcessingException as it indicates that the Stage has been misconfigured.

      It would actually have been better in some ways to compile the expression in the stage's initializer, as that would turn at least one of these issues into a ComponentInitializationException, which I think would have been an improvement. Unfortunately, none of the objects in the XPath API are thread-safe or reentrant, so this would have required synchronized access to the field.

        Attachments

          Activity

            People

            Assignee:
            ian@iay.org.uk Ian Young
            Reporter:
            ian@iay.org.uk Ian Young
            Watchers:
            0 Start watching this issue

              Dates

              Created:
              Updated:
              Resolved: