{"record":{"id":"962de8f29570ce14","repo":"apache/flink","slug":"unable-to-find-field-in-type","errorCode":null,"errorMessage":"Unable to find field \"{}\" in type {}.","messagePattern":"Unable to find field \"(.+?)\" in type (.+?)\\.","errorType":"exception","errorClass":"InvalidFieldReferenceException","httpStatus":null,"severity":"error","filePath":"flink-core/src/main/java/org/apache/flink/api/java/typeutils/PojoTypeInfo.java","lineNumber":200,"sourceCode":"                keyPosition++;\n            }\n            return;\n        } else {\n            field = matcher.group(1);\n        }\n\n        // get field\n        int fieldPos = -1;\n        TypeInformation<?> fieldType = null;\n        for (int i = 0; i < fields.length; i++) {\n            if (fields[i].getField().getName().equals(field)) {\n                fieldPos = i;\n                fieldType = fields[i].getTypeInformation();\n                break;\n            }\n        }\n        if (fieldPos == -1) {\n            throw new InvalidFieldReferenceException(\n                    \"Unable to find field \\\"\" + field + \"\\\" in type \" + this + \".\");\n        }\n        String tail = matcher.group(3);\n        if (tail == null) {\n            if (fieldType instanceof CompositeType) {\n                // forward offset\n                for (int i = 0; i < fieldPos; i++) {\n                    offset += this.getTypeAt(i).getTotalFields();\n                }\n                // add all fields of composite type\n                ((CompositeType<?>) fieldType).getFlatFields(\"*\", offset, result);\n            } else {\n                // we found the field to add\n                // compute flat field position by adding skipped fields\n                int flatFieldPos = offset;\n                for (int i = 0; i < fieldPos; i++) {\n                    flatFieldPos += this.getTypeAt(i).getTotalFields();\n                }","sourceCodeStart":182,"sourceCodeEnd":218,"githubUrl":"https://github.com/apache/flink/blob/2f3c205e9266cb30240eb7f4fdab15cad629a70f/flink-core/src/main/java/org/apache/flink/api/java/typeutils/PojoTypeInfo.java#L182-L218","documentation":"Thrown by PojoTypeInfo.getFlatFields when the fieldExpression matched the name regex but no PojoField with that exact name exists in the POJO. The expression syntax is valid but the field is simply not present. This is an InvalidFieldReferenceException.","triggerScenarios":"Calling dataStream.keyBy(\"usrName\") when the POJO field is named \"userName\", or keyBy(\"nonExistent\"). Also triggered by pojoTypeInfo.getFlatFields(\"missingField\"). The lookup loop at line 192-198 iterates fields[] and never finds a name match, leaving fieldPos == -1.","commonSituations":"Typo or case mismatch in the key string. The field is private and Flink did not recognize the class as a valid POJO (no public field or getter/setter pair), so the field list is incomplete. The class fell back to being treated as a generic type or POJO with fewer fields than expected after a refactor or rename.","solutions":["Verify the exact field name spelling and case against the POJO class definition.","Ensure the class satisfies POJO requirements: public class, public no-arg constructor, and either public fields or public getter/setter for the field.","Print the resolved type with System.out.println(TypeInformation.of(MyPojo.class)) and check it says 'PojoType' with the expected fields.","If the field was renamed, update all keyBy/groupBy references."],"exampleFix":"// before\npublic class Event { private String userName; }\nstream.keyBy(\"usrName\");\n// after\npublic class Event {\n    public String userName; // or getter+setter\n}\nstream.keyBy(\"userName\");","handlingStrategy":"validation","validationCode":"List<String> pojoFieldNames =\n    ((PojoTypeInfo<?>) TypeInformation.of(MyPojo.class))\n        .getPojoFields().stream()\n        .map(f -> f.getField().getName())\n        .collect(Collectors.toList());\nif (!pojoFieldNames.contains(keyField)) {\n    throw new IllegalArgumentException(\n        \"Field '\" + keyField + \"' not in POJO. Available: \" + pojoFieldNames);\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Log or print TypeInformation.of(MyPojo.class) during development to confirm the POJO fields Flink recognizes.","Ensure POJO classes have public fields or getter/setter pairs so Flink detects all fields.","Use a centralized constants class for field names."],"tags":["pojo","field-reference","type-system","keyby","flink-core"],"backgroundTag":null,"analyzedSha":"2f3c205e9266cb30240eb7f4fdab15cad629a70f","analyzedAt":"2026-08-14T08:48:24.518Z","schemaVersion":2},"datasetVersion":"2026-08-14T10:17:34.591Z"}