diff --git a/platform/lang-impl/src/com/intellij/codeInsight/template/impl/TemplateState.java b/platform/lang-impl/src/com/intellij/codeInsight/template/impl/TemplateState.java index 896945df10a0..fa3932580e17 100644 --- a/platform/lang-impl/src/com/intellij/codeInsight/template/impl/TemplateState.java +++ b/platform/lang-impl/src/com/intellij/codeInsight/template/impl/TemplateState.java @@ -536,8 +536,10 @@ public class TemplateState implements Disposable { new Runnable() { public void run() { BitSet calcedSegments = new BitSet(); + int maxAttempts = (myTemplate.getVariableCount()+1)*3; do { + maxAttempts--; calcedSegments.clear(); for (int i = myCurrentVariableNumber + 1; i < myTemplate.getVariableCount(); i++) { String variableName = myTemplate.getVariableNameAt(i); @@ -565,7 +567,7 @@ public class TemplateState implements Disposable { } } } - while (!calcedSegments.isEmpty()); + while (!calcedSegments.isEmpty() && maxAttempts >= 0); } } );