[logback-dev] [JIRA] Created: (LBCORE-134) Joran XML Parser sometimes misses white space characters from element bodies

Michael Franz (JIRA) noreply-jira at qos.ch
Tue Jan 5 13:27:33 CET 2010


Joran XML Parser sometimes misses white space characters from element bodies
----------------------------------------------------------------------------

                 Key: LBCORE-134
                 URL: http://jira.qos.ch/browse/LBCORE-134
             Project: logback-core
          Issue Type: Bug
          Components: Joran
    Affects Versions: 0.9.18
            Reporter: Michael Franz
            Assignee: Logback dev list
            Priority: Critical


I have the following example configuration:

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

	<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] &quot;xyz&quot;%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.


-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: http://jira.qos.ch/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira

        


More information about the logback-dev mailing list