Buggy code:
establishConnection ( ) ; titleValue = "mytitleœ+₡<seq2seq4repair_space>ĕ&yesÅ" ; descriptionValue = "mydescription<seq2seq4repair_space>œ<seq2seq4repair_space>₡<seq2seq4repair_space>ĕ<seq2seq4repair_space>Å" ; contentEncoding = PostWriterTest . UTF_8 ; sampler . setContentEncoding ( contentEncoding ) ; setupFormData ( sampler , titleValue , descriptionValue ) ; postWriter . setHeaders ( connection , sampler ) ; postWriter . sendPostData ( connection , sampler ) ; checkContentTypeUrlEncoded ( connection ) ; expectedString = ( ( "title=" + ( URLEncoder . encode ( titleValue , PostWriterTest . UTF_8 ) ) ) + "&description=" ) + ( URLEncoder . encode ( descriptionValue , PostWriterTest . UTF_8 ) ) ; expectedUrl = expectedString . getBytes ( "US-ASCII" ) ; checkContentLength ( connection , expectedUrl . length ) ; checkArraysHaveSameContent ( expectedUrl , connection . getOutputStreamContent ( ) ) ; assertEquals ( URLDecoder . decode ( new String ( expectedUrl , "US-ASCII" ) , contentEncoding ) , URLDecoder . decode ( new String ( connection . getOutputStreamContent ( ) , "US-ASCII" ) , contentEncoding ) ) ; unencodedString = ( ( "title=" + titleValue ) + "&description=" ) + descriptionValue ; unexpectedUrl = unencodedString . getBytes ( "US-ASCII" ) ; checkArraysHaveDifferentContent ( unexpectedUrl , connection . getOutputStreamContent ( ) ) ; connection . disconnect ( ) ; titleValue = "mytitle%20and%20space%2Ftest%C3%85" ; descriptionValue = "mydescription+and+plus+as+space%2Ftest%C3%85" ; setupFormData ( sampler , true , titleValue , descriptionValue ) ; establishConnection ( ) ; contentEncoding = "" ; sampler . setContentEncoding ( contentEncoding ) ; postWriter . setHeaders ( connection , sampler ) ; postWriter . sendPostData ( connection , sampler ) ; checkContentTypeUrlEncoded ( connection ) ; expectedUrl = new String ( ( ( ( "title=" + ( titleValue . replaceAll ( "%20" , "+" ) . replaceAll ( "%C3%85" , "%C5" ) ) ) + "&description=" ) + ( descriptionValue . replaceAll ( "%C3%85" , "%C5" ) ) ) ) . getBytes ( "US-ASCII" ) ; checkContentLength ( connection , expectedUrl . length ) ; checkArraysHaveSameContent ( expectedUrl , connection . getOutputStreamContent ( ) ) ; assertEquals ( URLDecoder . decode ( new String ( expectedUrl , "US-ASCII" ) , "ISO-8859-1" ) , URLDecoder . decode ( new String ( connection . getOutputStreamContent ( ) , "US-ASCII" ) , "ISO-8859-1" ) ) ; connection . disconnect ( ) ; establishConnection ( ) ; contentEncoding = "ISO-8859-1" ; sampler . setContentEncoding ( contentEncoding ) ; postWriter . setHeaders ( connection , sampler ) ; postWriter . sendPostData ( connection , sampler ) ; checkContentTypeUrlEncoded ( connection ) ; expectedUrl = new String ( ( ( ( "title=" + ( titleValue . replaceAll ( "%20" , "+" ) . replaceAll ( "%C3%85" , "%C5" ) ) ) + "&description=" ) + ( descriptionValue . replaceAll ( "%C3%85" , "%C5" ) ) ) ) . getBytes ( "US-ASCII" ) ; checkContentLength ( connection , expectedUrl . length ) ; checkArraysHaveSameContent ( expectedUrl , connection . getOutputStreamContent ( ) ) ; assertEquals ( URLDecoder . decode ( new String ( expectedUrl , "US-ASCII" ) , contentEncoding ) , URLDecoder . decode ( new String ( connection . getOutputStreamContent ( ) , "US-ASCII" ) , contentEncoding ) ) ; connection . disconnect ( ) ; establishConnection ( ) ; contentEncoding = PostWriterTest . UTF_8 ; sampler . setContentEncoding ( contentEncoding ) ; postWriter . setHeaders ( connection , sampler ) ; postWriter . sendPostData ( connection , sampler ) ; checkContentTypeUrlEncoded ( connection ) ; <START_BUG> expectedUrl = new String ( ( ( ( "title=" + ( titleValue . replaceAll ( "%20" , "+" ) ) ) + "&description=" ) + descriptionValue ) ) . getBytes ( "US-ASCII" ) ; <END_BUG> checkContentLength ( connection , expectedUrl . length ) ; checkArraysHaveSameContent ( expectedUrl , connection . getOutputStreamContent ( ) ) ; assertEquals ( URLDecoder . decode ( new String ( expectedUrl , "US-ASCII" ) , contentEncoding ) , URLDecoder . decode ( new String ( connection . getOutputStreamContent ( ) , "US-ASCII" ) , contentEncoding ) ) ; connection . disconnect ( ) ; } public void testSetHeaders ( ) throws IOException { } public void testSetHeaders_NoFilename ( ) throws IOException { } private void setupNoFilename ( HTTPSampler httpSampler ) { } private void setupFilepart ( HTTPSampler httpSampler ) { } private void setupFilepart ( HTTPSampler httpSampler , String fileField , File file , String mimeType ) { } private void setupFormData ( HTTPSampler httpSampler ) { } private void setupFormData ( HTTPSampler httpSampler , String titleValue , String descriptionValue ) { } private void setupFormData ( HTTPSampler httpSampler , boolean isEncoded , String titleValue , String descriptionValue ) { } private void establishConnection ( ) throws MalformedURLException { } private byte [ ] createExpectedOutput ( String boundaryString , String contentEncoding , String titleValue , String descriptionValue , byte [ ] fileContent ) throws IOException { } private byte [ ] createExpectedOutput ( String boundaryString , String contentEncoding , String titleField , String titleValue , String descriptionField , String descriptionValue , String fileField , byte [ ] fileContent ) throws IOException { } private byte [ ] createExpectedFormdataOutput ( String boundaryString , String contentEncoding , String titleField , String titleValue , String descriptionField , String descriptionValue , boolean firstMultipart , boolean lastMultipart ) throws IOException { } private byte [ ] createExpectedFilepartOutput ( String boundaryString , String fileField , File file , String mimeType , byte [ ] fileContent , boolean firstMultipart , boolean lastMultipart ) throws IOException { } private void checkArraysHaveSameContent ( byte [ ] expected , byte [ ] actual ) throws UnsupportedEncodingException { } private void checkArraysHaveDifferentContent ( byte [ ] expected , byte [ ] actual ) { } private void checkContentTypeMultipart ( HttpURLConnection conn , String boundaryString ) { } private void checkContentTypeUrlEncoded ( HttpURLConnection conn ) { } private void checkContentLength ( HttpURLConnection conn , int length ) { } private static class StubURLConnection extends HttpURLConnection { private ByteArrayOutputStream output = new ByteArrayOutputStream ( ) ; private Map < String , String > properties = new HashMap < String , String > ( ) ;

Fix:
expectedUrl = ( ( ( "title=" + ( titleValue . replaceAll ( "%20" , "+" ) ) ) + "&description=" ) + descriptionValue ) . getBytes ( "US-ASCII" ) ;