LinkedHashMap is a Wrong dependency type



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(
    at com.intellij.util.CachedValueBase.getTimeStamp(
    at com.intellij.psi.impl.PsiCachedValue.getTimeStamp(
    at com.intellij.util.CachedValueBase.isDependencyOutOfDate(
    at com.intellij.psi.impl.PsiCachedValue.isDependencyOutOfDate(
    at com.intellij.util.CachedValueBase.isUpToDate(
    at com.intellij.psi.impl.PsiCachedValue.isUpToDate(
    at com.intellij.util.CachedValueBase.getValueWithLock(
    at com.intellij.psi.impl.PsiCachedValue.getValueWithLock(
    at com.intellij.psi.impl.PsiCachedValueImpl.getValue(

Mostly it works, but sometimes not. This happens when calling

fun findIncludeTagsWithType(type: String) = includeTags.value[type] ?: emptyList()

What am I doing wrong?



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.


Please sign in to leave a comment.