Available in versions: Dev (3.19) | Latest (3.18)

This is experimental functionality, and as such subject to change. Use at your own risk!

Possibly wrong expressions

Applies to ❌ Open Source Edition   ✅ Express Edition   ✅ Professional Edition   ✅ Enterprise Edition

The SPI method handling this event is possiblyWrongExpression()

Some expressions have a high likelyhood of being wrong, even if they're correct most of the time, or within the domain known by the developer who wrote the expression.

Why is it bad?

Murphy's Law dictates that the slight risk of the expression turning wrong eventually means that it should better be fixed as soon as possible. Various examples of possibly wrong expressions include:

  • MOD(x, 2) = 1 for oddness checks doesn't work for negative numbers. Compare with zero instead: MOD(x, 2) != 0

An example is given here:

// A custom DiagnosticsListener SPI implementation
class PossiblyWrongExpression extends DefaultDiagnosticsListener {
    public void possiblyWrongExpression(DiagnosticsContext ctx) {
        // The statement that is being executed and which has a possibly wrong expression.
        System.out.println("Actual statement: " + ctx.actualStatement());
        // The possibly wrong expression.
        System.out.println("Predicate       : " + ctx.part());

// Configuration is configured with the target DataSource, SQLDialect, etc. for instance Oracle.
try (
    Connection c = DSL.using(configuration.derive(new PossiblyWrongExpression()))
    Statement s = c.createStatement()
) {
    try (ResultSet a = s.executeQuery("SELECT id FROM author WHERE MOD(id, 2) = 1")) {
        while (a.next())


Do you have any feedback about this page? We'd love to hear it!

The jOOQ Logo