java.util.NoSuchElementException崩溃,LruCache内的currectsize 和cache内的数据size综合差距很大
- Dominant language
- Java
- Stars
- 35k
- Forks
- 6.2k
- Avg merge
- 1d 11h
- Merged PRs (30d)
- 8
Description
glide version:
implementation 'com.github.penfeizhou.android.animation:glide-plugin:2.16.0'
implementation 'com.github.penfeizhou.android.animation:apng:2.16.0'
kapt 'com.github.bumptech.glide:compiler:4.11.0'

我们之前发现了这个崩溃:
java.util.NoSuchElementException
at java.util.LinkedHashMap$LinkedHashIterator.nextNode(LinkedHashMap.java:777)
at java.util.LinkedHashMap$LinkedEntryIterator.next(LinkedHashMap.java:808)
at java.util.LinkedHashMap$LinkedEntryIterator.next(LinkedHashMap.java:806)
at com.bumptech.glide.util.LruCache.trimToSize(LruCache.java:169)
app打开在首页,有个循环的banner,图片并没有很大,按理说不会触发trimToSize,在追踪这个问题的时候debug断点LruCache里的put和remove方法,发现currentSize比预想的要大,所以在每次断点处,我都打印了下cache里面的每个的size和总和发现和currectSize不一样,而且隔一会就会差距变得更大。如开始的图所示。total is 3652480 currectsize is 6784136(这时非debug下运行一段时间后的),等再次不进行断点自动运行一会后会变成:total is 3652480 currectsize is 8796056 自己计算打印的total又变回3652480 currectsize 又比之前的 6784136 大了很多,变成了 currectsize is 8796056 。
debug时的代码如图

:
当currectsize大于29.9M时,会触发trimToSize,但这cache里面其实并没有什么,所以就崩溃了
Contributor guide
Assessment
This issue has not been assessed yet.