Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8146067

javax.xml.stream.StreamFilter does not report first accepted element

XMLWordPrintable

      FULL PRODUCT VERSION :
      java version "1.8.0_25"
      Java(TM) SE Runtime Environment (build 1.8.0_25-b17)
      Java HotSpot(TM) 64-Bit Server VM (build 25.25-b02, mixed mode)


      ADDITIONAL OS VERSION INFORMATION :
      Linux 3.16.0-4-amd64 #1 SMP Debian 3.16.7-ckt2-1 (2014-12-08) x86_64 GNU/Linux

      A DESCRIPTION OF THE PROBLEM :
      Filter a XMLStreamReader using a StreamFilter that accepts certain elements. Then the first accepted element won't be reported as a START_ELEMENT event.

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      See the provided test case.

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      The first accepted element should be reported as a XMLEvent.START_ELEMENT.
      ACTUAL -
      The first accepted element is not reported as a XMLEvent.START_ELEMENT.

      ERROR MESSAGES/STACK TRACES THAT OCCUR :
      No direct error message.

      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------
      test.xml:
      <?xml version="1.0" encoding="UTF-8"?>
      <first>
          <second>foo</second>
      </first>


      Main.java:
      public final class Main
      {
      public static void main(String[] p_args) throws Exception
      {
      final Path l_file = Paths.get("test.xml");
      assert Files.isRegularFile(l_file);

      final XMLInputFactory l_fac = XMLInputFactory.newFactory();

      final StreamFilter l_filter = new StreamFilter()
      {
      @Override
      public boolean accept(XMLStreamReader p_reader)
      {
      if (!p_reader.isStartElement() && !p_reader.isEndElement())
      return false;

      System.out.println("FILTER:" + p_reader.getLocalName());

      return true;
      }
      };

      try (final InputStream l_in = Files.newInputStream(l_file))
      {
      final XMLStreamReader l_reader =
      l_fac.createFilteredReader(l_fac.createXMLStreamReader(l_in), l_filter);

      final LinkedList<String> l_stack = new LinkedList<>();

      while (l_reader.hasNext())
      {
      switch (l_reader.next())
      {
      case XMLEvent.START_ELEMENT:
      System.out.println(l_reader.getLocalName());
      l_stack.push(l_reader.getLocalName());
      break;

      case XMLEvent.END_ELEMENT:
      System.out.println("/" + l_reader.getLocalName());
      l_stack.pop();
      break;
      }
      }
      }
      }
      }

      ---------- END SOURCE ----------

            joehw Joe Wang
            webbuggrp Webbug Group
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: