{"record":{"id":"d6ef577743c7b456","repo":"JetBrains/intellij-community","slug":"changesignature-contract-converter-parameter-remov","errorCode":"changeSignature.contract.converter.parameter.removed","errorMessage":"Parameter '{0}' was deleted, but contract clause '{1}' depends on it","messagePattern":"Parameter '(.+?)' was deleted, but contract clause '(.+?)' depends on it","errorType":"exception","errorClass":"ContractConversionException","httpStatus":null,"severity":"error","filePath":"java/java-impl/src/com/intellij/refactoring/changeSignature/ContractConverter.java","lineNumber":79,"sourceCode":"      result.add(convertContract(contract, newToOldIndex, oldToNewIndex, oldParameterNames));\n    }\n    if (result.equals(contracts)) return annotation;\n    return JavaMethodContractUtil.updateContract(annotation, result);\n  }\n\n  private static @NotNull StandardMethodContract convertContract(@NotNull StandardMethodContract contract,\n                                                                 int @NotNull [] newToOldIndex,\n                                                                 int @NotNull [] oldToNewIndex,\n                                                                 String @NotNull [] oldParameterNames) throws ContractConversionException {\n    if (contract.getParameterCount() != oldToNewIndex.length) {\n      // invalid contract\n      throw new ContractConversionException(JavaRefactoringBundle.message(\"changeSignature.contract.converter.invalid.clause\", contract));\n    }\n    for (int i = 0; i < contract.getParameterCount(); i++) {\n      if (contract.getParameterConstraint(i) != StandardMethodContract.ValueConstraint.ANY_VALUE && oldToNewIndex[i] == -1) {\n        String paramRemovedMessage = JavaRefactoringBundle.message(\"changeSignature.contract.converter.parameter.removed\",\n                                                                   oldParameterNames[i], contract);\n        throw new ContractConversionException(paramRemovedMessage);\n      }\n    }\n    StandardMethodContract.ValueConstraint[] newConstraints = IntStreamEx.of(newToOldIndex)\n                                                                         .mapToObj(idx -> idx == -1 ? StandardMethodContract.ValueConstraint.ANY_VALUE : contract.getParameterConstraint(idx))\n                                                                         .toArray(StandardMethodContract.ValueConstraint.class);\n    ContractReturnValue returnValue = contract.getReturnValue();\n    if (returnValue instanceof ContractReturnValue.ParameterReturnValue) {\n      int oldIndex = ((ContractReturnValue.ParameterReturnValue)returnValue).getParameterNumber();\n      if (oldIndex >= contract.getParameterCount()) {\n        String errorRefMessage = JavaRefactoringBundle.message(\"changeSignature.contract.converter.invalid.return.reference\", returnValue);\n        throw new ContractConversionException(errorRefMessage);\n      }\n      int index = oldToNewIndex[oldIndex];\n      if (index == -1) {\n        String paramRemovedMessage = JavaRefactoringBundle.message(\"changeSignature.contract.converter.return.parameter.removed\",\n                                                                   oldParameterNames[oldIndex], contract);\n        throw new ContractConversionException(paramRemovedMessage);\n      }","sourceCodeStart":61,"sourceCodeEnd":97,"githubUrl":"https://github.com/JetBrains/intellij-community/blob/be881553f2a76ac8b4ea53950d93f0de78295c19/java/java-impl/src/com/intellij/refactoring/changeSignature/ContractConverter.java#L61-L97","documentation":"Thrown by the private convertContract in ContractConverter when a parameter that a contract clause constrains (constraint != ANY_VALUE, i.e. not '_') is removed by the Change Signature operation (oldToNewIndex[i] == -1). Dropping the parameter would silently invalidate the clause's meaning, so the refactoring refuses to proceed.","triggerScenarios":"Change Signature removing a parameter that appears with a real constraint (null, !null, true, false) in some @Contract clause; e.g. deleting parameter 's' from @Contract(\"null -> fail\") boolean f(String s).","commonSituations":"Cleaning up 'unused' parameters that are actually load-bearing for nullability contracts; API slimming on annotated public methods; batch refactor scripts deleting parameters without checking annotations.","solutions":["Instead of deleting the parameter, keep it or replace its constraint with '_' only after you delete the parameter — but the IDE requires the clause not depend on it, so first restructure the logic so the constraint is unnecessary.","Split the refactoring: first edit @Contract manually to remove dependence on that parameter (change its constraint to '_'), then run Change Signature to delete the parameter.","Alternatively delete the whole @Contract annotation if it is no longer meaningful after the parameter removal."],"exampleFix":"// before: deleting 's' via Change Signature throws\n@Contract(\"null -> fail\")\nvoid f(String s) { ... }\n// after: drop the constraint first, then delete the parameter\n// step 1: @Contract(\" -> fail\") void f(String s) -> simplify to no contract, or keep param","handlingStrategy":"validation","validationCode":"// before deleting parameter i, check no clause constrains it\nfor (StandardMethodContract c : StandardMethodContract.parseContract(contractText)) {\n  if (c.getParameterConstraint(i) != StandardMethodContract.ValueConstraint.ANY_VALUE) {\n    // clause depends on the parameter to be deleted; adjust contract first\n  }\n}","typeGuard":null,"tryCatchPattern":"try { ContractConverter.convertContract(method, info); } catch (ContractConversionException e) { /* relax the constraint to '_' or drop the annotation, then delete the parameter */ }","preventionTips":["Before removing a parameter, scan @Contract clauses for non-'_' constraints on it.","Treat constrained parameters as API surface; they are observable via the contract.","Prefer changing the constraint to '_' manually in the editor before running Change Signature."],"tags":["java","refactoring","change-signature","contract-annotation","parameter-removal"],"backgroundTag":null,"analyzedSha":"be881553f2a76ac8b4ea53950d93f0de78295c19","analyzedAt":"2026-08-14T14:13:06.425Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}