LinkedHashMap is a Wrong dependency type
Hi,
I'm using the CacheValuesManager for caching a complex calculation. The CachedValue is a Map:
private val includeTags: CachedValue<Map<String, Collection<XmlTag>>>
This works, but sometimes IDEA throws an error when reading from this map:
java.lang.Throwable: Wrong dependency type: class java.util.LinkedHashMap
at com.intellij.openapi.diagnostic.Logger.error(Logger.java:123)
at com.intellij.util.CachedValueBase.getTimeStamp(CachedValueBase.java:177)
at com.intellij.psi.impl.PsiCachedValue.getTimeStamp(PsiCachedValue.java:101)
at com.intellij.util.CachedValueBase.isDependencyOutOfDate(CachedValueBase.java:138)
at com.intellij.psi.impl.PsiCachedValue.isDependencyOutOfDate(PsiCachedValue.java:74)
at com.intellij.util.CachedValueBase.isUpToDate(CachedValueBase.java:128)
at com.intellij.psi.impl.PsiCachedValue.isUpToDate(PsiCachedValue.java:65)
at com.intellij.util.CachedValueBase.getValueWithLock(CachedValueBase.java:227)
at com.intellij.psi.impl.PsiCachedValue.getValueWithLock(PsiCachedValue.java:60)
at com.intellij.psi.impl.PsiCachedValueImpl.getValue(PsiCachedValueImpl.java:38)
Mostly it works, but sometimes not. This happens when calling
fun findIncludeTagsWithType(type: String) = includeTags.value[type] ?: emptyList()
What am I doing wrong?
Please sign in to leave a comment.
To check CachedValue validness IDE will check timestamps of all dependencies. If true was specified as second parameter of CacheValuesManager.createCachedValue invokation (or createCachedValue with one argument is used) then IDE will try to check timestamp of calculated value as well.
Quite likely cached value doesn't need extra validness check for calculated value, in such case passing false as second parameter of CacheValuesManager.createCachedValue invokation will be the solution.
Thanks, that was my failure.