JetBrains/intellij-community · error · IncorrectOperationException
Can't change name of JShell holder method
Error message
Can't change name of JShell holder method
What it means
PsiJShellHolderMethodImpl is a synthetic PsiMethod created as a holder for JShell snippet evaluation in the IDE console. Its name is internal plumbing for the JShell protocol, not user-visible source, so setName throws IncorrectOperationException("Can't change name of JShell holder method").
Source
Thrown at java/java-psi-impl/src/com/intellij/psi/impl/source/PsiJShellHolderMethodImpl.java:185
@Override
public @Nullable PsiMethod findDeepestSuperMethod() {
return null;
}
@Override
public PsiMethod @NotNull [] findDeepestSuperMethods() {
return PsiMethod.EMPTY_ARRAY;
}
@Override
public @NotNull PsiModifierList getModifierList() {
return new LightModifierList(getManager());
}
@Override
public PsiElement setName(@NotNull String name) throws IncorrectOperationException {
throw new IncorrectOperationException("Can't change name of JShell holder method");
}
@Override
public @NotNull HierarchicalMethodSignature getHierarchicalMethodSignature() {
return PsiSuperMethodImplUtil.getHierarchicalMethodSignature(this);
}
@Override
public boolean isDeprecated() {
return false;
}
@Override
public @Nullable PsiDocComment getDocComment() {
return null;
}
@OverrideView on GitHub (pinned to be881553f2)
Solutions
- Filter out synthetic/non-physical elements: check method.isPhysical() == false or instanceof PsiJShellHolderMethodImpl (or skip files from the Java Shell console file type) before renaming.
- Scope rename/refactoring actions to source files only (e.g. restrict to FileElementType sources, or check file.getViewProvider().getVirtualFile() is in the project source roots).
- If you must rename the snippet code, edit the snippet text in the console rather than PSI mutation.
Example fix
// before
method.setName(newName); // holder method from JShell console -> throws
// after
if (!method.isPhysical() || method.getContainingFile().getFileType().getName().equals("JAVA SHELL")) continue;
method.setName(newName); Defensive patterns
Strategy: type-guard
Validate before calling
if (!method.isPhysical()) continue; // synthetic JShell holder
Type guard
static boolean isRenamableMethod(PsiMethod m) { return m.isPhysical() && !(m instanceof PsiJShellHolderMethodImpl); } Try / catch
try { method.setName(n); } catch (IncorrectOperationException e) { /* skip console snippet holder */ } Prevention
- Restrict refactors to physical elements in project source roots.
- Ignore console/shell file types when walking PSI.
When it happens
Trigger: Calling setName on a method discovered inside a JShell snippet file (java shell console PSI); typically a generic plugin (rename, find-usages, refactoring) walking the console's in-memory PSI tree.
Common situations: Plugins that traverse all PsiMethods in open editors/buffers while a JShell or Java REPL console session is active; refactorings invoked from the shell console; tests exercising snippet PSI.
Related errors
- ''{0}'' is not an identifier.
- Cannot rename light class
- Implicitly declared class may have no name
- psi.error.attempt.to.edit.class.file
- Cannot rename receiver parameter
AI-assisted analysis of JetBrains/intellij-community@be881553f2 (2026-08-14).
Data as JSON: /api/errors/9790c25b4fb75f31.
Report an issue: GitHub.