{"record":{"id":"5bf667d2db2dad77","repo":"JetBrains/intellij-community","slug":"local-variable-declarations-are-not-supported-here","errorCode":null,"errorMessage":"Local variable declarations are not supported here.","messagePattern":"Local variable declarations are not supported here\\.","errorType":"exception","errorClass":"EvaluateRuntimeException","httpStatus":null,"severity":"error","filePath":"java/debugger/impl/src/com/intellij/debugger/engine/evaluation/expression/EvaluatorBuilderImpl.java","lineNumber":868,"sourceCode":"                Evaluator rEvaluator = myResult;\n\n                PsiExpression localVarReference = elementFactory.createExpressionFromText(localVariable.getName(), initializer);\n\n                localVarReference.accept(this);\n                Evaluator lEvaluator = myResult;\n                rEvaluator = handleAssignmentBoxingAndPrimitiveTypeConversions(localVarReference.getType(), rType, rEvaluator,\n                                                                               statement.getProject());\n\n                Evaluator assignment = new AssignmentEvaluator(lEvaluator, rEvaluator);\n                evaluators.add(assignment);\n              }\n              catch (IncorrectOperationException e) {\n                LOG.error(e);\n              }\n            }\n          }\n          else {\n            throw new EvaluateRuntimeException(new EvaluateException(\n              JavaDebuggerBundle.message(\"evaluation.error.local.variable.declarations.not.supported\"), null));\n          }\n        }\n        else {\n          throw new EvaluateRuntimeException(new EvaluateException(\n            JavaDebuggerBundle.message(\"evaluation.error.unsupported.declaration\", declaredElement.getText()), null));\n        }\n      }\n\n      if (!evaluators.isEmpty()) {\n        CodeFragmentEvaluator codeFragmentEvaluator = new CodeFragmentEvaluator(myCurrentFragmentEvaluator);\n        codeFragmentEvaluator.setStatements(evaluators.toArray(new Evaluator[0]));\n        myResult = codeFragmentEvaluator;\n      }\n      else {\n        myResult = null;\n      }\n    }","sourceCodeStart":850,"sourceCodeEnd":886,"githubUrl":"https://github.com/JetBrains/intellij-community/blob/be881553f2a76ac8b4ea53950d93f0de78295c19/java/debugger/impl/src/com/intellij/debugger/engine/evaluation/expression/EvaluatorBuilderImpl.java#L850-L886","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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"],"exampleFix":"// before (expression mode): int x = 5; x * 2;\n\n// after (expression mode): 5 * 2;\n// or: switch the Evaluate dialog to Code fragment mode","handlingStrategy":"validation","validationCode":"// when driving evaluation programmatically\nif (mode.allowsCodeFragments() || !containsDeclarations(expressionText)) {\n  evaluator = EvaluatorBuilder.build(fragment, mode);\n} else {\n  evaluator = EvaluatorBuilder.build(stripDeclarations(expressionText), EXPRESSION_MODE);\n}","typeGuard":null,"tryCatchPattern":"try {\n  textUI.evaluate(input);\n} catch (EvaluateRuntimeException e) {\n  // if 'declarations not supported', retry with declarations inlined/removed\n}","preventionTips":["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"],"tags":["debugger","evaluation","declarations","evaluator-builder"],"backgroundTag":null,"analyzedSha":"be881553f2a76ac8b4ea53950d93f0de78295c19","analyzedAt":"2026-08-14T14:13:06.425Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}