JetBrains/intellij-community · error · EvaluateRuntimeException
Local variable declarations are not supported here.
Error message
Local variable declarations are not supported here.
What it means
Thrown by EvaluatorBuilderImpl when the evaluated code fragment contains a local variable declaration statement but the current evaluation mode/context does not support declaring new locals (e.g. a single-expression evaluator or a context where only statements/expressions are allowed). The builder explicitly rejects the declaration instead of failing later at runtime.
Source
Thrown at java/debugger/impl/src/com/intellij/debugger/engine/evaluation/expression/EvaluatorBuilderImpl.java:868
Evaluator rEvaluator = myResult;
PsiExpression localVarReference = elementFactory.createExpressionFromText(localVariable.getName(), initializer);
localVarReference.accept(this);
Evaluator lEvaluator = myResult;
rEvaluator = handleAssignmentBoxingAndPrimitiveTypeConversions(localVarReference.getType(), rType, rEvaluator,
statement.getProject());
Evaluator assignment = new AssignmentEvaluator(lEvaluator, rEvaluator);
evaluators.add(assignment);
}
catch (IncorrectOperationException e) {
LOG.error(e);
}
}
}
else {
throw new EvaluateRuntimeException(new EvaluateException(
JavaDebuggerBundle.message("evaluation.error.local.variable.declarations.not.supported"), null));
}
}
else {
throw new EvaluateRuntimeException(new EvaluateException(
JavaDebuggerBundle.message("evaluation.error.unsupported.declaration", declaredElement.getText()), null));
}
}
if (!evaluators.isEmpty()) {
CodeFragmentEvaluator codeFragmentEvaluator = new CodeFragmentEvaluator(myCurrentFragmentEvaluator);
codeFragmentEvaluator.setStatements(evaluators.toArray(new Evaluator[0]));
myResult = codeFragmentEvaluator;
}
else {
myResult = null;
}
}View on GitHub (pinned to be881553f2)
Solutions
- Enable 'Code fragment mode' / 'Enable new variables' in the Evaluate dialog so declarations are allowed
- Rewrite the evaluation as a single expression without declarations (e.g. inline the value)
- Use a watcher with pre-declared variables instead of declaring new ones
Example fix
// before (expression mode): int x = 5; x * 2; // after (expression mode): 5 * 2; // or: switch the Evaluate dialog to Code fragment mode
Defensive patterns
Strategy: validation
Validate before calling
// when driving evaluation programmatically
if (mode.allowsCodeFragments() || !containsDeclarations(expressionText)) {
evaluator = EvaluatorBuilder.build(fragment, mode);
} else {
evaluator = EvaluatorBuilder.build(stripDeclarations(expressionText), EXPRESSION_MODE);
} Try / catch
try {
textUI.evaluate(input);
} catch (EvaluateRuntimeException e) {
// if 'declarations not supported', retry with declarations inlined/removed
} Prevention
- Enable code fragment mode in the Evaluate dialog when using declarations
- Prefer single expressions in watchers and inline evaluators
- Inline declared values instead of introducing new locals in restricted contexts
When it happens
Trigger: Visiting a PsiDeclarationStatement in a code fragment evaluated in 'expression' mode (Alt+F8 Evaluate Expression without 'code fragment' mode enabled), or an API-driven evaluation built with EvaluatorBuilder without fragment support; the else branch throws EvaluateRuntimeException with evaluation.error.local.variable.declarations.not.supported.
Common situations: User types 'int x = 5;' into the Evaluate dialog while it is configured as a single expression instead of a code fragment; evaluating declarations in a watcher or inline evaluator that only accepts expressions.
Related errors
- Interface method invocation is not supported in JVM {}. Use
- Cannot construct wrapper object for value of type {}: Unable
- Variable ''{0}'' is already declared
- Invalid declaration : {0} Only local variable declarations a
- inconvertible.type.cast
AI-assisted analysis of JetBrains/intellij-community@be881553f2 (2026-08-14).
Data as JSON: /api/errors/5bf667d2db2dad77.
Report an issue: GitHub.