{"record":{"id":"9790c25b4fb75f31","repo":"JetBrains/intellij-community","slug":"can-t-change-name-of-jshell-holder-method","errorCode":null,"errorMessage":"Can't change name of JShell holder method","messagePattern":"Can't change name of JShell holder method","errorType":"exception","errorClass":"IncorrectOperationException","httpStatus":null,"severity":"error","filePath":"java/java-psi-impl/src/com/intellij/psi/impl/source/PsiJShellHolderMethodImpl.java","lineNumber":185,"sourceCode":"\n  @Override\n  public @Nullable PsiMethod findDeepestSuperMethod() {\n    return null;\n  }\n\n  @Override\n  public PsiMethod @NotNull [] findDeepestSuperMethods() {\n    return PsiMethod.EMPTY_ARRAY;\n  }\n\n  @Override\n  public @NotNull PsiModifierList getModifierList() {\n    return new LightModifierList(getManager());\n  }\n\n  @Override\n  public PsiElement setName(@NotNull String name) throws IncorrectOperationException {\n    throw new IncorrectOperationException(\"Can't change name of JShell holder method\");\n  }\n\n  @Override\n  public @NotNull HierarchicalMethodSignature getHierarchicalMethodSignature() {\n    return PsiSuperMethodImplUtil.getHierarchicalMethodSignature(this);\n  }\n\n  @Override\n  public boolean isDeprecated() {\n    return false;\n  }\n\n  @Override\n  public @Nullable PsiDocComment getDocComment() {\n    return null;\n  }\n\n  @Override","sourceCodeStart":167,"sourceCodeEnd":203,"githubUrl":"https://github.com/JetBrains/intellij-community/blob/be881553f2a76ac8b4ea53950d93f0de78295c19/java/java-psi-impl/src/com/intellij/psi/impl/source/PsiJShellHolderMethodImpl.java#L167-L203","documentation":"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\").","triggerScenarios":"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.","commonSituations":"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.","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."],"exampleFix":"// before\nmethod.setName(newName); // holder method from JShell console -> throws\n\n// after\nif (!method.isPhysical() || method.getContainingFile().getFileType().getName().equals(\"JAVA SHELL\")) continue;\nmethod.setName(newName);","handlingStrategy":"type-guard","validationCode":"if (!method.isPhysical()) continue; // synthetic JShell holder","typeGuard":"static boolean isRenamableMethod(PsiMethod m) { return m.isPhysical() && !(m instanceof PsiJShellHolderMethodImpl); }","tryCatchPattern":"try { method.setName(n); } catch (IncorrectOperationException e) { /* skip console snippet holder */ }","preventionTips":["Restrict refactors to physical elements in project source roots.","Ignore console/shell file types when walking PSI."],"tags":["java","psi","jshell","synthetic-elements","rename"],"backgroundTag":null,"analyzedSha":"be881553f2a76ac8b4ea53950d93f0de78295c19","analyzedAt":"2026-08-14T14:13:06.425Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}