{"record":{"id":"70698b2c32a2959e","repo":"apache/beam","slug":"type-mismatch-between-getter-and-setter-methods-for-property","errorCode":null,"errorMessage":"Type mismatch between getter and setter methods for property [%s]. Getter is of type [%s] whereas setter is of type [%s].","messagePattern":"Type mismatch between getter and setter methods for property \\[(.+?)\\]\\. Getter is of type \\[(.+?)\\] whereas setter is of type \\[(.+?)\\]\\.","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"sdks/java/core/src/main/java/org/apache/beam/sdk/options/PipelineOptionsFactory.java","lineNumber":921,"sourceCode":"\n    // Add the remaining getters with missing setters.\n    for (Map.Entry<String, Method> getterToMethod : propertyNamesToGetters.entrySet()) {\n      descriptors.add(\n          new PropertyDescriptor(getterToMethod.getKey(), getterToMethod.getValue(), null));\n    }\n    return descriptors;\n  }\n\n  private static class TypeMismatch {\n    private String propertyName;\n    private Type getterPropertyType;\n    private Type setterPropertyType;\n  }\n\n  private static void throwForTypeMismatches(List<TypeMismatch> mismatches) {\n    if (mismatches.size() == 1) {\n      TypeMismatch mismatch = mismatches.get(0);\n      throw new IllegalArgumentException(\n          String.format(\n              \"Type mismatch between getter and setter methods for property [%s]. \"\n                  + \"Getter is of type [%s] whereas setter is of type [%s].\",\n              mismatch.propertyName, mismatch.getterPropertyType, mismatch.setterPropertyType));\n    } else if (mismatches.size() > 1) {\n      StringBuilder builder =\n          new StringBuilder(\"Type mismatches between getters and setters detected:\");\n      for (TypeMismatch mismatch : mismatches) {\n        builder.append(\n            String.format(\n                \"%n  - Property [%s]: Getter is of type [%s] whereas setter is of type [%s].\",\n                mismatch.propertyName,\n                mismatch.getterPropertyType.toString(),\n                mismatch.setterPropertyType.toString()));\n      }\n      throw new IllegalArgumentException(builder.toString());\n    }\n  }","sourceCodeStart":903,"sourceCodeEnd":939,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/java/core/src/main/java/org/apache/beam/sdk/options/PipelineOptionsFactory.java#L903-L939","documentation":"PipelineOptionsFactory validates that each interface method pair (getter/setter) on a PipelineOptions subinterface has matching generic return/parameter types. When exactly one property has mismatched getter and setter types, throwForTypeMismatches throws an IllegalArgumentException naming the property and both types.","triggerScenarios":"Defining a PipelineOptions interface with e.g. int getFoo() but void setFoo(String value), or a getter returning a subtype while the setter takes a supertype.","commonSituations":"Refactoring an option type in one method but not the other, hand-writing setters without IDE assistance, or copy-pasting option interfaces between classes.","solutions":["Make the setter parameter type exactly match the getter return type for the named property.","Regenerate the setter using the IDE's 'generate setter' from the getter.","Check the generic type parameters (e.g. Map<String, List<T>>) are identical on both methods.","If both methods are intentional but different names were intended, rename the methods so they don't form a mismatched property pair."],"exampleFix":"// before\nString getOutputPath();\nvoid setOutputPath(Path path);\n// after\nString getOutputPath();\nvoid setOutputPath(String path);","handlingStrategy":"validation","validationCode":"assert optionsIface.getMethod(\"getFoo\").getGenericReturnType().equals(optionsIface.getMethod(\"setFoo\", String.class).getGenericParameterTypes()[0]);","typeGuard":null,"tryCatchPattern":"try { PipelineOptionsFactory.as(MyOptions.class); } catch (IllegalArgumentException e) { throw new IllegalStateException(\"bad options interface: \" + e.getMessage(), e); }","preventionTips":["Generate setters from getters with the IDE","Keep getter/setter pairs adjacent in options interfaces","Add an early test that instantiates each options interface via the factory"],"tags":["apache-beam","type-mismatch","options-interface"],"backgroundTag":"type-mismatch","analyzedSha":"12126d8942aaf848030c478b4c6a28c6af861c66","analyzedAt":"2026-09-13T01:50:10.254Z","contentChangedAt":"2026-09-13T01:50:10.254Z","schemaVersion":2},"datasetVersion":"2026-09-20T03:17:13.778Z"}