JetBrains/intellij-community · error · EvaluateException

evaluation.error.cannot.resolve.constructor

evaluation.error.cannot.resolve.constructor

Error message

Cannot resolve constructor ''{0}''

What it means

Thrown by EvaluatorBuilderImpl when evaluating a 'new Foo(...)' expression: resolveMethodGenerics() failed to resolve a constructor and at least one argument is present. The evaluator cannot synthesize a constructor call it cannot bind, so it reports the constructor as unresolvable with the full expression text.

Source

Thrown at java/debugger/impl/src/com/intellij/debugger/engine/evaluation/expression/EvaluatorBuilderImpl.java:1720

          new TypeEvaluator(JVMNameUtil.getJVMQualifiedName(expressionPsiType)),
          dimensionEvaluator,
          initializerEvaluator
        );
      }
      else if (expressionPsiType instanceof PsiClassType) { // must be a class ref
        PsiClass aClass = CompilingEvaluatorTypesUtil.getClass((PsiClassType)expressionPsiType);
        if (aClass instanceof PsiAnonymousClass) {
          throw unsupportedExpression(JavaDebuggerBundle.message("evaluation.error.anonymous.class.evaluation.not.supported"));
        }
        PsiExpressionList argumentList = expression.getArgumentList();
        if (argumentList == null) {
          throw expressionInvalid(expression);
        }
        final PsiExpression[] argExpressions = argumentList.getExpressions();
        final JavaResolveResult constructorResolveResult = expression.resolveMethodGenerics();
        PsiMethod constructor = CompilingEvaluatorTypesUtil.getReferencedConstructor((PsiMethod)constructorResolveResult.getElement());
        if (constructor == null && argExpressions.length > 0) {
          throw new EvaluateRuntimeException(new EvaluateException(
            JavaDebuggerBundle.message("evaluation.error.cannot.resolve.constructor", expression.getText()), null));
        }
        Evaluator[] argumentEvaluators = new Evaluator[argExpressions.length];
        // evaluate arguments
        for (int idx = 0; idx < argExpressions.length; idx++) {
          PsiExpression argExpression = argExpressions[idx];
          argExpression.accept(this);
          if (myResult != null) {
            argumentEvaluators[idx] = DisableGC.create(myResult);
          }
          else {
            throw expressionInvalid(argExpression);
          }
        }

        if (constructor != null) {
          processBoxingConversions(constructor.getParameterList().getParameters(), argExpressions, constructorResolveResult.getSubstitutor(), argumentEvaluators);
        }

View on GitHub (pinned to be881553f2)

Solutions

  1. Use exact argument types matching an existing constructor (cast nulls: new Foo((String)null))
  2. Verify the class and its version are on the runtime classpath of the debuggee, not just the IDE
  3. For inner classes, qualify with the outer instance: outer.new Inner(args)
  4. Fall back to a factory method call instead of a constructor expression

Example fix

// before: new Foo(null)

// after: new Foo((String)null)
Defensive patterns

Strategy: validation

Validate before calling

JavaResolveResult r = newExpr.resolveMethodGenerics();
if (r.getElement() == null && newExpr.getArgumentList().getExpressions().length > 0) {
  // disambiguate args with explicit casts or pick a factory method before evaluating
}

Try / catch

try {
  evaluator.evaluate(context);
} catch (EvaluateRuntimeException e) {
  // if constructor unresolved: retry with null-argument casts, e.g. new Foo((String)null)
}

Prevention

When it happens

Trigger: Visiting a PsiNewExpression with a PsiClassType whose resolveMethodGenerics() returns no PsiMethod (or a non-constructor element), while argumentList.getExpressions().length > 0; typical when the class is not on the debuggee's classpath, is ambiguous, or the argument types match no overload.

Common situations: Evaluating 'new Foo(bar)' where Foo comes from a library version different from the one the debuggee loaded; constructing inner (non-static) classes without an enclosing instance; evaluating constructors of classes compiled with newer bytecode than the debuggee's JVM understands.

Related errors


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