From edd0ed56ebbe340c95b60bdf460f4132d214efad Mon Sep 17 00:00:00 2001 From: Roman Shevchenko Date: Mon, 26 Mar 2012 20:05:48 +0200 Subject: [PATCH] EA-34896 (clear catch type caches more thoroughly) --- .../source/tree/java/PsiCatchSectionImpl.java | 33 ++++++++++++------- 1 file changed, 22 insertions(+), 11 deletions(-) diff --git a/java/java-psi-impl/src/com/intellij/psi/impl/source/tree/java/PsiCatchSectionImpl.java b/java/java-psi-impl/src/com/intellij/psi/impl/source/tree/java/PsiCatchSectionImpl.java index f7b9b8ff77c8..6dd26b59e597 100644 --- a/java/java-psi-impl/src/com/intellij/psi/impl/source/tree/java/PsiCatchSectionImpl.java +++ b/java/java-psi-impl/src/com/intellij/psi/impl/source/tree/java/PsiCatchSectionImpl.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2009 JetBrains s.r.o. + * Copyright 2000-2012 JetBrains s.r.o. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -43,6 +43,7 @@ import java.util.List; public class PsiCatchSectionImpl extends CompositePsiElement implements PsiCatchSection, Constants { private static final Logger LOG = Logger.getInstance("#com.intellij.psi.impl.source.tree.java.PsiCatchSectionImpl"); + private final Object myTypesCacheLock = new Object(); private CachedValue> myTypesCache = null; public PsiCatchSectionImpl() { @@ -75,17 +76,27 @@ public class PsiCatchSectionImpl extends CompositePsiElement implements PsiCatch return getTypesCache().getValue(); } - private synchronized CachedValue> getTypesCache() { - if (myTypesCache == null) { - final CachedValuesManager cacheManager = CachedValuesManager.getManager(getProject()); - myTypesCache = cacheManager.createCachedValue(new CachedValueProvider>() { - @Override public Result> compute() { - final List types = computePreciseCatchTypes(getParameter()); - return Result.create(types, PsiModificationTracker.MODIFICATION_COUNT); - } - }, false); + @Override + public void clearCaches() { + super.clearCaches(); + synchronized (myTypesCacheLock) { + myTypesCache = null; + } + } + + private CachedValue> getTypesCache() { + synchronized (myTypesCacheLock) { + if (myTypesCache == null) { + final CachedValuesManager cacheManager = CachedValuesManager.getManager(getProject()); + myTypesCache = cacheManager.createCachedValue(new CachedValueProvider>() { + @Override public Result> compute() { + final List types = computePreciseCatchTypes(getParameter()); + return Result.create(types, PsiModificationTracker.MODIFICATION_COUNT); + } + }, false); + } + return myTypesCache; } - return myTypesCache; } private List computePreciseCatchTypes(final PsiParameter parameter) {