Return-Path: X-Original-To: apmail-hc-commits-archive@www.apache.org Delivered-To: apmail-hc-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 75AD310261 for ; Mon, 24 Feb 2014 19:54:30 +0000 (UTC) Received: (qmail 49389 invoked by uid 500); 24 Feb 2014 19:54:29 -0000 Delivered-To: apmail-hc-commits-archive@hc.apache.org Received: (qmail 49345 invoked by uid 500); 24 Feb 2014 19:54:29 -0000 Mailing-List: contact commits-help@hc.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: "HttpComponents Project" Delivered-To: mailing list commits@hc.apache.org Received: (qmail 49338 invoked by uid 99); 24 Feb 2014 19:54:29 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 24 Feb 2014 19:54:29 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=5.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 24 Feb 2014 19:54:24 +0000 Received: from eris.apache.org (localhost [127.0.0.1]) by eris.apache.org (Postfix) with ESMTP id 620DD238883D for ; Mon, 24 Feb 2014 19:54:02 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r1571416 - in /httpcomponents/httpclient/trunk: httpclient-cache/src/main/java/org/apache/http/impl/client/cache/CachingHttpClientBuilder.java httpclient/src/main/java/org/apache/http/impl/client/HttpClientBuilder.java Date: Mon, 24 Feb 2014 19:54:02 -0000 To: commits@hc.apache.org From: sebb@apache.org X-Mailer: svnmailer-1.0.9 Message-Id: <20140224195402.620DD238883D@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: sebb Date: Mon Feb 24 19:54:01 2014 New Revision: 1571416 URL: http://svn.apache.org/r1571416 Log: Rename or inline local variables to avoid variable hiding Modified: httpcomponents/httpclient/trunk/httpclient-cache/src/main/java/org/apache/http/impl/client/cache/CachingHttpClientBuilder.java httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/client/HttpClientBuilder.java Modified: httpcomponents/httpclient/trunk/httpclient-cache/src/main/java/org/apache/http/impl/client/cache/CachingHttpClientBuilder.java URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient-cache/src/main/java/org/apache/http/impl/client/cache/CachingHttpClientBuilder.java?rev=1571416&r1=1571415&r2=1571416&view=diff ============================================================================== --- httpcomponents/httpclient/trunk/httpclient-cache/src/main/java/org/apache/http/impl/client/cache/CachingHttpClientBuilder.java (original) +++ httpcomponents/httpclient/trunk/httpclient-cache/src/main/java/org/apache/http/impl/client/cache/CachingHttpClientBuilder.java Mon Feb 24 19:54:01 2014 @@ -105,18 +105,19 @@ public class CachingHttpClientBuilder ex @Override protected ClientExecChain decorateMainExec(final ClientExecChain mainExec) { final CacheConfig config = this.cacheConfig != null ? this.cacheConfig : CacheConfig.DEFAULT; - ResourceFactory resourceFactory = this.resourceFactory; - if (resourceFactory == null) { + // We copy the instance fields to avoid changing them, and rename to avoid accidental use of the wrong version + ResourceFactory resourceFactoryCopy = this.resourceFactory; + if (resourceFactoryCopy == null) { if (this.cacheDir == null) { - resourceFactory = new HeapResourceFactory(); + resourceFactoryCopy = new HeapResourceFactory(); } else { - resourceFactory = new FileResourceFactory(cacheDir); + resourceFactoryCopy = new FileResourceFactory(cacheDir); } } - HttpCacheStorage storage = this.storage; - if (storage == null) { + HttpCacheStorage storageCopy = this.storage; + if (storageCopy == null) { if (this.cacheDir == null) { - storage = new BasicHttpCacheStorage(config); + storageCopy = new BasicHttpCacheStorage(config); } else { final ManagedHttpCacheStorage managedStorage = new ManagedHttpCacheStorage(config); if (this.deleteCache) { @@ -131,7 +132,7 @@ public class CachingHttpClientBuilder ex } else { addCloseable(managedStorage); } - storage = managedStorage; + storageCopy = managedStorage; } } final AsynchronousValidator revalidator = createAsynchronousRevalidator(config); @@ -139,13 +140,13 @@ public class CachingHttpClientBuilder ex HttpCacheInvalidator cacheInvalidator = this.httpCacheInvalidator; if (cacheInvalidator == null) { - cacheInvalidator = new CacheInvalidator(uriExtractor, storage); + cacheInvalidator = new CacheInvalidator(uriExtractor, storageCopy); } return new CachingExec(mainExec, new BasicHttpCache( - resourceFactory, - storage, config, + resourceFactoryCopy, + storageCopy, config, uriExtractor, cacheInvalidator), config, revalidator); } Modified: httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/client/HttpClientBuilder.java URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/client/HttpClientBuilder.java?rev=1571416&r1=1571415&r2=1571416&view=diff ============================================================================== --- httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/client/HttpClientBuilder.java (original) +++ httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/client/HttpClientBuilder.java Mon Feb 24 19:54:01 2014 @@ -691,34 +691,35 @@ public class HttpClientBuilder { public CloseableHttpClient build() { // Create main request executor - HttpRequestExecutor requestExec = this.requestExec; - if (requestExec == null) { - requestExec = new HttpRequestExecutor(); - } - HttpClientConnectionManager connManager = this.connManager; - if (connManager == null) { - LayeredConnectionSocketFactory sslSocketFactory = this.sslSocketFactory; - if (sslSocketFactory == null) { + // We copy the instance fields to avoid changing them, and rename to avoid accidental use of the wrong version + HttpRequestExecutor requestExecCopy = this.requestExec; + if (requestExecCopy == null) { + requestExecCopy = new HttpRequestExecutor(); + } + HttpClientConnectionManager connManagerCopy = this.connManager; + if (connManagerCopy == null) { + LayeredConnectionSocketFactory sslSocketFactoryCopy = this.sslSocketFactory; + if (sslSocketFactoryCopy == null) { final String[] supportedProtocols = systemProperties ? split( System.getProperty("https.protocols")) : null; final String[] supportedCipherSuites = systemProperties ? split( System.getProperty("https.cipherSuites")) : null; - X509HostnameVerifier hostnameVerifier = this.hostnameVerifier; - if (hostnameVerifier == null) { - hostnameVerifier = SSLConnectionSocketFactory.BROWSER_COMPATIBLE_HOSTNAME_VERIFIER; + X509HostnameVerifier hostnameVerifierCopy = this.hostnameVerifier; + if (hostnameVerifierCopy == null) { + hostnameVerifierCopy = SSLConnectionSocketFactory.BROWSER_COMPATIBLE_HOSTNAME_VERIFIER; } if (sslcontext != null) { - sslSocketFactory = new SSLConnectionSocketFactory( - sslcontext, supportedProtocols, supportedCipherSuites, hostnameVerifier); + sslSocketFactoryCopy = new SSLConnectionSocketFactory( + sslcontext, supportedProtocols, supportedCipherSuites, hostnameVerifierCopy); } else { if (systemProperties) { - sslSocketFactory = new SSLConnectionSocketFactory( + sslSocketFactoryCopy = new SSLConnectionSocketFactory( (SSLSocketFactory) SSLSocketFactory.getDefault(), - supportedProtocols, supportedCipherSuites, hostnameVerifier); + supportedProtocols, supportedCipherSuites, hostnameVerifierCopy); } else { - sslSocketFactory = new SSLConnectionSocketFactory( + sslSocketFactoryCopy = new SSLConnectionSocketFactory( SSLContexts.createDefault(), - hostnameVerifier); + hostnameVerifierCopy); } } } @@ -726,7 +727,7 @@ public class HttpClientBuilder { final PoolingHttpClientConnectionManager poolingmgr = new PoolingHttpClientConnectionManager( RegistryBuilder.create() .register("http", PlainConnectionSocketFactory.getSocketFactory()) - .register("https", sslSocketFactory) + .register("https", sslSocketFactoryCopy) .build()); if (defaultSocketConfig != null) { poolingmgr.setDefaultSocketConfig(defaultSocketConfig); @@ -749,62 +750,62 @@ public class HttpClientBuilder { if (maxConnPerRoute > 0) { poolingmgr.setDefaultMaxPerRoute(maxConnPerRoute); } - connManager = poolingmgr; + connManagerCopy = poolingmgr; } - ConnectionReuseStrategy reuseStrategy = this.reuseStrategy; - if (reuseStrategy == null) { + ConnectionReuseStrategy reuseStrategyCopy = this.reuseStrategy; + if (reuseStrategyCopy == null) { if (systemProperties) { final String s = System.getProperty("http.keepAlive", "true"); if ("true".equalsIgnoreCase(s)) { - reuseStrategy = DefaultConnectionReuseStrategy.INSTANCE; + reuseStrategyCopy = DefaultConnectionReuseStrategy.INSTANCE; } else { - reuseStrategy = NoConnectionReuseStrategy.INSTANCE; + reuseStrategyCopy = NoConnectionReuseStrategy.INSTANCE; } } else { - reuseStrategy = DefaultConnectionReuseStrategy.INSTANCE; + reuseStrategyCopy = DefaultConnectionReuseStrategy.INSTANCE; } } - ConnectionKeepAliveStrategy keepAliveStrategy = this.keepAliveStrategy; - if (keepAliveStrategy == null) { - keepAliveStrategy = DefaultConnectionKeepAliveStrategy.INSTANCE; + ConnectionKeepAliveStrategy keepAliveStrategyCopy = this.keepAliveStrategy; + if (keepAliveStrategyCopy == null) { + keepAliveStrategyCopy = DefaultConnectionKeepAliveStrategy.INSTANCE; } - AuthenticationStrategy targetAuthStrategy = this.targetAuthStrategy; - if (targetAuthStrategy == null) { - targetAuthStrategy = TargetAuthenticationStrategy.INSTANCE; + AuthenticationStrategy targetAuthStrategyCopy = this.targetAuthStrategy; + if (targetAuthStrategyCopy == null) { + targetAuthStrategyCopy = TargetAuthenticationStrategy.INSTANCE; } - AuthenticationStrategy proxyAuthStrategy = this.proxyAuthStrategy; - if (proxyAuthStrategy == null) { - proxyAuthStrategy = ProxyAuthenticationStrategy.INSTANCE; + AuthenticationStrategy proxyAuthStrategyCopy = this.proxyAuthStrategy; + if (proxyAuthStrategyCopy == null) { + proxyAuthStrategyCopy = ProxyAuthenticationStrategy.INSTANCE; } - UserTokenHandler userTokenHandler = this.userTokenHandler; - if (userTokenHandler == null) { + UserTokenHandler userTokenHandlerCopy = this.userTokenHandler; + if (userTokenHandlerCopy == null) { if (!connectionStateDisabled) { - userTokenHandler = DefaultUserTokenHandler.INSTANCE; + userTokenHandlerCopy = DefaultUserTokenHandler.INSTANCE; } else { - userTokenHandler = NoopUserTokenHandler.INSTANCE; + userTokenHandlerCopy = NoopUserTokenHandler.INSTANCE; } } ClientExecChain execChain = new MainClientExec( - requestExec, - connManager, - reuseStrategy, - keepAliveStrategy, - targetAuthStrategy, - proxyAuthStrategy, - userTokenHandler); + requestExecCopy, + connManagerCopy, + reuseStrategyCopy, + keepAliveStrategyCopy, + targetAuthStrategyCopy, + proxyAuthStrategyCopy, + userTokenHandlerCopy); execChain = decorateMainExec(execChain); - HttpProcessor httpprocessor = this.httpprocessor; - if (httpprocessor == null) { + HttpProcessor httpprocessorCopy = this.httpprocessor; + if (httpprocessorCopy == null) { - String userAgent = this.userAgent; - if (userAgent == null) { + String userAgentCopy = this.userAgent; + if (userAgentCopy == null) { if (systemProperties) { - userAgent = System.getProperty("http.agent"); + userAgentCopy = System.getProperty("http.agent"); } - if (userAgent == null) { - userAgent = DEFAULT_USER_AGENT; + if (userAgentCopy == null) { + userAgentCopy = DEFAULT_USER_AGENT; } } @@ -824,7 +825,7 @@ public class HttpClientBuilder { new RequestContent(), new RequestTargetHost(), new RequestClientConnControl(), - new RequestUserAgent(userAgent), + new RequestUserAgent(userAgentCopy), new RequestExpectContinue()); if (!cookieManagementDisabled) { b.add(new RequestAddCookies()); @@ -851,60 +852,58 @@ public class HttpClientBuilder { b.addLast(i); } } - httpprocessor = b.build(); + httpprocessorCopy = b.build(); } - execChain = new ProtocolExec(execChain, httpprocessor); + execChain = new ProtocolExec(execChain, httpprocessorCopy); execChain = decorateProtocolExec(execChain); // Add request retry executor, if not disabled if (!automaticRetriesDisabled) { - HttpRequestRetryHandler retryHandler = this.retryHandler; - if (retryHandler == null) { - retryHandler = DefaultHttpRequestRetryHandler.INSTANCE; - } - execChain = new RetryExec(execChain, retryHandler); + HttpRequestRetryHandler retryHandlerCopy = this.retryHandler; + if (retryHandlerCopy == null) { + retryHandlerCopy = DefaultHttpRequestRetryHandler.INSTANCE; + } + execChain = new RetryExec(execChain, retryHandlerCopy); } - HttpRoutePlanner routePlanner = this.routePlanner; - if (routePlanner == null) { - SchemePortResolver schemePortResolver = this.schemePortResolver; - if (schemePortResolver == null) { - schemePortResolver = DefaultSchemePortResolver.INSTANCE; + HttpRoutePlanner routePlannerCopy = this.routePlanner; + if (routePlannerCopy == null) { + SchemePortResolver schemePortResolverCopy = this.schemePortResolver; + if (schemePortResolverCopy == null) { + schemePortResolverCopy = DefaultSchemePortResolver.INSTANCE; } if (proxy != null) { - routePlanner = new DefaultProxyRoutePlanner(proxy, schemePortResolver); + routePlannerCopy = new DefaultProxyRoutePlanner(proxy, schemePortResolverCopy); } else if (systemProperties) { - routePlanner = new SystemDefaultRoutePlanner( - schemePortResolver, ProxySelector.getDefault()); + routePlannerCopy = new SystemDefaultRoutePlanner( + schemePortResolverCopy, ProxySelector.getDefault()); } else { - routePlanner = new DefaultRoutePlanner(schemePortResolver); + routePlannerCopy = new DefaultRoutePlanner(schemePortResolverCopy); } } // Add redirect executor, if not disabled if (!redirectHandlingDisabled) { - RedirectStrategy redirectStrategy = this.redirectStrategy; - if (redirectStrategy == null) { - redirectStrategy = DefaultRedirectStrategy.INSTANCE; + RedirectStrategy redirectStrategyCopy = this.redirectStrategy; + if (redirectStrategyCopy == null) { + redirectStrategyCopy = DefaultRedirectStrategy.INSTANCE; } - execChain = new RedirectExec(execChain, routePlanner, redirectStrategy); + execChain = new RedirectExec(execChain, routePlannerCopy, redirectStrategyCopy); } // Optionally, add service unavailable retry executor - final ServiceUnavailableRetryStrategy serviceUnavailStrategy = this.serviceUnavailStrategy; - if (serviceUnavailStrategy != null) { - execChain = new ServiceUnavailableRetryExec(execChain, serviceUnavailStrategy); + final ServiceUnavailableRetryStrategy serviceUnavailStrategyCopy = this.serviceUnavailStrategy; + if (serviceUnavailStrategyCopy != null) { + execChain = new ServiceUnavailableRetryExec(execChain, serviceUnavailStrategyCopy); } // Optionally, add connection back-off executor - final BackoffManager backoffManager = this.backoffManager; - final ConnectionBackoffStrategy connectionBackoffStrategy = this.connectionBackoffStrategy; - if (backoffManager != null && connectionBackoffStrategy != null) { - execChain = new BackoffStrategyExec(execChain, connectionBackoffStrategy, backoffManager); + if (this.backoffManager != null && this.connectionBackoffStrategy != null) { + execChain = new BackoffStrategyExec(execChain, this.connectionBackoffStrategy, this.backoffManager); } - Lookup authSchemeRegistry = this.authSchemeRegistry; - if (authSchemeRegistry == null) { - authSchemeRegistry = RegistryBuilder.create() + Lookup authSchemeRegistryCopy = this.authSchemeRegistry; + if (authSchemeRegistryCopy == null) { + authSchemeRegistryCopy = RegistryBuilder.create() .register(AuthSchemes.BASIC, new BasicSchemeFactory()) .register(AuthSchemes.DIGEST, new DigestSchemeFactory()) .register(AuthSchemes.NTLM, new NTLMSchemeFactory()) @@ -912,9 +911,9 @@ public class HttpClientBuilder { .register(AuthSchemes.KERBEROS, new KerberosSchemeFactory()) .build(); } - Lookup cookieSpecRegistry = this.cookieSpecRegistry; - if (cookieSpecRegistry == null) { - cookieSpecRegistry = RegistryBuilder.create() + Lookup cookieSpecRegistryCopy = this.cookieSpecRegistry; + if (cookieSpecRegistryCopy == null) { + cookieSpecRegistryCopy = RegistryBuilder.create() .register(CookieSpecs.BEST_MATCH, new BestMatchSpecFactory()) .register(CookieSpecs.STANDARD, new RFC2965SpecFactory()) .register(CookieSpecs.BROWSER_COMPATIBILITY, new BrowserCompatSpecFactory()) @@ -941,10 +940,10 @@ public class HttpClientBuilder { return new InternalHttpClient( execChain, - connManager, - routePlanner, - cookieSpecRegistry, - authSchemeRegistry, + connManagerCopy, + routePlannerCopy, + cookieSpecRegistryCopy, + authSchemeRegistryCopy, defaultCookieStore, defaultCredentialsProvider, defaultRequestConfig != null ? defaultRequestConfig : RequestConfig.DEFAULT,