Buggy code:
public class ResultCollector extends AbstractListenerElement implements Serializable , NoThreadClone , Clearable , Remoteable , SampleListener , TestStateListener { private static final Logger log = LoggingManager . getLoggerForClass ( ) ; private static final long serialVersionUID = 233L ; 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 static final String SUCCESS_ONLY_LOGGING = "ResultCollector.success_only_logging" ; private static final Object LOCK = new Object ( ) ; private static final Map < String , ResultCollector . FileEntry > files = new HashMap < String , ResultCollector . FileEntry > ( ) ; private static class FileEntry { final PrintWriter pw ; final SampleSaveConfiguration config ; FileEntry ( PrintWriter _pw , SampleSaveConfiguration _config ) { } } private static int instanceCount ; private volatile transient PrintWriter out ; private volatile boolean inTest = false ; private volatile boolean isStats = false ; private volatile Summariser summariser ; public ResultCollector ( ) { } public ResultCollector ( Summariser summer ) { } @ Override public Object clone ( ) { } private void setFilenameProperty ( String f ) { } public String getFilename ( ) { } public boolean isErrorLogging ( ) { } public final void setErrorLogging ( boolean errorLogging ) { } public final void setSuccessOnlyLogging ( boolean value ) { } public boolean isSuccessOnlyLogging ( ) { } public boolean isSampleWanted ( boolean success ) { } public static boolean isSampleWanted ( boolean success , boolean errorOnly , boolean successOnly ) { } public void setFilename ( String f ) { } @ Override public void testEnded ( String host ) { } @ Override public void testStarted ( String host ) { } @ Override public void testEnded ( ) { } @ Override public void testStarted ( ) { } public void loadExistingFile ( ) { } private static void writeFileStart ( PrintWriter writer , SampleSaveConfiguration saveConfig ) { } private static void writeFileEnd ( PrintWriter pw , SampleSaveConfiguration saveConfig ) { } private static PrintWriter getFileWriter ( String filename , SampleSaveConfiguration saveConfig ) throws IOException { if ( ( filename == null ) || ( ( filename . length ( ) ) == 0 ) ) { return null ; } filename = FileServer . resolveBaseRelativeName ( filename ) ; ResultCollector . FileEntry fe = ResultCollector . files . get ( filename ) ; PrintWriter writer = null ; boolean trimmed = true ; if ( fe == null ) { if ( saveConfig . saveAsXml ( ) ) { trimmed = ResultCollector . trimLastLine ( filename ) ; } else { trimmed = new File ( filename ) . exists ( ) ; } File pdir = new File ( filename ) . getParentFile ( ) ; if ( pdir != null ) { if ( pdir . mkdirs ( ) ) { ResultCollector . log . info ( ( ( "Folder<seq2seq4repair_space>" + ( pdir . getAbsolutePath ( ) ) ) + "<seq2seq4repair_space>was<seq2seq4repair_space>created" ) ) ; } if ( ! ( pdir . exists ( ) ) ) { ResultCollector . log . warn ( ( "Error<seq2seq4repair_space>creating<seq2seq4repair_space>directories<seq2seq4repair_space>for<seq2seq4repair_space>" + ( pdir . toString ( ) ) ) ) ; } } <START_BUG> writer = new PrintWriter ( new OutputStreamWriter ( new BufferedOutputStream ( new FileOutputStream ( filename , trimmed ) ) , SaveService . getFileEncoding ( "UTF-8" ) ) , true ) ; <END_BUG> ResultCollector . log . debug ( ( "Opened<seq2seq4repair_space>file:<seq2seq4repair_space>" + filename ) ) ; ResultCollector . files . put ( filename , new ResultCollector . FileEntry ( writer , saveConfig ) ) ; } else { writer = fe . pw ; } if ( ! trimmed ) { ResultCollector . writeFileStart ( writer , saveConfig ) ; } return writer ; } private static boolean trimLastLine ( String filename ) { } @ Override public void sampleStarted ( SampleEvent e ) { } @ Override public void sampleStopped ( SampleEvent e ) { } @ Override public void sampleOccurred ( SampleEvent event ) { } protected final void sendToVisualizer ( SampleResult r ) { } public void recordStats ( TestElement e ) throws Exception { } private boolean isResultMarked ( SampleResult res ) { } private void initializeFileOutput ( ) throws IOException { } private void finalizeFileOutput ( ) { } public SampleSaveConfiguration getSaveConfig ( ) { } public void setSaveConfig ( SampleSaveConfiguration saveConfig ) { } @ Override public void clearData ( ) { } }

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