JetBrains/intellij-community · error · IncorrectOperationException
Cannot create {0} - incorrect {1} template.
Error message
Cannot create {0} - incorrect {1} template. What it means
Thrown by JavaDirectoryServiceImpl.createInterface() when the internal file template used to create a new interface (JavaTemplateUtil.INTERNAL_INTERFACE_TEMPLATE_NAME) yields a PsiClass that is not an interface. The check is someClass.isInterface() after instantiateClassFromTemplate; failure means the 'interface' keyword was removed from the customized template. It is an IncorrectOperationException aborting the create-from-template action.
Source
Thrown at java/java-impl/src/com/intellij/psi/impl/file/JavaDirectoryServiceImpl.java:106
@NotNull String templateName,
boolean askForUndefinedVariables) throws IncorrectOperationException {
return createClass(dir, name, templateName, askForUndefinedVariables, Collections.emptyMap());
}
@Override
public PsiClass createClass(@NotNull PsiDirectory dir,
@NotNull String name,
@NotNull String templateName,
boolean askForUndefinedVariables, final @NotNull Map<String, String> additionalProperties) throws IncorrectOperationException {
return createClassFromTemplate(dir, name, templateName, askForUndefinedVariables, additionalProperties);
}
@Override
public @NotNull PsiClass createInterface(@NotNull PsiDirectory dir, @NotNull String name) throws IncorrectOperationException {
String templateName = JavaTemplateUtil.INTERNAL_INTERFACE_TEMPLATE_NAME;
PsiClass someClass = createClassFromTemplate(dir, name, templateName);
if (!someClass.isInterface()) {
throw new IncorrectOperationException(getIncorrectTemplateMessage(templateName, dir.getProject()));
}
return someClass;
}
@Override
public @NotNull PsiClass createEnum(@NotNull PsiDirectory dir, @NotNull String name) throws IncorrectOperationException {
String templateName = JavaTemplateUtil.INTERNAL_ENUM_TEMPLATE_NAME;
PsiClass someClass = createClassFromTemplate(dir, name, templateName);
if (!someClass.isEnum()) {
throw new IncorrectOperationException(getIncorrectTemplateMessage(templateName, dir.getProject()));
}
return someClass;
}
@Override
public @NotNull PsiClass createRecord(@NotNull PsiDirectory dir, @NotNull String name) throws IncorrectOperationException {
String templateName = JavaTemplateUtil.INTERNAL_RECORD_TEMPLATE_NAME;
PsiClass someClass = createClassFromTemplate(dir, name, templateName);View on GitHub (pinned to be881553f2)
Solutions
- Open Settings > Editor > File and Code Templates, find the internal interface template and restore it so it still contains 'interface ${NAME} { ... }'.
- If unsure which template is broken, reset all file templates to defaults (the templates tab's reset action) and retry creating the interface.
- Check whether a plugin injects or overrides code templates and disable it temporarily.
- For plugin authors: ensure you pass JavaTemplateUtil.INTERNAL_INTERFACE_TEMPLATE_NAME and do not customize it to a non-interface.
Example fix
// template before (broken)
#parse("File Header.java")
class ${NAME} {
}
// template after (fixed)
#parse("File Header.java")
public interface ${NAME} {
} Defensive patterns
Strategy: validation
Validate before calling
FileTemplate template = FileTemplateManager.getInstance(project).getInternalTemplate(JavaTemplateUtil.INTERNAL_INTERFACE_TEMPLATE_NAME);
String text = template.getText();
if (!text.contains("interface")) {
// template broken; reset before calling createInterface
} Try / catch
try { JavaDirectoryService.getInstance().createInterface(dir, name); } catch (IncorrectOperationException e) { /* report template name from message, reset template */ } Prevention
- Do not customize internal templates (INTERFACE/ENUM/RECORD/ANNOTATION) by removing their type keyword; keep 'interface ${NAME}'.
- After changing file templates, immediately test New > Interface in a scratch project.
- Reset templates to defaults before reporting platform bugs about class creation.
When it happens
Trigger: Calling JavaDirectoryService.createInterface(dir, name) or the New > Interface action when the internal interface template (file template used for internal creation) has been edited so it no longer declares an interface (e.g. 'interface ${NAME}' replaced with 'class ${NAME}').
Common situations: A user customized internal code templates via Settings > Editor > File and Code Templates and broke the interface template; a plugin or settings sync shipped a corrupted template; restoring defaults only for some templates after an IDE upgrade.
Related errors
- Cannot create class in invalid package: '{qualifiedName}'
- Cannot create class-file
- Cannot bind to {element}
- error.package.set.position.parsing.error
- No JDK specified
AI-assisted analysis of JetBrains/intellij-community@be881553f2 (2026-08-14).
Data as JSON: /api/errors/47c005abbfa2733d.
Report an issue: GitHub.