{"record":{"id":"8d1c322c72e241bd","repo":"JetBrains/intellij-community","slug":"invalid-declaration-0-only-local-variable-decl","errorCode":null,"errorMessage":"Invalid declaration : {0} Only local variable declarations are supported.","messagePattern":"Invalid declaration : (.+?) Only local variable declarations are supported\\.","errorType":"exception","errorClass":"EvaluateRuntimeException","httpStatus":null,"severity":"error","filePath":"java/debugger/impl/src/com/intellij/debugger/engine/evaluation/expression/EvaluatorBuilderImpl.java","lineNumber":873,"sourceCode":"                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    }\n\n    @Override\n    public void visitConditionalExpression(@NotNull PsiConditionalExpression expression) {\n      if (LOG.isDebugEnabled()) {\n        LOG.debug(\"visitConditionalExpression \" + expression);","sourceCodeStart":855,"sourceCodeEnd":891,"githubUrl":"https://github.com/JetBrains/intellij-community/blob/be881553f2a76ac8b4ea53950d93f0de78295c19/java/debugger/impl/src/com/intellij/debugger/engine/evaluation/expression/EvaluatorBuilderImpl.java#L855-L891","documentation":"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.","triggerScenarios":"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().","commonSituations":"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.","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"],"exampleFix":"// before (fragment): class Pair { int a, b; }\nnew Pair()\n\n// after (fragment): java.util.List.of(1, 2)","handlingStrategy":"validation","validationCode":"for (PsiElement el : declarationStatement.getDeclaredElements()) {\n  if (!(el instanceof PsiLocalVariable)) {\n    throw new UnsupportedOperationException(\"Only local variable declarations are supported: \" + el.getText());\n  }\n}","typeGuard":"boolean isSupportedDeclaration(PsiDeclarationStatement s) {\n  return Arrays.stream(s.getDeclaredElements()).allMatch(e -> e instanceof PsiLocalVariable);\n}","tryCatchPattern":"try {\n  builder.visitElement(fragment);\n} catch (EvaluateRuntimeException e) {\n  // strip class/enum declarations and re-evaluate\n}","preventionTips":["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"],"tags":["debugger","evaluation","declaration","unsupported-syntax"],"backgroundTag":null,"analyzedSha":"be881553f2a76ac8b4ea53950d93f0de78295c19","analyzedAt":"2026-08-14T14:13:06.425Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}