{"record":{"id":"8a8c79fabff3d6a7","repo":"apache/flink","slug":"invalid-pojo-field-reference","errorCode":null,"errorMessage":"Invalid POJO field reference \"{}\".","messagePattern":"Invalid POJO field reference \"(.+?)\"\\.","errorType":"exception","errorClass":"InvalidFieldReferenceException","httpStatus":null,"severity":"error","filePath":"flink-core/src/main/java/org/apache/flink/api/java/typeutils/PojoTypeInfo.java","lineNumber":158,"sourceCode":"    }\n\n    @Override\n    @PublicEvolving\n    public boolean isSortKeyType() {\n        // Support for sorting POJOs that implement Comparable is not implemented yet.\n        // Since the order of fields in a POJO type is not well defined, sorting on fields\n        //   gives only some undefined order.\n        return false;\n    }\n\n    @Override\n    @PublicEvolving\n    public void getFlatFields(\n            String fieldExpression, int offset, List<FlatFieldDescriptor> result) {\n\n        Matcher matcher = PATTERN_NESTED_FIELDS_WILDCARD.matcher(fieldExpression);\n        if (!matcher.matches()) {\n            throw new InvalidFieldReferenceException(\n                    \"Invalid POJO field reference \\\"\" + fieldExpression + \"\\\".\");\n        }\n\n        String field = matcher.group(0);\n        if (field.equals(ExpressionKeys.SELECT_ALL_CHAR)\n                || field.equals(ExpressionKeys.SELECT_ALL_CHAR_SCALA)) {\n            // handle select all\n            int keyPosition = 0;\n            for (PojoField pField : fields) {\n                if (pField.getTypeInformation() instanceof CompositeType) {\n                    CompositeType<?> cType = (CompositeType<?>) pField.getTypeInformation();\n                    cType.getFlatFields(\n                            String.valueOf(ExpressionKeys.SELECT_ALL_CHAR),\n                            offset + keyPosition,\n                            result);\n                    keyPosition += cType.getTotalFields() - 1;\n                } else {\n                    result.add(","sourceCodeStart":140,"sourceCodeEnd":176,"githubUrl":"https://github.com/apache/flink/blob/2f3c205e9266cb30240eb7f4fdab15cad629a70f/flink-core/src/main/java/org/apache/flink/api/java/typeutils/PojoTypeInfo.java#L140-L176","documentation":"Thrown by PojoTypeInfo.getFlatFields when the fieldExpression string does not match the POJO field-name regex (an identifier starting with a letter, underscore, or '$' — optionally dotted with nested sub-fields — or the '*'/'_' wildcard). The expression is syntactically invalid before any field lookup happens. This is an InvalidFieldReferenceException (extends IllegalArgumentException).","triggerScenarios":"Calling dataStream.keyBy(\"123field\"), keyBy(\"\"), keyBy(\"field-name\"), keyBy(\"a.b.\") (trailing dot), or pojoTypeInfo.getFlatFields(\"a b\") on a POJO-typed stream/dataset. Internally reached via ExpressionKeys(String[], TypeInformation) which trims the expression then calls cType.getFlatFields(keyExpr).","commonSituations":"Developer types a field reference that starts with a digit (valid for Tuple/Row but not POJO), includes hyphens/spaces, has a trailing dot, or passes an empty string. Also occurs when copy-pasting a tuple-style key like 'f0' onto a POJO stream, or when a programmatic field-name source yields a non-identifier value.","solutions":["Correct the field expression to a valid Java identifier that exactly matches a POJO field name (letters, digits, '_', '$'; must start with a letter, '_', or '$').","For nested access use dot-separated identifiers: \"address.city\".","If you meant all fields, use the wildcard \"*\" or \"_\".","Inspect the actual POJO type with TypeInformation.of(MyPojo.class) to confirm available field names."],"exampleFix":"// before\ndataStream.keyBy(\"0fieldName\");\n// after\ndataStream.keyBy(\"fieldName\");","handlingStrategy":"validation","validationCode":"private static final Pattern POJO_FIELD =\n    Pattern.compile(\"[\\\\p{L}_$][\\\\p{L}\\\\p{Digit}_$]*(\\\\..+)?\");\n\nvoid validatePojoFieldExpr(String expr) {\n    if (expr == null || !POJO_FIELD.matcher(expr).matches()) {\n        throw new IllegalArgumentException(\"Invalid POJO field expression: \" + expr);\n    }\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Always verify field expressions are valid Java identifiers before passing to keyBy/getFlatFields.","Use a constants class or enum for field names to avoid typos."],"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"}