Skip to content

[CALCITE-7772] ModelHandler.addFunctions should defer UDF class initialization until after shape validation - #5255

Open
rubenada wants to merge 1 commit into
apache:mainfrom
rubenada:CALCITE-7772
Open

[CALCITE-7772] ModelHandler.addFunctions should defer UDF class initialization until after shape validation#5255
rubenada wants to merge 1 commit into
apache:mainfrom
rubenada:CALCITE-7772

Conversation

@rubenada

Copy link
Copy Markdown
Contributor

Jira Link

CALCITE-7772

Changes Proposed

Minor improvement.

ModelHandler.addFunctions(...) currently loads the UDF class (already controlled by a ClassNameFilter allowlist/denylist) named in the model with the single-argument Class.forName(className), which uses initialize=true. Only after the class object is returned do the shape-check helpers (TableFunctionImpl.create, TableMacroImpl.create, ScalarFunctionImpl.create / functions, AggregateFunctionImpl.create) decide whether the class is usable as a function, and if none of them accepts it, addFunctions throws "Not a valid function class: ..." at the end of the method. That ordering means the class's static initializer runs even when the class turns out to be the wrong shape, which can be avoided. This will keep allowlist guarantee at "these classes may be used as functions", not "these classes' static initializers may be run at will".

Comment thread core/src/main/java/org/apache/calcite/model/ModelHandler.java
@sonarqubecloud

Copy link
Copy Markdown

@rubenada rubenada added the LGTM-will-merge-soon Overall PR looks OK. Only minor things left. label Sep 14, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

LGTM-will-merge-soon Overall PR looks OK. Only minor things left.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants