JetBrains/intellij-community · error · EvaluateRuntimeException
Invalid declaration : {0} Only local variable declarations a
Error message
Invalid declaration : {0} Only local variable declarations are supported. What it means
Thrown by EvaluatorBuilderImpl when a PsiDeclarationStatement contains an element that is not a local variable — for example a class, enum, or field declaration inside an evaluated fragment. Only local variable declarations are supported by the JVM debugger's expression compiler, so anything else is rejected with the offending source text included in the message.
Source
Thrown at java/debugger/impl/src/com/intellij/debugger/engine/evaluation/expression/EvaluatorBuilderImpl.java:873
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;
}
}
@Override
public void visitConditionalExpression(@NotNull PsiConditionalExpression expression) {
if (LOG.isDebugEnabled()) {
LOG.debug("visitConditionalExpression " + expression);View on GitHub (pinned to be881553f2)
Solutions
- Remove nested type declarations from the evaluated fragment; declare the type in real project code instead
- Replace the local class usage with an existing project class or a lambda/anonymous expression
- Perform the setup in the actual source and re-run to the breakpoint
Example fix
// before (fragment): class Pair { int a, b; }
new Pair()
// after (fragment): java.util.List.of(1, 2) Defensive patterns
Strategy: validation
Validate before calling
for (PsiElement el : declarationStatement.getDeclaredElements()) {
if (!(el instanceof PsiLocalVariable)) {
throw new UnsupportedOperationException("Only local variable declarations are supported: " + el.getText());
}
} Type guard
boolean isSupportedDeclaration(PsiDeclarationStatement s) {
return Arrays.stream(s.getDeclaredElements()).allMatch(e -> e instanceof PsiLocalVariable);
} Try / catch
try {
builder.visitElement(fragment);
} catch (EvaluateRuntimeException e) {
// strip class/enum declarations and re-evaluate
} Prevention
- Keep type declarations out of evaluated fragments
- Declare helper types in project source before debugging
- Substitute lambdas or existing classes for local classes in evaluations
When it happens
Trigger: Visiting a declaration statement whose declaredElement is not a PsiLocalVariable (inner class declaration, local enum/interface/record in the fragment, annotation-type declaration); the builder falls to the else branch and throws evaluation.error.unsupported.declaration with declaredElement.getText().
Common situations: User pastes a code snippet containing 'class Foo { ... }' or 'enum E { A }' into the Evaluate code-fragment dialog; evaluating fragments that declare local records (Java 16+) which the evaluator cannot compile.
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
- Local variable declarations are not supported here.
- inconvertible.type.cast
AI-assisted analysis of JetBrains/intellij-community@be881553f2 (2026-08-14).
Data as JSON: /api/errors/8d1c322c72e241bd.
Report an issue: GitHub.