JetBrains/intellij-community · error · IncorrectOperationException

Unsupported operation

Error message

Unsupported operation

What it means

PsiDocParamRef is the reference inside a @param/@throws javadoc tag to a method parameter. Its bindToElement only supports rebinding to another PsiParameter; passing any other element type throws IncorrectOperationException("Unsupported operation").

Source

Thrown at java/java-psi-impl/src/com/intellij/psi/impl/source/javadoc/PsiDocParamRef.java:77

    return new PsiReferenceBase<PsiElement>(this, range) {
      @Override
      public PsiElement resolve() {
        return target;
      }

      @Override
      public PsiElement handleElementRename(@NotNull String newElementName) {
        final CharTable charTableByTree = SharedImplUtil.findCharTableByTree(getNode());
        LeafElement newElement = Factory.createSingleLeafElement(JavaDocTokenType.DOC_TAG_VALUE_TOKEN, newElementName, charTableByTree, getManager());
        replaceChild(valueToken, newElement);
        return PsiDocParamRef.this;
      }

      @Override
      public PsiElement bindToElement(@NotNull PsiElement element) throws IncorrectOperationException {
        if (isReferenceTo(element)) return PsiDocParamRef.this;
        if(!(element instanceof PsiParameter)) {
          throw new IncorrectOperationException("Unsupported operation");
        }
        return handleElementRename(((PsiParameter)element).getName());
      }

      @Override
      public boolean isReferenceTo(@NotNull PsiElement element) {
        if (!(element instanceof PsiNamedElement)) return false;
        PsiNamedElement namedElement = (PsiNamedElement)element;
        if (!getCanonicalText().equals(namedElement.getName())) return false;
        return getManager().areElementsEquivalent(resolve(), element);
      }
    };
  }

  public static @NotNull List<PsiNamedElement> getAllParameters(@NotNull PsiDocComment comment) {
    List<PsiNamedElement> allParams = new ArrayList<>();
    PsiJavaDocumentedElement owner = comment.getOwner();
    if (owner instanceof PsiMethod) {

View on GitHub (pinned to be881553f2)

Solutions

  1. Guard the call: only bind when element instanceof PsiParameter.
  2. To update the javadoc text after a rename, call handleElementRename(newName) instead, which rewrites the tag value token.
  3. If the target is a type/throws reference, bind the appropriate reference object from the @throws tag, not the @param one.

Example fix

// before
docParamRef.bindToElement(target); // target is PsiField -> throws

// after
if (target instanceof PsiParameter) {
  docParamRef.bindToElement(target);
} else {
  docParamRef.handleElementRename(target.getName()); // just fix the tag text
}
Defensive patterns

Strategy: type-guard

Validate before calling

if (!(target instanceof PsiParameter)) return; // javadoc @param refs only bind to parameters

Type guard

static boolean canBindDocParamRef(PsiElement e) { return e instanceof PsiParameter; }

Try / catch

try { docRef.bindToElement(t); } catch (IncorrectOperationException e) { docRef.handleElementRename(t.getName()); }

Prevention

When it happens

Trigger: Calling bindToElement on the reference from a javadoc @param tag (element type DOC_TAG_VALUE_TOKEN) with a non-PsiParameter target such as a PsiField or PsiMethod.

Common situations: Refactorings that move/rename parameters and generically rebind all references including javadoc ones; plugins syncing javadoc with signature changes; wrong resolve result fed into bind from a custom resolver.

Related errors


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