JetBrains/intellij-community · warning · EvaluateException

Invalid local variable name ''{0}''

Error message

Invalid local variable name ''{0}''

What it means

Thrown by LocalVariableDescriptorImpl.getDescriptorEvaluation when the debugger tries to build a PSI expression from a local variable's name via JavaPsiFacade.getElementFactory().createExpressionFromText(getName(), ...). If the variable's name (as reported by the target VM's variable table) is empty or not a valid Java identifier, the PSI factory throws IncorrectOperationException, which is wrapped into an EvaluateException with this message.

Source

Thrown at java/debugger/impl/src/com/intellij/debugger/ui/impl/watch/LocalVariableDescriptorImpl.java:108

  @Override
  public String getName() {
    return myLocalVariable.name();
  }

  @Override
  public @Nullable String getDeclaredType() {
    return myTypeName;
  }

  @Override
  public PsiExpression getDescriptorEvaluation(DebuggerContext context) throws EvaluateException {
    PsiElementFactory elementFactory = JavaPsiFacade.getElementFactory(myProject);
    try {
      return elementFactory.createExpressionFromText(getName(), PositionUtil.getContextElement(context));
    }
    catch (IncorrectOperationException e) {
      throw new EvaluateException(JavaDebuggerBundle.message("error.invalid.local.variable.name", getName()), e);
    }
  }

  @Override
  public XValueModifier getModifier(JavaValue value) {
    return new JavaValueModifier(value) {
      @Override
      protected void setValueImpl(@NotNull XExpression expression, @NotNull XModificationCallback callback) {
        final LocalVariableProxyImpl local = LocalVariableDescriptorImpl.this.getLocalVariable();
        if (local != null) {
          final DebuggerContextImpl debuggerContext = DebuggerManagerEx.getInstanceEx(getProject()).getContext();
          set(expression, callback, debuggerContext, new SetValueRunnable() {
            @Override
            public void setValue(EvaluationContextImpl evaluationContext, Value newValue) throws ClassNotLoadedException,
                                                                                                 InvalidTypeException,
                                                                                                 EvaluateException {
              debuggerContext.getFrameProxy().setValue(local, preprocessValue(evaluationContext, newValue, getLType()));
              update(debuggerContext);

View on GitHub (pinned to be881553f2)

Solutions

  1. Rebuild the target module with full debug info (-g or -g:vars) and restart the debug session
  2. If the code is obfuscated, exclude it from renaming or attach original sources/variable names before debugging
  3. Check that class files on the classpath match the sources you are editing (stale build); rebuild project
  4. As a workaround, evaluate the value by its computed expression or use Watches with an explicit valid expression instead of the broken variable entry

Example fix

// before: relying on variable-table names from a -g:none build
javac -g:none Main.java
// after: compile with local variable tables so the debugger gets valid names
javac -g Main.java
Defensive patterns

Strategy: try-catch

Validate before calling

// before asking the debugger to evaluate a variable, check the name is a legal identifier
boolean valid = name != null && !name.isEmpty() && NameUtil.isValidIdentifier(name);

Try / catch

try {
  PsiExpression expr = descriptor.getDescriptorEvaluation(context);
} catch (EvaluateException e) {
  // name not representable as Java expression; fall back to raw JDI value display
  showRawValue(descriptor);
}

Prevention

When it happens

Trigger: Evaluating the 'this' expression or inspecting/evaluating a local variable in the Variables view whose name is blank, a keyword, or contains characters illegal in a Java identifier; typically happens when the class was compiled without local variable tables, with obfuscated/renamed variables, or by non-standard compilers (Kotlin with odd name mangling, bytecode manipulators).

Common situations: Debugging obfuscated code (ProGuard/R8), classes compiled with -g:none so variable names come back empty, or synthetic variables produced by Kotlin/Scala/Groovy compilers. Also seen when the debug info is stale after hot-swap/redefine and names no longer match.

Related errors


AI-assisted analysis of JetBrains/intellij-community@be881553f2 (2026-08-14). Data as JSON: /api/errors/24a2e1f462337761. Report an issue: GitHub.