Buggy code:
int timeout = ctx . getRemoteConnectionSettings ( ) . getConnectionTimeout ( ) ; int connectionPoolSize = SystemPropertiesHelper . getInteger ( HttpClientProxyUtil . CONNECTION_POOL_SIZE_KEY , DEFAULT_MAX_TOTAL_CONNECTIONS ) ; httpClient . getHttpConnectionManager ( ) . getParams ( ) . setConnectionTimeout ( timeout ) ; httpClient . getHttpConnectionManager ( ) . getParams ( ) . setSoTimeout ( timeout ) ; httpClient . getHttpConnectionManager ( ) . getParams ( ) . setMaxTotalConnections ( connectionPoolSize ) ; httpClient . getHttpConnectionManager ( ) . getParams ( ) . setMaxConnectionsPerHost ( ANY_HOST_CONFIGURATION , connectionPoolSize ) ; HostConfiguration httpConfiguration = httpClient . getHostConfiguration ( ) ; RemoteAuthenticationSettings ras = ctx . getRemoteAuthenticationSettings ( ) ; boolean isSimpleAuthUsed = false ; boolean isNtlmUsed = false ; if ( ras != null ) { List < String > authPrefs = new ArrayList < String > ( 2 ) ; authPrefs . add ( DIGEST ) ; authPrefs . add ( BASIC ) ; if ( ras instanceof ClientSSLRemoteAuthenticationSettings ) { } else if ( ras instanceof NtlmRemoteAuthenticationSettings ) { NtlmRemoteAuthenticationSettings nras = ( ( NtlmRemoteAuthenticationSettings ) ( ras ) ) ; authPrefs . add ( 0 , NTLM ) ; HttpClientProxyUtil . logger ( logger ) . info ( "...<seq2seq4repair_space>authentication<seq2seq4repair_space>setup<seq2seq4repair_space>for<seq2seq4repair_space>NTLM<seq2seq4repair_space>domain<seq2seq4repair_space>'{}'" , nras . getNtlmDomain ( ) ) ; httpConfiguration . setHost ( nras . getNtlmHost ( ) ) ; httpClient . getState ( ) . setCredentials ( ANY , new org . apache . commons . httpclient . NTCredentials ( nras . getUsername ( ) , nras . getPassword ( ) , nras . getNtlmHost ( ) , nras . getNtlmDomain ( ) ) ) ; isNtlmUsed = true ; } else if ( ras instanceof UsernamePasswordRemoteAuthenticationSettings ) { UsernamePasswordRemoteAuthenticationSettings uras = ( ( UsernamePasswordRemoteAuthenticationSettings ) ( ras ) ) ; HttpClientProxyUtil . logger ( logger ) . info ( "...<seq2seq4repair_space>authentication<seq2seq4repair_space>setup<seq2seq4repair_space>for<seq2seq4repair_space>remote<seq2seq4repair_space>storage<seq2seq4repair_space>with<seq2seq4repair_space>username<seq2seq4repair_space>'{}'" , uras . getUsername ( ) ) ; httpClient . getState ( ) . setCredentials ( ANY , new org . apache . commons . httpclient . UsernamePasswordCredentials ( uras . getUsername ( ) , uras . getPassword ( ) ) ) ; isSimpleAuthUsed = true ; } httpClient . getParams ( ) . setParameter ( AUTH_SCHEME_PRIORITY , authPrefs ) ; } RemoteProxySettings rps = ctx . getRemoteProxySettings ( ) ; boolean isProxyUsed = false ; if ( rps . isEnabled ( ) ) { isProxyUsed = true ; HttpClientProxyUtil . logger ( logger ) . info ( "...<seq2seq4repair_space>proxy<seq2seq4repair_space>setup<seq2seq4repair_space>with<seq2seq4repair_space>host<seq2seq4repair_space>'{}'" , rps . getHostname ( ) ) ; httpConfiguration . setProxy ( rps . getHostname ( ) , rps . getPort ( ) ) ; if ( ( ( rps . getNonProxyHosts ( ) ) != null ) && ( ! ( rps . getNonProxyHosts ( ) . isEmpty ( ) ) ) ) { Set < Pattern > nonProxyHostPatterns = new HashSet < Pattern > ( rps . getNonProxyHosts ( ) . size ( ) ) ; for ( String nonProxyHostRegex : rps . getNonProxyHosts ( ) ) { try { nonProxyHostPatterns . add ( Pattern . compile ( nonProxyHostRegex , Pattern . CASE_INSENSITIVE ) ) ; } catch ( PatternSyntaxException e ) { HttpClientProxyUtil . logger ( logger ) . warn ( "Invalid<seq2seq4repair_space>non<seq2seq4repair_space>proxy<seq2seq4repair_space>host<seq2seq4repair_space>regex:<seq2seq4repair_space>{}" , nonProxyHostRegex , e ) ; } } httpConfiguration . getParams ( ) . setParameter ( NON_PROXY_HOSTS_PATTERNS_KEY , nonProxyHostPatterns ) ; } if ( ( rps . getProxyAuthentication ( ) ) != null ) { ras = rps . getProxyAuthentication ( ) ; List < String > authPrefs = new ArrayList < String > ( 2 ) ; authPrefs . add ( DIGEST ) ; authPrefs . add ( BASIC ) ; if ( ras instanceof ClientSSLRemoteAuthenticationSettings ) { } else if ( ras instanceof NtlmRemoteAuthenticationSettings ) { NtlmRemoteAuthenticationSettings nras = ( ( NtlmRemoteAuthenticationSettings ) ( ras ) ) ; authPrefs . add ( 0 , NTLM ) ; if ( ( ( ctx . getRemoteAuthenticationSettings ( ) ) != null ) && ( ( ctx . getRemoteAuthenticationSettings ( ) ) instanceof NtlmRemoteAuthenticationSettings ) ) { HttpClientProxyUtil . logger ( logger ) . warn ( ( "...<seq2seq4repair_space>Apache<seq2seq4repair_space>Commons<seq2seq4repair_space>HttpClient<seq2seq4repair_space>3.x<seq2seq4repair_space>is<seq2seq4repair_space>unable<seq2seq4repair_space>to<seq2seq4repair_space>use<seq2seq4repair_space>NTLM<seq2seq4repair_space>auth<seq2seq4repair_space>scheme\n" + ( ( ( "<seq2seq4repair_space>for<seq2seq4repair_space>BOTH<seq2seq4repair_space>server<seq2seq4repair_space>side<seq2seq4repair_space>and<seq2seq4repair_space>proxy<seq2seq4repair_space>side<seq2seq4repair_space>authentication!\n" + "<seq2seq4repair_space>You<seq2seq4repair_space>MUST<seq2seq4repair_space>reconfigure<seq2seq4repair_space>server<seq2seq4repair_space>side<seq2seq4repair_space>auth<seq2seq4repair_space>and<seq2seq4repair_space>use<seq2seq4repair_space>BASIC//DIGEST<seq2seq4repair_space>scheme\n" ) + "<seq2seq4repair_space>if<seq2seq4repair_space>you<seq2seq4repair_space>have<seq2seq4repair_space>to<seq2seq4repair_space>use<seq2seq4repair_space>NTLM<seq2seq4repair_space>proxy,<seq2seq4repair_space>otherwise<seq2seq4repair_space>it<seq2seq4repair_space>will<seq2seq4repair_space>not<seq2seq4repair_space>work!\n" ) + "<seq2seq4repair_space>***<seq2seq4repair_space>SERVER<seq2seq4repair_space>SIDE<seq2seq4repair_space>AUTH<seq2seq4repair_space>OVERRIDDEN" ) ) ) ; } HttpClientProxyUtil . logger ( logger ) . info ( "...<seq2seq4repair_space>proxy<seq2seq4repair_space>authentication<seq2seq4repair_space>setup<seq2seq4repair_space>for<seq2seq4repair_space>NTLM<seq2seq4repair_space>domain<seq2seq4repair_space>'{}'" , nras . getNtlmDomain ( ) ) ; httpConfiguration . setHost ( nras . getNtlmHost ( ) ) ; httpClient . getState ( ) . setProxyCredentials ( ANY , new org . apache . commons . httpclient . NTCredentials ( nras . getUsername ( ) , nras . getPassword ( ) , nras . getNtlmHost ( ) , nras . getNtlmDomain ( ) ) ) ; isNtlmUsed = true ; } else if ( ras instanceof UsernamePasswordRemoteAuthenticationSettings ) { UsernamePasswordRemoteAuthenticationSettings uras = ( ( UsernamePasswordRemoteAuthenticationSettings ) ( ras ) ) ; HttpClientProxyUtil . logger ( logger ) . info ( "...<seq2seq4repair_space>proxy<seq2seq4repair_space>authentication<seq2seq4repair_space>setup<seq2seq4repair_space>for<seq2seq4repair_space>remote<seq2seq4repair_space>storage<seq2seq4repair_space>with<seq2seq4repair_space>username<seq2seq4repair_space>'{}'" , uras . getUsername ( ) ) ; httpClient . getState ( ) . setProxyCredentials ( ANY , new org . apache . commons . httpclient . UsernamePasswordCredentials ( uras . getUsername ( ) , uras . getPassword ( ) ) ) ; } httpClient . getParams ( ) . setParameter ( AUTH_SCHEME_PRIORITY , authPrefs ) ; } } if ( isSimpleAuthUsed && ( ! isProxyUsed ) ) { HttpClientProxyUtil . logger ( logger ) . info ( ( "...<seq2seq4repair_space>simple<seq2seq4repair_space>scenario:<seq2seq4repair_space>simple<seq2seq4repair_space>authentication<seq2seq4repair_space>used<seq2seq4repair_space>with<seq2seq4repair_space>no<seq2seq4repair_space>proxy<seq2seq4repair_space>in<seq2seq4repair_space>between<seq2seq4repair_space>target<seq2seq4repair_space>and<seq2seq4repair_space>us," + "<seq2seq4repair_space>will<seq2seq4repair_space>use<seq2seq4repair_space>preemptive<seq2seq4repair_space>authentication" ) ) ; httpClient . getParams ( ) . setAuthenticationPreemptive ( true ) ; } final Boolean isNtlmUsedOldValue = ( ( Boolean ) ( ctx . getContextObject ( HttpClientProxyUtil . NTLM_IS_IN_USE_KEY ) ) ) ; <START_BUG> if ( ( isNtlmUsedOldValue == null ) || ( ( ! ( isNtlmUsedOldValue . booleanValue ( ) ) ) != isNtlmUsed ) ) { <END_BUG> if ( isNtlmUsed ) { ctx . putContextObject ( HttpClientProxyUtil . NTLM_IS_IN_USE_KEY , Boolean . TRUE ) ; } else { ctx . putContextObject ( HttpClientProxyUtil . NTLM_IS_IN_USE_KEY , Boolean . FALSE ) ; } } } private static Logger logger ( final Logger logger ) { } }

Fix:
if ( ( isNtlmUsedOldValue == null ) || ( ( isNtlmUsedOldValue . booleanValue ( ) ) != isNtlmUsed ) ) {