{"record":{"id":"5d429c9a7275cb43","repo":"JetBrains/intellij-community","slug":"method-0-is-not-static","errorCode":null,"errorMessage":"Method {0} is not static","messagePattern":"Method (.+?) is not static","errorType":"exception","errorClass":"CommonRefactoringUtil.RefactoringErrorHintException","httpStatus":null,"severity":"error","filePath":"java/java-impl-refactorings/src/com/intellij/refactoring/convertToInstanceMethod/ConvertToInstanceMethodHandler.java","lineNumber":81,"sourceCode":"\n  @Override\n  public void invoke(@NotNull Project project, PsiElement @NotNull [] elements, DataContext dataContext) {\n    if (elements.length != 1 || !(elements[0] instanceof PsiMethod method)) return;\n    try {\n      new ConvertToInstanceMethodDialog(method, calculatePossibleInstanceQualifiers(method)).show();\n    }\n    catch (CommonRefactoringUtil.RefactoringErrorHintException e) {\n      if (ApplicationManager.getApplication().isUnitTestMode()) throw e;\n      Editor editor = CommonDataKeys.EDITOR.getData(dataContext);\n      CommonRefactoringUtil.showErrorHint(project, editor, RefactoringBundle.getCannotRefactorMessage(e.getMessage()),\n                                          getRefactoringName(), HelpID.CONVERT_TO_INSTANCE_METHOD);\n    }\n  }\n\n  @VisibleForTesting\n  public static Object @NotNull [] calculatePossibleInstanceQualifiers(@NotNull PsiMethod method) {\n    if (!method.hasModifierProperty(PsiModifier.STATIC)) {\n      throw new CommonRefactoringUtil.RefactoringErrorHintException(\n        JavaRefactoringBundle.message(\"convertToInstanceMethod.method.is.not.static\", method.getName()));\n    }\n    List<Object> qualifiers = new ArrayList<>();\n    final PsiParameter[] parameters = method.getParameterList().getParameters();\n    boolean classTypesFound = false;\n    boolean resolvableClassesFound = false;\n    for (final PsiParameter parameter : parameters) {\n      final PsiType type = parameter.getType();\n      if (type instanceof PsiClassType classType) {\n        classTypesFound = true;\n        final PsiClass psiClass = classType.resolve();\n        if (psiClass != null && !(psiClass instanceof PsiTypeParameter)) {\n          resolvableClassesFound = true;\n          if (method.getManager().isInProject(psiClass)) {\n            qualifiers.add(parameter);\n          }\n        }\n      }","sourceCodeStart":63,"sourceCodeEnd":99,"githubUrl":"https://github.com/JetBrains/intellij-community/blob/be881553f2a76ac8b4ea53950d93f0de78295c19/java/java-impl-refactorings/src/com/intellij/refactoring/convertToInstanceMethod/ConvertToInstanceMethodHandler.java#L63-L99","documentation":"ConvertToInstanceMethodHandler.calculatePossibleInstanceQualifiers throws CommonRefactoringUtil.RefactoringErrorHintException when the method passed to the 'Convert To Instance Method' refactoring lacks the static modifier. The refactoring works by demoting a static method to an instance method of one of its parameter types, so a non-static method has nothing to convert; the exception message names the offending method. In interactive mode the handler catches it and shows an error hint; in unit test mode it propagates.","triggerScenarios":"Invoking Convert to Instance Method (Refactor menu or intention) with the caret on a non-static method, or calling calculatePossibleInstanceQualifiers(method) programmatically where !method.hasModifierProperty(PsiModifier.STATIC).","commonSituations":"Invoking the refactoring from a quicklist or keyboard shortcut while the caret resolves to an instance method; plugins/upgrade scripts batch-applying the refactoring without checking modifiers; caret on a method that was just made non-static in the editor but the PSI used is stale.","solutions":["Select a static method (add the 'static' modifier or move the caret into a static method) before invoking the refactoring.","If the method should become an instance method of a parameter type, make it static first, convert, then adjust.","Programmatic callers: check method.hasModifierProperty(PsiModifier.STATIC) before calling and skip/report instead.","If the editor and model disagree, sync the file (resolve stale PSI) and retry."],"exampleFix":"// before:\nclass C { void m(A a) { ... } }  // convert-to-instance fails\n\n// after:\nclass C { static void m(A a) { ... } }  // then Convert to Instance Method succeeds","handlingStrategy":"validation","validationCode":"if (!method.hasModifierProperty(PsiModifier.STATIC)) {\n  // skip or report 'method is not static' before invoking the refactoring\n}","typeGuard":null,"tryCatchPattern":"try {\n  ConvertToInstanceMethodHandler.calculatePossibleInstanceQualifiers(method);\n} catch (CommonRefactoringUtil.RefactoringErrorHintException e) {\n  // show hint message; in unit-test mode this exception propagates\n}","preventionTips":["Check the STATIC modifier before invoking Convert to Instance Method.","In unit tests, expect RefactoringErrorHintException to be thrown (not hinted) — assert on it."],"tags":["java","intellij","refactoring","instance-method","psi","precondition"],"backgroundTag":null,"analyzedSha":"be881553f2a76ac8b4ea53950d93f0de78295c19","analyzedAt":"2026-08-14T14:13:06.425Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}