Uploaded image for project: 'logback'
  1. logback
  2. LOGBACK-191

Joran XML Parser sometimes misses white space characters from element bodies

    XMLWordPrintable

Details

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: Critical Critical
    • None
    • None
    • logback-core
    • None

    Description

      I have the following example configuration:

      <property name="Layout1" value="[Layout1] "xyz""/>

      <appender name="LayoutTest_Console" class="ch.qos.logback.core.ConsoleAppender">
      <filter class="ch.qos.logback.classic.filter.ThresholdFilter">
      <level>TRACE</level>
      </filter>
      <layout class="ch.qos.logback.classic.PatternLayout">
      <Pattern>
      [%date

      {yyyy-MM-dd HH:mm:ss.SSS}

      ] ${Layout1} [Layout2] "xyz"%n
      </Pattern>
      </layout>
      </appender>

      and this produces the following output:

      [2010-01-05 13:06:34.897] [Layout1] "xyz" [Layout2]"xyz"

      Notice the missing space between [Layout2] and "xyz" in the output that was present in the configuration.

      The investigation shows a bug in ch.qos.logback.core.joran.event.SaxEventRecorder:
      public void characters(char[] ch, int start, int length) {

      String body = new String(ch, start, length);
      if (body == null)

      { return; }

      // if the body string is null
      if (body != null) {
      String bodyTrimmed = body.trim();
      if (bodyTrimmed.length() == 0)

      { return; }
      }

      SaxEvent lastEvent = getLastEvent();
      if (lastEvent instanceof BodyEvent) { BodyEvent be = (BodyEvent) lastEvent; be.append(body); } else { saxEventList.add(new BodyEvent(body, getLocator())); }

      }

      In my case the following calls were made to this method:
      1. "[%date{yyyy-MM-dd HH:mm:ss.SSS}] ${Layout1} [Layout2]"
      2. " "
      3. """
      4. "xyz"
      5. """
      6. "%n".

      Note that the calls actually performed depend on the actual body content within the file and the actually used SAX parser (in my case com.sun.org.apache.xerces.internal.jaxp.SAXParserImpl$JAXPSAXParser).

      So within the method the:
      // if the body string is null
      if (body != null) {
      String bodyTrimmed = body.trim();
      if (bodyTrimmed.length() == 0) { return; }

      }
      must not occur if the last event was already a BodyEvent.

      Attachments

        Activity

          People

            ceki Ceki Gülcü
            mfranz@intershop.de Michael Franz
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: