{"record":{"id":"625f8b4c850f0c71","repo":"JetBrains/intellij-community","slug":"changesignature-contract-converter-definition-erro","errorCode":"changeSignature.contract.converter.definition.error","errorMessage":"Error in contract definition: {0}","messagePattern":"Error in contract definition: (.+?)","errorType":"exception","errorClass":"ContractConversionException","httpStatus":null,"severity":"error","filePath":"java/java-impl/src/com/intellij/refactoring/changeSignature/ContractConverter.java","lineNumber":53,"sourceCode":"    if (AnnotationUtil.isExternalAnnotation(annotation)) {\n      throw new ContractConversionException(JavaRefactoringBundle.message(\"changeSignature.contract.converter.external.annotations\"));\n    }\n    if (annotation.getOwner() != method.getModifierList()) {\n      throw new ContractInheritedException();\n    }\n    if (annotation.findDeclaredAttributeValue(MutationSignature.ATTR_MUTATES) != null) {\n      throw new ContractConversionException(JavaRefactoringBundle.message(\"changeSignature.contract.converter.mutation.contract\"));\n    }\n    String text = AnnotationUtil.getStringAttributeValue(annotation, null);\n    List<StandardMethodContract> contracts = Collections.emptyList();\n    if (text != null) {\n      try {\n        contracts = StandardMethodContract.parseContract(text);\n      }\n      catch (StandardMethodContract.ParseException exception) {\n        String definitionError = JavaRefactoringBundle.message(\"changeSignature.contract.converter.definition.error\",\n                                                               exception.getMessage());\n        throw new ContractConversionException(definitionError);\n      }\n    }\n    int[] newToOldIndex = StreamEx.of(newParameters).mapToInt(ParameterInfo::getOldIndex).toArray();\n    int[] oldToNewIndex = reverseIndex(oldParameterNames.length, newToOldIndex);\n\n    List<StandardMethodContract> result = new ArrayList<>();\n    for (StandardMethodContract contract : contracts) {\n      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) {","sourceCodeStart":35,"sourceCodeEnd":71,"githubUrl":"https://github.com/JetBrains/intellij-community/blob/be881553f2a76ac8b4ea53950d93f0de78295c19/java/java-impl/src/com/intellij/refactoring/changeSignature/ContractConverter.java#L35-L71","documentation":"Thrown by ContractConverter.convertContract when the inline @Contract value cannot be parsed by StandardMethodContract.parseContract. The annotation text is syntactically invalid as a contract expression, so conversion is impossible; the underlying ParseException message is embedded. This indicates the annotation value itself is malformed, independent of the refactoring.","triggerScenarios":"Refactoring a method with @Contract(\"foo -> bar\") (unknown constraint names), @Contract(\"null -> new\") (bad return value), unbalanced '->', wrong clause separator ';', or wrong arity like 'null, null -> true; true, null -> false' with mismatched parameter counts.","commonSituations":"Typos in hand-written contract strings; contracts written for a different parameter count after earlier edits; copy-paste from documentation with wrong clause syntax; inspection warnings ignored before running the refactoring.","solutions":["Fix the @Contract value so every clause is '<constraint,constraint,...> -> <return>' with constraint names from StandardMethodContract (null, !null, true, false, _, fail, new, this, paramN) and semicolons between clauses.","Ensure the number of comma-separated constraints equals the method's parameter count in each clause.","Let the IDE's '@Contract syntax error' inspection highlight the problem first, then rerun Change Signature."],"exampleFix":"// before\n@Contract(\"nul -> false\")\nboolean check(String s) { ... }\n// after\n@Contract(\"null -> false\")\nboolean check(@Nullable String s) { ... }","handlingStrategy":"validation","validationCode":"String text = AnnotationUtil.getStringAttributeValue(annotation, null);\nif (text != null) {\n  try { StandardMethodContract.parseContract(text); }\n  catch (StandardMethodContract.ParseException e) { /* annotation is malformed; fix before refactoring */ }\n}","typeGuard":null,"tryCatchPattern":"try { ContractConverter.convertContract(method, info); } catch (ContractConversionException e) { /* message embeds parse error; fix the @Contract string, then re-run */ }","preventionTips":["Enable and heed the '@Contract' syntax inspection; never leave red annotations in code.","Memorize clause grammar: constraints (null,!null,true,false,_,fail,new,this,paramN) comma-separated per parameter, '-> return', clauses joined by ';'.","After changing any method signature, re-read its @Contract and update arity/constraints."],"tags":["java","refactoring","change-signature","contract-annotation","syntax"],"backgroundTag":null,"analyzedSha":"be881553f2a76ac8b4ea53950d93f0de78295c19","analyzedAt":"2026-08-14T14:13:06.425Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}