Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 301735 - Tracing: pipes in messages result in corrupt trace file
Summary: Tracing: pipes in messages result in corrupt trace file
Status: RESOLVED FIXED
Alias: None
Product: Equinox
Classification: Eclipse Project
Component: Framework (show other bugs)
Version: unspecified   Edit
Hardware: PC Windows Vista
: P3 normal (vote)
Target Milestone: 3.6 M6   Edit
Assignee: Thomas Watson CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2010-02-03 13:28 EST by Mathias Kinzler CLA
Modified: 2010-02-11 11:36 EST (History)
2 users (show)

See Also:


Attachments
Example trace with messages containing pipes (615 bytes, text/plain)
2010-02-03 13:31 EST, Mathias Kinzler CLA
no flags Details
possible patch for this problem. (9.44 KB, application/octet-stream)
2010-02-03 17:09 EST, Troy Bishop CLA
tjwatson: iplog+
Details
updated patch (7.88 KB, application/vnd.lotus-organizer)
2010-02-03 18:04 EST, Thomas Watson CLA
no flags Details
Proposed javadoc change (1.12 KB, patch)
2010-02-11 10:16 EST, Mathias Kinzler CLA
tjwatson: iplog+
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Mathias Kinzler CLA 2010-02-03 13:28:23 EST
Build Identifier:  I20091210-1301

When tracing a message containing pipes ('|'), the pipe is stored as-is which results in strange behavior when reading this file (I'm currently trying to write some sort of parser for trace files).
The only solution that I can see is to do some sort of escaping (of course pipes might not just occur in messages, but also in Exception messages that are traced using the corresponding trace(String, String, Throwable) method).
There is a similar issue with line breaks, but quite frankly, I'm not so sure about the correct solution; I managed to write some logic that can deal with this, but I haven't played around with all the possible combinations of /n and /r yet... 

Reproducible: Always

Steps to Reproduce:
1. Activate tracing for some location
2. call trace(<your location>, "A message with a pipe | here");
3. Observe the entry in the file
Comment 1 Mathias Kinzler CLA 2010-02-03 13:31:03 EST
Created attachment 158082 [details]
Example trace with messages containing pipes

The first entry was written with a message
"The pipe comes between o's: o|o", the second with a message
"The pipe comes between o's and spaces: o | o"
Comment 2 Thomas Watson CLA 2010-02-03 14:58:42 EST
See bug 286130.

I don't think line breaks are an issue if we can ensure that '|' is not contained in messages.  We likely need to do some escaping of '|' like you suggest for the following fields of a trace entry.

- thread name
- option path
- message
- throwable

If we escape the pipes somehow then each you just need to read each entry string up to the next '|' char, even if there are line feeds in the middle.  Correct?  I'm not sure what the best option is for escaping '|'.  Perhaps we should use the html escaping for '|' (&#124;).

Note that we already changed the format to version 1.1 for 3.6 in bug 286130 so any other changes here do not require a bump in format version.
Comment 3 Troy Bishop CLA 2010-02-03 17:09:46 EST
Created attachment 158108 [details]
possible patch for this problem.

How about the following patch?  It encodes any occurrences of | with the string Tom recommended (&#124;).  This is applied to only the thread name, option path, message, and any of the throwable text.  I've also updated the junit testcase to verify this scenario (however it only checks the option-path and message).
Comment 4 Thomas Watson CLA 2010-02-03 18:04:02 EST
Created attachment 158113 [details]
updated patch

Thanks Troy!

Here is an updated patch.  There was an issue if the | char was at the end of the string for decoding/encoding.  Here is another implementation of encoding/decoding and updated testcase to test having multiple | chars and at the beginning and end of the string.
Comment 5 Mathias Kinzler CLA 2010-02-04 03:48:44 EST
Great.
Comment 6 Thomas Watson CLA 2010-02-04 09:23:45 EST
Patch released. (with small change to not use "this" to call the static method encodeText).
Comment 7 Mathias Kinzler CLA 2010-02-11 10:16:16 EST
Created attachment 158860 [details]
Proposed javadoc change
Comment 8 Mathias Kinzler CLA 2010-02-11 10:18:01 EST
Comment on attachment 158860 [details]
Proposed javadoc change

The specific behavior for escaping pipes should be documented in the javadoc.
Comment 9 Thomas Watson CLA 2010-02-11 11:36:50 EST
Comment on attachment 158860 [details]
Proposed javadoc change

Thanks, patch has been released.