<commit_before>package net.jsunit;

import org.jdom.Element;
import org.jdom.output.XMLOutputter;

public class TestCaseResultWriter {
	public static final String TEST_CASE = "testcase", NAME = "name", TIME = "time", FAILURE = "failure", ERROR = "error", MESSAGE = "message";
	
	private TestCaseResult result;
	public TestCaseResultWriter(TestCaseResult result) {
		this.result=result;
	}
	public void addXmlTo(Element element) {
		element.addContent(createTestCaseElement());
	}
	public Element createTestCaseElement() {
		Element testCaseElement = new Element(TEST_CASE);
		testCaseElement.setAttribute(NAME, result.getName());
		testCaseElement.setAttribute(TIME, String.valueOf(result.getTime()));
		if (result.hadFailure()) {
			Element failureElement = new Element(FAILURE);
			failureElement.setAttribute(MESSAGE, result.getFailure());
			testCaseElement.addContent(failureElement);
		} else if (result.hadError()) {
			Element errorElement = new Element(ERROR);
			errorElement.setAttribute(MESSAGE, result.getError());
			testCaseElement.addContent(errorElement);
		}
		return testCaseElement;<commit_msg>Prevent exceptions when message has null characters (bug 911152)<commit_after>package net.jsunit;

import org.jdom.Element;
import org.jdom.output.XMLOutputter;

public class TestCaseResultWriter {
	public static final String TEST_CASE = "testcase", NAME = "name", TIME = "time", FAILURE = "failure", ERROR = "error", MESSAGE = "message";
	
	private TestCaseResult result;
	public TestCaseResultWriter(TestCaseResult result) {
		this.result=result;
	}
	public void addXmlTo(Element element) {
		element.addContent(createTestCaseElement());
	}
	public Element createTestCaseElement() {
		Element testCaseElement = new Element(TEST_CASE);
		try {
		    testCaseElement.setAttribute(NAME, result.getName().replace('\u0000', ' '));
		} catch (Exception ex) {
		    ex.printStackTrace();
		}
		testCaseElement.setAttribute(TIME, String.valueOf(result.getTime()));
		if (result.hadFailure()) {
			Element failureElement = new Element(FAILURE);
			try {
			    failureElement.setAttribute(MESSAGE, result.getFailure().replace('\u0000', ' '));
			} catch(Exception ex) {
			    ex.printStackTrace();
			}
			testCaseElement.addContent(failureElement);
		} else if (result.hadError()) {
			Element errorElement = new Element(ERROR);
			try {
			    errorElement.setAttribute(MESSAGE, result.getError().replace('\u0000', ' '));
			} catch(Exception ex) {
			    ex.printStackTrace();
			}
			testCaseElement.addContent(errorElement);
		}
		return testCaseElement;
{'fraction_non_alphanumeric': 0.12271133619010519, 'fraction_numerical': 0.007012076353720296, 'mean_word_length': 5.187951807228916, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2972975', 'n_tokens_mistral': 815, 'n_tokens_neox': 729, 'n_words': 158}