Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: EXPOSED-263 Null arg parameter in exec() throws if logger enabled #1973

Merged
merged 1 commit into from
Jan 23, 2024

Conversation

bog-walk
Copy link
Member

The type for exec() parameterized arguments is declared as args: Iterable<Pair<IColumnType, Any?>>, so passing null as the second element correctly sets the statement parameter to SQL NULL.
But if a logger is enabled, this exception is thrown instead:

java.lang.IllegalStateException: NULL in non-nullable column.

This is because all IColumnType default to being not nullable and fail the check in ColumnType.valueToString() when attempting to parse the null parameter value.

This exception can be avoided by always providing SQL NULL directly, via Op.nullOp<T>().
But given the type hints, the accepted parameter values should match what would be accepted by any other DSL statement.

Even if the column in the Exposed table object is declared as being nullable(), the column type in exec() has no knowledge of this because it is meant to accept plain SQL using an anonymous Statement object.
This fix sets the nullable parameter of any column type in args to true so that no exception will be thrown when the logger invokes valueToString().

The type for exec() parameterized arguments is declared as args: Iterable<Pair<IColumnType, Any?>>,
so passing null as the second element correctly sets the statement parameter to SQL NULL.
But if a logger is enabled, this exception is thrown:
java.lang.IllegalStateException: NULL in non-nullable column.
This is because all IColumnType default to being not nullable and fail the check
in `ColumnType.valueToString()` when attempting to parse the parameter value.

This exception can be avoided by always providing SQL NULL directly, via Op.nullOp<T>().
But given the type hints, the accepted parameter values should match what would
be accepted by any other DSL statement.

Even if the column in the Exposed table object is declared as being `nullable()`,
the column type in `exec()` has no knowledge of this because it is meant to accept
plain SQL using an anonymous Statement object.
This fix sets the nullable parameter of any column type in args to true so that
no exception will be thrown when the logger invokes valueToString().
@bog-walk bog-walk requested review from e5l and joc-a January 22, 2024 18:26
Copy link
Member

@e5l e5l left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

@bog-walk bog-walk merged commit 0a37dda into main Jan 23, 2024
5 checks passed
@bog-walk bog-walk deleted the bog-walk/fix-exec-null-log branch January 23, 2024 14:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants