{"record":{"id":"0a4351baa201326b","repo":"apache/beam","slug":"java-bean-s-contains-a-setter-for-field-s-that-has-a","errorCode":null,"errorMessage":"Java Bean '%s' contains a setter for field '%s' that has a mismatching type. %s","messagePattern":"Java Bean '(.+?)' contains a setter for field '(.+?)' that has a mismatching type\\. (.+?)","errorType":"exception","errorClass":"RuntimeException","httpStatus":null,"severity":"error","filePath":"sdks/java/core/src/main/java/org/apache/beam/sdk/schemas/utils/JavaBeanUtils.java","lineNumber":116,"sourceCode":"      Integer integer = i;\n      if (setterMap.put(schema.getField(integer).getName(), setters.get(integer)) != null) {\n        throw new IllegalStateException(\"Duplicate key\");\n      }\n    }\n\n    for (FieldValueTypeInformation type : getters) {\n      FieldValueTypeInformation setterType = setterMap.get(type.getName());\n      Method m =\n          Preconditions.checkArgumentNotNull(type.getMethod(), GETTER_WITH_NULL_METHOD_ERROR);\n      if (setterType == null) {\n        throw new RuntimeException(\n            String.format(\n                \"Java Bean '%s' contains a getter for field '%s', but does not contain a matching\"\n                    + \" setter. %s\",\n                m.getDeclaringClass(), type.getName(), CONSTRUCTOR_HELP_STRING));\n      }\n      if (!type.getType().equals(setterType.getType())) {\n        throw new RuntimeException(\n            String.format(\n                \"Java Bean '%s' contains a setter for field '%s' that has a mismatching type. %s\",\n                m.getDeclaringClass(), type.getName(), CONSTRUCTOR_HELP_STRING));\n      }\n      if (!type.isNullable() == setterType.isNullable()) {\n        throw new RuntimeException(\n            String.format(\n                \"Java Bean '%s' contains a setter for field '%s' that has a mismatching nullable\"\n                    + \" attribute. %s\",\n                m.getDeclaringClass(), type.getName(), CONSTRUCTOR_HELP_STRING));\n      }\n    }\n  }\n\n  // Static ByteBuddy instance used by all helpers.\n  private static final ByteBuddy BYTE_BUDDY = new ByteBuddy();\n\n  private static final Map<TypeDescriptorWithSchema<?>, List<FieldValueTypeInformation>>","sourceCodeStart":98,"sourceCodeEnd":134,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/java/core/src/main/java/org/apache/beam/sdk/schemas/utils/JavaBeanUtils.java#L98-L134","documentation":"validateJavaBean compares each getter's inferred type with the corresponding setter's parameter type. If they differ, Beam cannot round-trip the property through a schema field and throws RuntimeException. Consistent getter/setter types are required for a valid schema-backed bean.","triggerScenarios":"Getter returns String but setter takes CharSequence/Object; getter returns int but setter takes Integer; generic getter returning T with a setter of a concrete type; differing nullability wrappers in types Beam resolves distinctly.","commonSituations":"Hand-written beans where a refactor changed only one of getter/setter; Lombok generating a setter type different from a hand-written getter (e.g. fluent builder setters returning this); boxing mismatches (Integer vs int usually OK, but boxed vs unboxed logical types are not).","solutions":["Make the setter parameter type exactly match the getter return type.","If the setter intentionally accepts a wider type, narrow it or add a matching-typed setter.","Regenerate accessors with Lombok (@Data) so they are consistent.","Check that generic types are concrete — resolve type variables to fixed classes."],"exampleFix":"// before\npublic String getName() {...} public void setName(CharSequence n) {...}\n// after\npublic String getName() {...} public void setName(String n) {...}","handlingStrategy":"validation","validationCode":"for (PropertyDescriptor pd : Introspector.getBeanInfo(MyBean.class).getPropertyDescriptors()) { if (pd.getReadMethod() != null && pd.getWriteMethod() != null && !pd.getReadMethod().getReturnType().equals(pd.getWriteMethod().getParameterTypes()[0])) throw new IllegalStateException(pd.getName() + \" accessor types differ\"); }","typeGuard":null,"tryCatchPattern":"try { Schema.of(MyBean.class); } catch (RuntimeException e) { if (e.getMessage().contains(\"mismatching type\")) { /* align getter/setter types */ } throw e; }","preventionTips":["Generate accessors together (Lombok @Data or IDE generate both).","Grep/CI-check that getter return types equal setter parameter types.","Resolve generic property types to concrete classes."],"tags":["java","javabean","schema","type-mismatch"],"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"}