{"record":{"id":"7e8233017d8a7b7d","repo":"JetBrains/intellij-community","slug":"no-target-class-for-the-instance-method-is-found","errorCode":null,"errorMessage":"No target class for the instance method is found: method parameter types are unknown.","messagePattern":"No target class for the instance method is found: method parameter types are unknown\\.","errorType":"exception","errorClass":"CommonRefactoringUtil.RefactoringErrorHintException","httpStatus":null,"severity":"error","filePath":"java/java-impl-refactorings/src/com/intellij/refactoring/convertToInstanceMethod/ConvertToInstanceMethodHandler.java","lineNumber":132,"sourceCode":"    }\n    if (!qualifiers.isEmpty()) {\n      return qualifiers.toArray();\n    }\n    \n    String message;\n    if (!classTypesFound) {\n      message = JavaRefactoringBundle.message(\"convertToInstanceMethod.no.parameters.with.reference.type\");\n    }\n    else if (!resolvableClassesFound) {\n      message = JavaRefactoringBundle.message(\"convertToInstanceMethod.all.reference.type.parameters.have.unknown.types\");\n    }\n    else {\n      message = JavaRefactoringBundle.message(\"convertToInstanceMethod.all.reference.type.parameters.are.not.in.project\");\n    }\n    if (canHaveUsableConstructor) {\n      message += \" \" + JavaRefactoringBundle.message(\"convertToInstanceMethod.no.default.ctor\");\n    }\n    throw new CommonRefactoringUtil.RefactoringErrorHintException(message);\n  }\n\n  @Override\n  public boolean isAvailableForQuickList(@NotNull Editor editor, @NotNull PsiFile file, @NotNull DataContext dataContext) {\n    PsiElement caretElement = BaseRefactoringAction.getElementAtCaret(editor, file);\n    return MethodUtils.getJavaMethodFromHeader(caretElement) != null;\n  }\n\n  static @NlsContexts.DialogTitle String getRefactoringName() {\n    return JavaRefactoringBundle.message(\"convert.to.instance.method.title\");\n  }\n}\n","sourceCodeStart":114,"sourceCodeEnd":145,"githubUrl":"https://github.com/JetBrains/intellij-community/blob/be881553f2a76ac8b4ea53950d93f0de78295c19/java/java-impl-refactorings/src/com/intellij/refactoring/convertToInstanceMethod/ConvertToInstanceMethodHandler.java#L114-L145","documentation":"ConvertToInstanceMethodHandler throws RefactoringErrorHintException when a static method qualifies for conversion but none of its parameters can serve as the new containing instance. The message is assembled from three cases: no parameters of reference type at all (convertToInstanceMethod.no.parameters.with.reference.type), reference-typed parameters whose classes are all unresolvable (unknown types), or all resolvable classes living outside the project/content roots; if a usable constructor is possible, a hint about a missing default constructor is appended.","triggerScenarios":"Running Convert to Instance Method on 'static void m(int x, long y)' (no reference parameters); on 'static void m(Unknown u)' where the type does not resolve; or on 'static void m(String s)' where java.lang.String resolves but is not in project sources and cannot host the method.","commonSituations":"Utility methods that only take primitives/arrays of primitives; broken classpath so parameter types fail to resolve (red code, missing libraries); parameters typed solely by JDK/third-party classes that the refactoring cannot modify.","solutions":["Add or select a parameter whose type is a project class (must resolve and be inside project content roots).","Fix unresolved parameter types first: add missing dependencies so the code compiles without red references.","If the only candidate host class is external (JDK/library), the refactoring cannot place a method there — introduce a wrapper parameter of a project type instead.","Where the default-constructor hint is appended, ensure the target class has an accessible no-arg constructor or be ready to create one."],"exampleFix":"// before:\nclass C { static void m(int x) { ... } }\n\n// after:\nclass C { static void m(MyProjectObj o, int x) { ... } }  // conversion target now available","handlingStrategy":"validation","validationCode":"boolean usable = false;\nfor (PsiParameter p : method.getParameterList().getParameters()) {\n  if (p.getType() instanceof PsiClassType ct) {\n    PsiClass c = ct.resolve();\n    if (c != null && !(c instanceof PsiTypeParameter) && isInsideProjectSources(c)) usable = true;\n  }\n}\nif (!usable) { /* do not invoke the refactoring; explain why */ }","typeGuard":null,"tryCatchPattern":"try {\n  ConvertToInstanceMethodHandler.calculatePossibleInstanceQualifiers(method);\n} catch (CommonRefactoringUtil.RefactoringErrorHintException e) {\n  // message explains: no reference params / unresolved types / classes outside project (+ ctor hint)\n}","preventionTips":["Ensure the method has at least one parameter of a resolvable project-local class type.","Fix red/unresolved code and classpath problems before refactorings."],"tags":["java","intellij","refactoring","instance-method","classpath","precondition"],"backgroundTag":null,"analyzedSha":"be881553f2a76ac8b4ea53950d93f0de78295c19","analyzedAt":"2026-08-14T14:13:06.425Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}