<commit_before>/*
 * Copyright 2001-2005 The Apache Software Foundation.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *   http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * 
 */

package org.apache.jmeter.samplers;

import java.io.Serializable;
import java.io.UnsupportedEncodingException;
import java.net.HttpURLConnection;
import java.net.URL;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

import org.apache.avalon.framework.configuration.Configuration;
import org.apache.jmeter.assertions.AssertionResult;
import org.apache.jmeter.util.JMeterUtils;
import org.apache.jorphan.logging.LoggingManager;
import org.apache.log.Logger;

/**
 * This is a nice packaging for the various information returned from taking a
 * sample of an entry.
 * 
 */
public class SampleResult implements Serializable {

    // Needs to be accessible from Test code
    static final Logger log = LoggingManager.getLoggerForClass();

	// Bug 33196 - encoding ISO-8859-1 is only suitable for Western countries
	// However the suggested System.getProperty("file.encoding") is Cp1252 on
	// Windows
	// So use a new property with the original value as default
	private static final String DEFAULT_ENCODING 
            = JMeterUtils.getPropDefault("sampleresult.default.encoding", // $NON-NLS-1$
			"ISO-8859-1"); // $NON-NLS-1$

	/**
	 * Data type value indicating that the response data is text.
	 * 
	 * @see #getDataType
	 * @see #setDataType(java.lang.String)
	 */
	public final static String TEXT = "text"; // $NON-NLS-1$

	/**
	 * Data type value indicating that the response data is binary.
	 * 
	 * @see #getDataType
	 * @see #setDataType(java.lang.String)
	 */
	public final static String BINARY = "bin"; // $NON-NLS-1$

	/* empty arrays which can be returned instead of null */
	private static final byte[] EMPTY_BA = new byte[0];

	private static final SampleResult[] EMPTY_SR = new SampleResult[0];

	private static final AssertionResult[] EMPTY_AR = new AssertionResult[0];

	private SampleSaveConfiguration saveConfig;

	private SampleResult parent = null;

	/**
	 * @param propertiesToSave
	 *            The propertiesToSave to set.
	 */
	public void setSaveConfig(SampleSaveConfiguration propertiesToSave) {
		this.saveConfig = propertiesToSave;
	}

	public SampleSaveConfiguration getSaveConfig() {
		return saveConfig;
	}

	private byte[] responseData = EMPTY_BA;

	private String responseCode;

	private String label;

	private String samplerData;

	private String threadName;

	private String responseMessage = "";

	private String responseHeaders = ""; // Never return null

	private String contentType = ""; // e.g. text/html; charset=utf-8

	private String requestHeaders = "";

	private long timeStamp = 0;// the time stamp - can be start or end

	private long startTime = 0; // changed to protected for subclass

	private long endTime = 0; // changed to protected for subclass

	private long idleTime = 0;// Allow for non-sample time

	private long pauseTime = 0;// Start of pause (if any)

	private List assertionResults;

	private List subResults;

	private String dataType=""; // Don't return null if not set

	private boolean success;

	private Set files;
<commit_msg>Avoid NPE when writing JTL if threadName does not get set<commit_after>/*
 * Copyright 2001-2005 The Apache Software Foundation.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *   http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * 
 */

package org.apache.jmeter.samplers;

import java.io.Serializable;
import java.io.UnsupportedEncodingException;
import java.net.HttpURLConnection;
import java.net.URL;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

import org.apache.avalon.framework.configuration.Configuration;
import org.apache.jmeter.assertions.AssertionResult;
import org.apache.jmeter.util.JMeterUtils;
import org.apache.jorphan.logging.LoggingManager;
import org.apache.log.Logger;

/**
 * This is a nice packaging for the various information returned from taking a
 * sample of an entry.
 * 
 */
public class SampleResult implements Serializable {

    // Needs to be accessible from Test code
    static final Logger log = LoggingManager.getLoggerForClass();

	// Bug 33196 - encoding ISO-8859-1 is only suitable for Western countries
	// However the suggested System.getProperty("file.encoding") is Cp1252 on
	// Windows
	// So use a new property with the original value as default
	private static final String DEFAULT_ENCODING 
            = JMeterUtils.getPropDefault("sampleresult.default.encoding", // $NON-NLS-1$
			"ISO-8859-1"); // $NON-NLS-1$

	/**
	 * Data type value indicating that the response data is text.
	 * 
	 * @see #getDataType
	 * @see #setDataType(java.lang.String)
	 */
	public final static String TEXT = "text"; // $NON-NLS-1$

	/**
	 * Data type value indicating that the response data is binary.
	 * 
	 * @see #getDataType
	 * @see #setDataType(java.lang.String)
	 */
	public final static String BINARY = "bin"; // $NON-NLS-1$

	/* empty arrays which can be returned instead of null */
	private static final byte[] EMPTY_BA = new byte[0];

	private static final SampleResult[] EMPTY_SR = new SampleResult[0];

	private static final AssertionResult[] EMPTY_AR = new AssertionResult[0];

	private SampleSaveConfiguration saveConfig;

	private SampleResult parent = null;

	/**
	 * @param propertiesToSave
	 *            The propertiesToSave to set.
	 */
	public void setSaveConfig(SampleSaveConfiguration propertiesToSave) {
		this.saveConfig = propertiesToSave;
	}

	public SampleSaveConfiguration getSaveConfig() {
		return saveConfig;
	}

	private byte[] responseData = EMPTY_BA;

	private String responseCode;

	private String label;

	private String samplerData;

	private String threadName = ""; // Never return null

	private String responseMessage = "";

	private String responseHeaders = ""; // Never return null

	private String contentType = ""; // e.g. text/html; charset=utf-8

	private String requestHeaders = "";

	private long timeStamp = 0;// the time stamp - can be start or end

	private long startTime = 0; // changed to protected for subclass

	private long endTime = 0; // changed to protected for subclass

	private long idleTime = 0;// Allow for non-sample time

	private long pauseTime = 0;// Start of pause (if any)

	private List assertionResults;

	private List subResults;

	private String dataType=""; // Don't return null if not set

	private boolean success;

	private Set files;

{'fraction_non_alphanumeric': 0.08960236432025792, 'fraction_numerical': 0.011821601289629231, 'mean_word_length': 3.8312783906554184, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '1558759', 'n_tokens_mistral': 2194, 'n_tokens_neox': 2023, 'n_words': 779}