{"action":"created","issue":{"url":"https://api.github.com/repos/square/okhttp/issues/1932","labels_url":"https://api.github.com/repos/square/okhttp/issues/1932/labels{/name}","comments_url":"https://api.github.com/repos/square/okhttp/issues/1932/comments","events_url":"https://api.github.com/repos/square/okhttp/issues/1932/events","html_url":"https://github.com/square/okhttp/issues/1932","id":111898411,"number":1932,"title":"NoSuchElementException should not be thrown by DiskLruCache.trimToSize()","user":{"login":"denversc","id":480382,"avatar_url":"https://avatars.githubusercontent.com/u/480382?v=3","gravatar_id":"","url":"https://api.github.com/users/denversc","html_url":"https://github.com/denversc","followers_url":"https://api.github.com/users/denversc/followers","following_url":"https://api.github.com/users/denversc/following{/other_user}","gists_url":"https://api.github.com/users/denversc/gists{/gist_id}","starred_url":"https://api.github.com/users/denversc/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/denversc/subscriptions","organizations_url":"https://api.github.com/users/denversc/orgs","repos_url":"https://api.github.com/users/denversc/repos","events_url":"https://api.github.com/users/denversc/events{/privacy}","received_events_url":"https://api.github.com/users/denversc/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"milestone":null,"comments":1,"created_at":"2015-10-16T19:44:42Z","updated_at":"2015-10-16T19:47:28Z","closed_at":"2015-10-16T19:47:28Z","body":"In an Android app that I'm writing I got a ```NoSuchElementException``` thrown from ```DiskLruCache.trimToSize()``` when invoked from ```cleanupRunnable```; however, I would expect that trimToSize() would never cause such an exception to occur.\r\n\r\n    FATAL EXCEPTION: OkHttp DiskLruCache\r\n    java.util.NoSuchElementException\r\n        at java.util.LinkedHashMap$LinkedHashIterator.nextEntry(LinkedHashMap.java:350)\r\n        at java.util.LinkedHashMap$ValueIterator.next(LinkedHashMap.java:371)\r\n        at com.squareup.okhttp.internal.DiskLruCache.trimToSize(DiskLruCache.java:664)\r\n        at com.squareup.okhttp.internal.DiskLruCache.access$200(DiskLruCache.java:88)\r\n        at com.squareup.okhttp.internal.DiskLruCache$1.run(DiskLruCache.java:175)\r\n        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)\r\n        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)\r\n        at java.lang.Thread.run(Thread.java:841)\r\n\r\nI think this exception is a symptom of a race condition.  This exception happened when I cancelled an upload in my Android app, which calls ```OkHttpClient.cancel(Object tag)```, which I believe schedules an asynchronous run of ```DiskLruCache.cleanupRunnable```.\r\n\r\nAll calls to ```trimToSize()``` are synchronized on the enclosing DiskLruCache instance... except when called from ```cleanupRunnable```.  This is suspicious, as perhaps the calls to trimToSize() from cleanupRunnable should also be synchronized on the DiskLruCache instance?\r\n\r\nokhttp version on which this issue was discovered: com.squareup.okhttp:okhttp:2.4.0\r\n\r\nThanks!"},"comment":{"url":"https://api.github.com/repos/square/okhttp/issues/comments/148817388","html_url":"https://github.com/square/okhttp/issues/1932#issuecomment-148817388","issue_url":"https://api.github.com/repos/square/okhttp/issues/1932","id":148817388,"user":{"login":"denversc","id":480382,"avatar_url":"https://avatars.githubusercontent.com/u/480382?v=3","gravatar_id":"","url":"https://api.github.com/users/denversc","html_url":"https://github.com/denversc","followers_url":"https://api.github.com/users/denversc/followers","following_url":"https://api.github.com/users/denversc/following{/other_user}","gists_url":"https://api.github.com/users/denversc/gists{/gist_id}","starred_url":"https://api.github.com/users/denversc/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/denversc/subscriptions","organizations_url":"https://api.github.com/users/denversc/orgs","repos_url":"https://api.github.com/users/denversc/repos","events_url":"https://api.github.com/users/denversc/events{/privacy}","received_events_url":"https://api.github.com/users/denversc/received_events","type":"User","site_admin":false},"created_at":"2015-10-16T19:47:28Z","updated_at":"2015-10-16T19:47:28Z","body":"Duplicate of #1804"}}