You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@hc.apache.org by "Francois-Xavier Bonnet (JIRA)" <ji...@apache.org> on 2012/12/14 12:40:13 UTC
[jira] [Reopened] (HTTPCLIENT-1276) NullPointerException when 304
response updates a cache entry
[ https://issues.apache.org/jira/browse/HTTPCLIENT-1276?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]
Francois-Xavier Bonnet reopened HTTPCLIENT-1276:
------------------------------------------------
I found another case I hadn't tested before: when the response contains a Vary header.
The problem occurs in org.apache.http.impl.client.cache.BasicHttpCache.doGetUpdatedParentEntry(String, HttpCacheEntry, HttpCacheEntry, String, String)
java.lang.NullPointerException
at org.apache.http.impl.client.cache.HeapResourceFactory.copy(HeapResourceFactory.java:73)
at org.apache.http.impl.client.cache.BasicHttpCache.doGetUpdatedParentEntry(BasicHttpCache.java:199)
at org.apache.http.impl.client.cache.BasicHttpCache$1.update(BasicHttpCache.java:119)
at org.apache.http.impl.client.cache.BasicHttpCacheStorage.updateEntry(BasicHttpCacheStorage.java:94)
at org.apache.http.impl.client.cache.BasicHttpCache.storeVariantEntry(BasicHttpCache.java:128)
at org.apache.http.impl.client.cache.BasicHttpCache.storeInCache(BasicHttpCache.java:96)
at org.apache.http.impl.client.cache.BasicHttpCache.cacheAndReturnResponse(BasicHttpCache.java:260)
at org.apache.http.impl.client.cache.CachingExec.handleBackendResponse(CachingExec.java:803)
at org.apache.http.impl.client.cache.CachingExec.callBackend(CachingExec.java:571)
at org.apache.http.impl.client.cache.CachingExec.handleCacheMiss(CachingExec.java:345)
at org.apache.http.impl.client.cache.CachingExec.execute(CachingExec.java:264)
at org.apache.http.impl.client.cache.CachingExec.execute(CachingExec.java:219)
at org.apache.http.impl.client.cache.TestCachingExec.testNotModifiedResponseWithVaryUpdatesCacheEntryWhenNoEntity(TestCachingExec.java:1624)
> NullPointerException when 304 response updates a cache entry
> ------------------------------------------------------------
>
> Key: HTTPCLIENT-1276
> URL: https://issues.apache.org/jira/browse/HTTPCLIENT-1276
> Project: HttpComponents HttpClient
> Issue Type: Bug
> Components: Cache
> Affects Versions: 4.2.2, Snapshot
> Reporter: Francois-Xavier Bonnet
> Priority: Blocker
> Fix For: 4.2.3
>
> Attachments: HTTPCLIENT-1274_HTTPCLIENT-1276.txt
>
>
> When sending a conditional request and the cache entry does not have an entity, CachingHttpClient throws a NullPointerException.
> To reproduce :
> - send a first conditional If-None-Match request and receive a first 304 that generates a cache entry with no entity
> - send a second conditional request and receive another 304
> When updating the cache entry, CachingHttpClient tries to copy the entity of the existing cache entry without testing if it is null.
> Here is a test to reproduce :
> @Test
> public void testNotModifiedResponseUpdatesCacheEntryWhenNoEntity()
> throws Exception {
> Date now = new Date();
> impl = new CachingExec(mockBackend, new BasicHttpCache(),CacheConfig.DEFAULT);
> HttpRequestWrapper req1 = HttpRequestWrapper.wrap(new HttpGet("http://foo.example.com/"));
> req1.addHeader("If-None-Match", "etag");
> HttpRequestWrapper req2 = HttpRequestWrapper.wrap(new HttpGet("http://foo.example.com/"));
> req2.addHeader("If-None-Match", "etag");
> HttpResponse resp1 = new BasicHttpResponse(HttpVersion.HTTP_1_1, HttpStatus.SC_NOT_MODIFIED, "Not modified");
> resp1.setHeader("Date", DateUtils.formatDate(now));
> resp1.setHeader("Cache-Control","max-age=0");
> resp1.setHeader("Etag", "etag");
> HttpResponse resp2 = new BasicHttpResponse(HttpVersion.HTTP_1_1, HttpStatus.SC_NOT_MODIFIED, "Not modified");
> resp2.setHeader("Date", DateUtils.formatDate(now));
> resp2.setHeader("Cache-Control","max-age=0");
> resp1.setHeader("Etag", "etag");
> backendExpectsAnyRequestAndReturn(resp1);
> backendExpectsAnyRequestAndReturn(resp2);
> replayMocks();
> HttpResponse result1 = impl.execute(route, req1);
> HttpResponse result2 = impl.execute(route, req2);
> verifyMocks();
> assertEquals(HttpStatus.SC_NOT_MODIFIED, result1.getStatusLine().getStatusCode());
> assertEquals("etag", result1.getFirstHeader("Etag").getValue());
> assertEquals(HttpStatus.SC_NOT_MODIFIED, result2.getStatusLine().getStatusCode());
> assertEquals("etag", result2.getFirstHeader("Etag").getValue());
> }
> And here is what you get:
> java.lang.NullPointerException
> at org.apache.http.impl.client.cache.HeapResourceFactory.copy(HeapResourceFactory.java:73)
> at org.apache.http.impl.client.cache.CacheEntryUpdater.updateCacheEntry(CacheEntryUpdater.java:90)
> at org.apache.http.impl.client.cache.BasicHttpCache.updateCacheEntry(BasicHttpCache.java:214)
> at org.apache.http.impl.client.cache.CachingExec.revalidateCacheEntry(CachingExec.java:752)
> at org.apache.http.impl.client.cache.CachingExec.revalidateCacheEntry(CachingExec.java:318)
> at org.apache.http.impl.client.cache.CachingExec.handleCacheHit(CachingExec.java:288)
> at org.apache.http.impl.client.cache.CachingExec.execute(CachingExec.java:266)
> at org.apache.http.impl.client.cache.CachingExec.execute(CachingExec.java:219)
> at org.apache.http.impl.client.cache.TestCachingExec.testNotModifiedResponseUpdatesHeadersInCacheWhenNoEntity(TestCachingExec.java:1591)
--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see: http://www.atlassian.com/software/jira
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@hc.apache.org
For additional commands, e-mail: dev-help@hc.apache.org