Buggy code:
public class UploadRunnable implements Runnable { private static final String BOUNDARY = "----0x6d6356418a05040fL" ; private static final String TD = "--" ; private static final String DCRLF = HttpProtocolConstants . HTTP_HEADER_DOUBLE_CRLF ; private static final String CRLF = HttpProtocolConstants . HTTP_HEADER_SINGLE_CRLF ; private String _url ; private Hashtable _params ; private String _fileKey ; private String _filePath ; private String _mimeType ; private Hashtable _headers ; private ScriptableFunction _success ; private ScriptableFunction _error ; private ConnectionFactory _factory ; private int [ ] _transports = new int [ ] { TransportInfo . TRANSPORT_TCP_WIFI , TransportInfo . TRANSPORT_BIS_B , TransportInfo . TRANSPORT_MDS , TransportInfo . TRANSPORT_TCP_CELLULAR , TransportInfo . TRANSPORT_WAP2 , TransportInfo . TRANSPORT_WAP } ; public UploadRunnable ( String url , String fileKey , Hashtable params , String filePath , String mimeType , long timeout , Hashtable headers , int [ ] transports , ScriptableFunction success , ScriptableFunction error ) { } public void run ( ) { FileConnection fc = null ; HttpConnection hc = null ; InputStream is = null ; OutputStream os = null ; boolean isHTTPS = false ; try { try { fc = ( ( FileConnection ) ( Connector . open ( _filePath , READ ) ) ) ; } catch ( Exception e ) { Logger . error ( "Invalid<seq2seq4repair_space>file<seq2seq4repair_space>path" ) ; callErrorCallback ( new String [ ] { "Invalid<seq2seq4repair_space>file<seq2seq4repair_space>path" } ) ; return ; } Logger . log ( "Setting<seq2seq4repair_space>mime<seq2seq4repair_space>type..." ) ; if ( ( _mimeType ) == null ) { _mimeType = MIMETypeAssociations . getMIMEType ( _filePath ) ; if ( ( _mimeType ) == null ) { _mimeType = HttpProtocolConstants . CONTENT_TYPE_IMAGE_JPEG ; } } if ( ! ( fc . exists ( ) ) ) { Logger . error ( "File<seq2seq4repair_space>not<seq2seq4repair_space>found" ) ; callErrorCallback ( new String [ ] { ( _filePath ) + "<seq2seq4repair_space>not<seq2seq4repair_space>found" } ) ; } <START_BUG> if ( ( _url . indexOf ( "https" ) ) != ( - 1 ) ) { <END_BUG> isHTTPS = true ; Logger . error ( "Setting<seq2seq4repair_space>End<seq2seq4repair_space>to<seq2seq4repair_space>End" ) ; _factory . setEndToEndDesired ( isHTTPS ) ; } ConnectionDescriptor connDesc = _factory . getConnection ( _url ) ; if ( connDesc != null ) { Logger . info ( ( "URL:<seq2seq4repair_space>" + ( connDesc . getUrl ( ) ) ) ) ; try { if ( isHTTPS ) { hc = ( ( HttpsConnection ) ( connDesc . getConnection ( ) ) ) ; } else { hc = ( ( HttpConnection ) ( connDesc . getConnection ( ) ) ) ; } String startBoundary = getStartBoundary ( _fileKey , fc . getName ( ) , _mimeType ) ; String endBoundary = getEndBoundary ( ) ; String params = ( ( _params ) != null ) ? getParameters ( _params ) : "" ; long fileSize = fc . fileSize ( ) ; long contentLength = ( ( fileSize + ( ( long ) ( startBoundary . length ( ) ) ) ) + ( ( long ) ( endBoundary . length ( ) ) ) ) + ( ( long ) ( params . length ( ) ) ) ; hc . setRequestMethod ( POST ) ; if ( ( _headers ) != null ) { String hKey ; String hVal ; for ( Enumeration e = _headers . keys ( ) ; e . hasMoreElements ( ) ; ) { hKey = e . nextElement ( ) . toString ( ) ; hVal = ( ( String ) ( _headers . get ( hKey ) ) ) ; Logger . error ( ( ( hKey + ":<seq2seq4repair_space>" ) + hVal ) ) ; hc . setRequestProperty ( hKey , hVal ) ; } } hc . setRequestProperty ( HEADER_USER_AGENT , System . getProperty ( "browser.useragent" ) ) ; hc . setRequestProperty ( HEADER_KEEP_ALIVE , "300" ) ; hc . setRequestProperty ( HEADER_CONNECTION , "keep-alive" ) ; hc . setRequestProperty ( HEADER_CONTENT_TYPE , ( ( ( HttpProtocolConstants . CONTENT_TYPE_MULTIPART_FORM_DATA ) + ";<seq2seq4repair_space>boundary=" ) + ( UploadRunnable . BOUNDARY ) ) ) ; hc . setRequestProperty ( HEADER_CONTENT_LENGTH , Long . toString ( contentLength ) ) ; os = hc . openDataOutputStream ( ) ; os . write ( params . getBytes ( ) ) ; os . write ( startBoundary . getBytes ( ) ) ; is = fc . openInputStream ( ) ; byte [ ] data = IOUtilities . streamToBytes ( is ) ; os . write ( data ) ; is . close ( ) ; os . write ( endBoundary . getBytes ( ) ) ; os . flush ( ) ; os . close ( ) ; is = hc . openDataInputStream ( ) ; int responseCode = hc . getResponseCode ( ) ; if ( responseCode != ( HttpConnection . HTTP_OK ) ) { Logger . error ( ( "Response<seq2seq4repair_space>code:<seq2seq4repair_space>" + responseCode ) ) ; callErrorCallback ( new Object [ ] { "Server<seq2seq4repair_space>Error" , new Integer ( responseCode ) } ) ; } else { callSuccessCallback ( new Object [ ] { new String ( IOUtilities . streamToBytes ( is ) ) } ) ; } } catch ( Throwable e ) { callErrorCallback ( new String [ ] { e . getMessage ( ) } ) ; e . printStackTrace ( ) ; } } else { Logger . error ( "Error<seq2seq4repair_space>creating<seq2seq4repair_space>HTTP<seq2seq4repair_space>connection" ) ; callErrorCallback ( new String [ ] { "Error<seq2seq4repair_space>creating<seq2seq4repair_space>HTTP<seq2seq4repair_space>connection." } ) ; } } finally { try { if ( fc != null ) fc . close ( ) ; if ( os != null ) os . close ( ) ; if ( is != null ) is . close ( ) ; if ( hc != null ) hc . close ( ) ; } catch ( Exception e ) { } } } protected String getStartBoundary ( String fileKey , String fileName , String mimeType ) { } protected String getEndBoundary ( ) { } protected String getParameters ( Hashtable params ) { }

Fix:
if ( ( _url . indexOf ( "https" ) ) == 0 ) {