OrderByManager.applyOrderBy ignores nullFirst when ordering by a function
Description
Working with my code, I have found a case, where OrderByManager.applyOrderBy ignores the specified null handling. Ordering is done by the return value of a custom function, The problem is a result of ExpressionUtils.isNullable returning the wrong result. In our case, the ExpressionUtils.isNullable(EntityMetamodel, ConstantifiedJoinNodeAttributeCollector, Map, FunctionExpression) variant returns false, when List<Expression> expressions contains a PathExpression (which is nullable = false) and NumericLiteral which is a constant. The problem is, the function it is analyzing is evaluating the contents of the field pointed by the PathExpression and might return null. And OrderByManager.applyOrderBy ignores null handling if it thinks the function never returns null.
Expected behavior
OrderByManager.applyOrderBy appends NULLS LAST or NULLS FIRST
Actual behavior
OrderByManager.applyOrderBy ignores NULLS caluse.
Environment
Version: 1.6.9 JPA-Provider: 5.6.15.Final DBMS: PostgreSQL 13.11
Could you please attach a reproducer for this problem or at least the query and the model that leads to this?