Project: JDT
Bug 208460 [JUnit] JUnit history unreadable if failure message included a NUL (zero) character
Reported: 2007-11-01 14:15:47 | Status: resolved fixed

Build ID: I20070625-1500 Steps To Reproduce: 1. Paste the following into a java project: +++++++++++++++++++++++++++++++++++++++++++++ import junit.framework.TestCase; public class NulCharacterInJUnitTestFailureMessage extends TestCase { public void testNul() { String message = "This message contains a NUL {\0} and then some more text."; fail(message); } } +++++++++++++++++++++++++++++++++++++++++++++ 2.Run this as a JUnit Test 3.Run some other test (need to have more than one entry in the JUnit test history; can be before or after the above test). 4.Click the JUnit history drop-down, and switch back and forth between a successful test and the failing test above). 5.Notice that an error has been generated. If you have a JUnit history with many valid entries (without NULs), they will no longer be accessible (you won't be able to see the list of test cases). More information: The error is generated because the SAX parser is unable to parse &#0;, which is what the NUL character was translated to. This in turn is because NUL is not a legal XML character (I ran into exactly this problem several years ago with an XML parser written in C). You might say "Don't do that!", and I will fix the code that led to this problem, but it would be nice to fix this bug so that others don't spend the time trying to figure out what went wrong. FWIW, my solution in the past was to translate NUL to Unicode's user/vendor area before writing the XML file, and then back again in my SAX handler. Here is the error: eclipse.buildId=I20071004-2151 java.fullversion=J2RE 1.5.0 IBM J9 2.3 Windows XP x86-32 j9vmwi3223-20070426 (JIT enabled) J9VM - 20070420_12448_lHdSMR JIT - 20070419_1806_r8 GC - 200704_19 BootLoader constants: OS=win32, ARCH=x86, WS=win32, NL=en_US Framework arguments: -showlocation -showlocation Command-line arguments: -os win32 -ws win32 -arch x86 -clean -showlocation -clean -showlocation -clean -data D:\jmsynge\jazzdev-repo-work This is a continuation of log file D:\jmsynge\jazzdev-repo-work\.metadata\.bak_2.log Created Time: 2007-10-29 17:29:19.363 Error Thu Nov 01 14:03:15 EDT 2007 The test run could not be imported from file 'D:\jmsynge\jazzdev-repo-work\.metadata\.plugins\org.eclipse.jdt.junit\history\20071101-140251.583.xml'. org.xml.sax.SAXParseException: Character reference "&#0" is an invalid XML character. at org.apache.xerces.util.ErrorHandlerWrapper.createSAXParseException(Unknown Source) at org.apache.xerces.util.ErrorHandlerWrapper.fatalError(Unknown Source) at org.apache.xerces.impl.XMLErrorReporter.reportError(Unknown Source) at org.apache.xerces.impl.XMLErrorReporter.reportError(Unknown Source) at org.apache.xerces.impl.XMLScanner.reportFatalError(Unknown Source) at org.apache.xerces.impl.XMLScanner.scanCharReferenceValue(Unknown Source) at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl.scanCharReference(Unknown Source) at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl$FragmentContentDispatcher.dispatch(Unknown Source) at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl.scanDocument(Unknown Source) at org.apache.xerces.parsers.XML11Configuration.parse(Unknown Source) at org.apache.xerces.parsers.XML11Configuration.parse(Unknown Source) at org.apache.xerces.parsers.XMLParser.parse(Unknown Source) at org.apache.xerces.parsers.AbstractSAXParser.parse(Unknown Source) at org.apache.xerces.jaxp.SAXParserImpl.parse(Unknown Source) at javax.xml.parsers.SAXParser.parse(Unknown Source) at org.eclipse.jdt.internal.junit.model.JUnitModel.importIntoTestRunSession(JUnitModel.java:424) at org.eclipse.jdt.internal.junit.model.TestRunSession.swapIn(TestRunSession.java:356) at org.eclipse.jdt.internal.junit.model.TestRunSession.addTestSessionListener(TestRunSession.java:298) at org.eclipse.jdt.internal.junit.ui.TestRunnerViewPart.setActiveTestRunSession(TestRunnerViewPart.java:1215) at org.eclipse.jdt.internal.junit.ui.TestRunnerViewPart.access$2(TestRunnerViewPart.java:1164) at org.eclipse.jdt.internal.junit.ui.TestRunnerViewPart$RunnerViewHistory.setActiveEntry(TestRunnerViewPart.java:330) at org.eclipse.jdt.internal.ui.viewsupport.HistoryDropDownAction$HistoryAction.run(HistoryDropDownAction.java:54) at org.eclipse.jface.action.Action.runWithEvent(Action.java:498) at org.eclipse.jface.action.ActionContributionItem.handleWidgetSelection(ActionContributionItem.java:545) at org.eclipse.jface.action.ActionContributionItem.access$2(ActionContributionItem.java:490) at org.eclipse.jface.action.ActionContributionItem$5.handleEvent(ActionContributionItem.java:402) at org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java:66) at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:938) at org.eclipse.swt.widgets.Display.runDeferredEvents(Display.java:3682) at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:3293) at org.eclipse.ui.internal.Workbench.runEventLoop(Workbench.java:2389) at org.eclipse.ui.internal.Workbench.runUI(Workbench.java:2353) at org.eclipse.ui.internal.Workbench.access$4(Workbench.java:2219) at org.eclipse.ui.internal.Workbench$4.run(Workbench.java:466) at org.eclipse.core.databinding.observable.Realm.runWithDefault(Realm.java:289) at org.eclipse.ui.internal.Workbench.createAndRunWorkbench(Workbench.java:461) at org.eclipse.ui.PlatformUI.createAndRunWorkbench(PlatformUI.java:149) at org.eclipse.ui.internal.ide.application.IDEApplication.start(IDEApplication.java:106) at org.eclipse.equinox.internal.app.EclipseAppHandle.run(EclipseAppHandle.java:153) at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.runApplication(EclipseAppLauncher.java:106) at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.start(EclipseAppLauncher.java:76) at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:363) at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:176) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:64) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:615) at org.eclipse.equinox.launcher.Main.invokeFramework(Main.java:504) at org.eclipse.equinox.launcher.Main.basicRun(Main.java:443) at org.eclipse.equinox.launcher.Main.run(Main.java:1169)

Files changed in fix:
org.eclipse.jdt.junit.core/src/org/eclipse/jdt/internal/junit/model/TestRunSessionSerializer.java