Buggy code:
public class ResultCollector extends AbstractListenerElement implements Serializable , NoThreadClone , Clearable , Remoteable , SampleListener , TestListener { private static final Logger log = LoggingManager . getLoggerForClass ( ) ; private static final long serialVersionUID = 231L ; private static final String TEST_IS_LOCAL = "*local*" ; private static final String TESTRESULTS_START = "<testResults>" ; private static final String TESTRESULTS_START_V1_1_PREVER = "<testResults<seq2seq4repair_space>version=\"" ; private static final String TESTRESULTS_START_V1_1_POSTVER = "\">" ; private static final String TESTRESULTS_END = "<//testResults>" ; private static final String XML_HEADER = "<?xml<seq2seq4repair_space>version=\"1.0\"<seq2seq4repair_space>encoding=\"UTF-8\"?>" ; private static final int MIN_XML_FILE_LEN = ( ( ResultCollector . XML_HEADER . length ( ) ) + ( ResultCollector . TESTRESULTS_START . length ( ) ) ) + ( ResultCollector . TESTRESULTS_END . length ( ) ) ; public static final String FILENAME = "filename" ; private static final String SAVE_CONFIG = "saveConfig" ; private static final String ERROR_LOGGING = "ResultCollector.error_logging" ; private transient DefaultConfigurationSerializer serializer ; private volatile transient PrintWriter out ; private boolean inTest = false ; private static Map files = new HashMap ( ) ; private Set hosts = new HashSet ( ) ; protected boolean isStats = false ; public ResultCollector ( ) { } public Object clone ( ) { } private void setFilenameProperty ( String f ) { } public String getFilename ( ) { } public boolean isErrorLogging ( ) { } public void setErrorLogging ( boolean errorLogging ) { } public void setFilename ( String f ) { } public void testEnded ( String host ) { } public void testStarted ( String host ) { } public void testEnded ( ) { } public void testStarted ( ) { } public void loadExistingFile ( ) { } private static void writeFileStart ( PrintWriter writer , SampleSaveConfiguration saveConfig ) { } private static void writeFileEnd ( PrintWriter pw , SampleSaveConfiguration saveConfig ) { } private static synchronized PrintWriter getFileWriter ( String filename , SampleSaveConfiguration saveConfig ) throws IOException { if ( ( filename == null ) || ( ( filename . length ( ) ) == 0 ) ) { return null ; } PrintWriter writer = ( ( PrintWriter ) ( ResultCollector . files . get ( filename ) ) ) ; boolean trimmed = true ; if ( writer == null ) { if ( saveConfig . saveAsXml ( ) ) { trimmed = ResultCollector . trimLastLine ( filename ) ; } else { trimmed = new File ( filename ) . exists ( ) ; } File pdir = new File ( filename ) . getParentFile ( ) ; if ( pdir != null ) pdir . mkdirs ( ) ; <START_BUG> writer = new PrintWriter ( new OutputStreamWriter ( new BufferedOutputStream ( new FileOutputStream ( filename , trimmed ) ) , "UTF-8" ) , true ) ; <END_BUG> ResultCollector . files . put ( filename , writer ) ; } if ( ! trimmed ) { ResultCollector . writeFileStart ( writer , saveConfig ) ; } return writer ; } private static boolean trimLastLine ( String filename ) { } private void readSamples ( TestResultWrapper testResults , Visualizer visualizer , boolean showAll ) throws Exception { } public void clearVisualizer ( ) { } public void sampleStarted ( SampleEvent e ) { } public void sampleStopped ( SampleEvent e ) { } public void sampleOccurred ( SampleEvent event ) { } protected final void sendToVisualizer ( SampleResult r ) { } private void recordResult ( SampleEvent event ) throws Exception { } public void recordStats ( TestElement e ) throws Exception { } private synchronized boolean isResultMarked ( SampleResult res ) { } private void initializeFileOutput ( ) throws IOException { } private synchronized void finalizeFileOutput ( ) { } public void testIterationStart ( LoopIterationEvent event ) { } public SampleSaveConfiguration getSaveConfig ( ) { } public void setSaveConfig ( SampleSaveConfiguration saveConfig ) { } public void clearData ( ) { } }

Fix:
writer = new PrintWriter ( new OutputStreamWriter ( new BufferedOutputStream ( new FileOutputStream ( filename , trimmed ) ) , SaveService . getFileEncoding ( "UTF-8" ) ) , true ) ;