JetBrains/intellij-community · error · IncorrectCodeFragmentException

Compilation failed:\n

Error message

Compilation failed:\n

What it means

Error "Compilation failed:\n" thrown in JetBrains/intellij-community.

Source

Thrown at java/debugger/impl/src/com/intellij/debugger/ui/impl/watch/CompilingEvaluatorImpl.java:123

      File sourceFile = null;
      try {
        sourceFile = generateTempSourceFile(compilerManager.getJavacCompilerWorkingDir());
        File srcDir = sourceFile.getParentFile();
        List<File> sourcePath = Collections.emptyList();
        Set<File> sources = Collections.singleton(sourceFile);

        myCompiledClasses =
          compilerManager.compileJavaCode(options, platformClasspath, classpath, Collections.emptyList(), Collections.emptyList(), sourcePath, sources, srcDir);
      }
      catch (CompilationException e) {
        StringBuilder res = new StringBuilder("Compilation failed:\n");
        for (CompilationException.Message m : e.getMessages()) {
          if (m.getCategory() == CompilerMessageCategory.ERROR) {
            res.append(m.getText()).append("\n");
          }
        }
        throw new IncorrectCodeFragmentException(res.toString());
      }
      catch (Exception e) {
        throw new EvaluateException(e.getMessage());
      }
      finally {
        if (sourceFile != null) {
          FileUtil.delete(sourceFile);
        }
      }
    }
    return myCompiledClasses;
  }

  private File generateTempSourceFile(File workingDir) throws IOException {
    Pair<String, String> fileData = ReadAction.compute(() -> {
      PsiFile file = myData.getGeneratedInnerClass().getContainingFile();
      return Pair.create(file.getName(), file.getText());
    });

View on GitHub (pinned to be881553f2)

Solutions

  1. Read the compiler diagnostics appended to the message and fix the expression accordingly.
  2. Check that referenced classes are on the debuggee classpath and names are spelled correctly.

Example fix

Fix the reported error, e.g. add a cast: (List<String>) value.

When it happens

Trigger: The expression submitted to the compiling evaluator fails Java compilation.

Common situations: Syntax errors, unresolved symbols, or type errors in an Evaluate Expression / watch using the compiling evaluator.


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