From c6955df2e2fbeef499c14a3194dbececf67ee0ff Mon Sep 17 00:00:00 2001 From: Sergey Prigogin Date: Tue, 7 Feb 2017 14:48:32 -0800 Subject: [PATCH] Bug 511871 - CContentAssistProcessor.createContext may leak index lock Change-Id: I828c94484c7b1594ba72551b80cd5ed6e6a8576c --- .../CContentAssistProcessor.java | 44 +++++++++++-------- 1 file changed, 25 insertions(+), 19 deletions(-) diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/text/contentassist/CContentAssistProcessor.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/text/contentassist/CContentAssistProcessor.java index 662662f050e..3948214d9e3 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/text/contentassist/CContentAssistProcessor.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/text/contentassist/CContentAssistProcessor.java @@ -266,29 +266,35 @@ public class CContentAssistProcessor extends ContentAssistProcessor { char activationChar = getActivationChar(viewer, offset); CContentAssistInvocationContext context = new CContentAssistInvocationContext(viewer, offset, fEditor, isCompletion, isAutoActivated()); - if (isCompletion && activationChar == '.' && fReplacementAutoActivationCharacters != null && - fReplacementAutoActivationCharacters.contains('.')) { - IASTCompletionNode node = context.getCompletionNode(); - if (node != null) { - IASTName[] names = node.getNames(); - if (names.length > 0 && names[0].getParent() instanceof IASTFieldReference) { - IASTFieldReference ref = (IASTFieldReference) names[0].getParent(); - IASTExpression ownerExpr = ref.getFieldOwner(); - IType ownerExprType = SemanticUtil.getNestedType(ownerExpr.getExpressionType(), SemanticUtil.TDEF); - if (ownerExprType instanceof ICPPUnknownType) { - ownerExprType = HeuristicResolver.resolveUnknownType((ICPPUnknownType) ownerExprType, - names[0]); - } - if (ownerExprType instanceof IPointerType) { - context = replaceDotWithArrow(viewer, offset, isCompletion, context, activationChar); + try { + if (isCompletion && activationChar == '.' && fReplacementAutoActivationCharacters != null && + fReplacementAutoActivationCharacters.contains('.')) { + IASTCompletionNode node = context.getCompletionNode(); + if (node != null) { + IASTName[] names = node.getNames(); + if (names.length > 0 && names[0].getParent() instanceof IASTFieldReference) { + IASTFieldReference ref = (IASTFieldReference) names[0].getParent(); + IASTExpression ownerExpr = ref.getFieldOwner(); + IType ownerExprType = SemanticUtil.getNestedType(ownerExpr.getExpressionType(), SemanticUtil.TDEF); + if (ownerExprType instanceof ICPPUnknownType) { + ownerExprType = HeuristicResolver.resolveUnknownType((ICPPUnknownType) ownerExprType, + names[0]); + } + if (ownerExprType instanceof IPointerType) { + context = replaceDotWithArrow(viewer, offset, isCompletion, context, activationChar); + } } } + if (context != null && isAutoActivated() && !fCContentAutoActivationCharacters.contains(activationChar)) { + // Auto-replace, but not auto-content-assist - bug 344387. + context.dispose(); + context = null; + } } - if (context != null && isAutoActivated() && !fCContentAutoActivationCharacters.contains(activationChar)) { - // Auto-replace, but not auto-content-assist - bug 344387. + } catch (RuntimeException | Error e) { + if (context != null) context.dispose(); - context = null; - } + throw e; } return context;