{"record":{"id":"65dd1f9048b682b1","repo":"hibernate/hibernate-orm","slug":"passed-selectionexpression-for-function-return-c","errorCode":null,"errorMessage":"Passed `selectionExpression` for function return cannot be null","messagePattern":"Passed `selectionExpression` for function return cannot be null","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"hibernate-core/src/main/java/org/hibernate/query/sqm/produce/function/internal/SetReturningFunctionTypeResolverBuilder.java","lineNumber":56,"sourceCode":"\t}\n\n\t@Override\n\tpublic SetReturningFunctionTypeResolverBuilder invariant(String component, BasicType<?> invariantType) {\n\t\treturn invariant( component, invariantType, component );\n\t}\n\n\t@Override\n\tpublic SetReturningFunctionTypeResolverBuilder useArgType(String component, int argPosition) {\n\t\treturn useArgType( component, argPosition, component );\n\t}\n\n\t@Override\n\tpublic SetReturningFunctionTypeResolver.Builder invariant(String component, BasicTypeReference<?> invariantType, String selectionExpression) {\n\t\tif ( invariantType == null ) {\n\t\t\tthrow new IllegalArgumentException( \"Passed `invariantType` for function return cannot be null\" );\n\t\t}\n\t\tif ( selectionExpression == null ) {\n\t\t\tthrow new IllegalArgumentException( \"Passed `selectionExpression` for function return cannot be null\" );\n\t\t}\n\t\treturn withComponent( component, new BasicTypeReferenceTypeResolver( component, selectionExpression, invariantType ) );\n\t}\n\n\t@Override\n\tpublic SetReturningFunctionTypeResolverBuilder invariant(String component, BasicType<?> invariantType, String selectionExpression) {\n\t\tif ( invariantType == null ) {\n\t\t\tthrow new IllegalArgumentException( \"Passed `invariantType` for function return cannot be null\" );\n\t\t}\n\t\tif ( selectionExpression == null ) {\n\t\t\tthrow new IllegalArgumentException( \"Passed `selectionExpression` for function return cannot be null\" );\n\t\t}\n\t\treturn withComponent( component, new BasicTypeTypeResolver( component, selectionExpression, invariantType ) );\n\t}\n\n\t@Override\n\tpublic SetReturningFunctionTypeResolverBuilder useArgType(String component, int argPosition, String selectionExpression) {\n\t\tif ( selectionExpression == null ) {","sourceCodeStart":38,"sourceCodeEnd":74,"githubUrl":"https://github.com/hibernate/hibernate-orm/blob/fad1729dce015f908198d57a8d80274a30f905a5/hibernate-core/src/main/java/org/hibernate/query/sqm/produce/function/internal/SetReturningFunctionTypeResolverBuilder.java#L38-L74","documentation":"The same invariant(component, BasicTypeReference, selectionExpression) overload also requires a non-null selectionExpression - the output column name/alias the function's row component carries in the result set. Null is rejected immediately with IllegalArgumentException at registration time. The selectionExpression makes each returned column addressable, so it cannot be defaulted silently.","triggerScenarios":"builder.invariant(\"value\", StandardBasicTypes.STRING, null) - the third argument was omitted or never set when defining a set-returning function's row component.","commonSituations":"Chained builder calls where the alias argument was dropped during refactoring; assuming the 3-arg overload derives the alias from the component name (only the 2-arg overloads do that).","solutions":["Pass an explicit selection expression: builder.invariant(\"value\", StandardBasicTypes.STRING, \"value\").","Use the shorter overload invariant(component, type), which defaults selectionExpression to the component name.","Guard with Objects.requireNonNull(selectionExpression, ...) before the call."],"exampleFix":"// before\nbuilder.invariant(\"value\", StandardBasicTypes.STRING, null);\n\n// after\nbuilder.invariant(\"value\", StandardBasicTypes.STRING, \"value\");\n// or let it default to the component name\nbuilder.invariant(\"value\", StandardBasicTypes.STRING);","handlingStrategy":"validation","validationCode":"String selection = Objects.requireNonNullElse(selectionExpression, component);\nbuilder.invariant(component, type, selection);","typeGuard":null,"tryCatchPattern":"try {\n    builder.invariant(component, type, selection);\n} catch (IllegalArgumentException e) {\n    throw new IllegalStateException(\"Incomplete set-returning function definition: \" + e.getMessage(), e);\n}","preventionTips":["Prefer the 2-arg overloads that default selectionExpression to the component name.","Never omit the third argument of a 3-arg overload; use the shorter overload instead.","Validate config-derived aliases before building."],"tags":["hibernate","set-returning-function","null-check","function-registration","bootstrap"],"backgroundTag":"illegal-argument-null-parameter","analyzedSha":"fad1729dce015f908198d57a8d80274a30f905a5","analyzedAt":"2026-08-22T04:13:57.527Z","schemaVersion":2},"datasetVersion":"2026-08-22T09:17:25.309Z"}