Skip to content

NotExpression parsing error #1170

Description

@xsgao-github

Describe the bug
NotExpression is not parsed correctly.

To Reproduce
Steps to reproduce the behavior:

  1. CCJSqlParserUtil.parseCondExpression("not not 1 = 1") generates following objects: NotExpression ( EqualsTo ( NotExpression ( 1 ) = 1 ) ). Instead, the result should be: NotExpression ( NotExpression ( EqualsTo (1 = 1) ) )
  2. CCJSqlParserUtil.parseCondExpression("not not not 1 = 1") yields Exception: net.sf.jsqlparser.JSQLParserException: Encountered unexpected token: "not" "NOT"

Expected behavior
Based on SQL operator precedence and associativity, NOT operator should be evaluated after equal (=), and NOT operator should be evaluated from right to left.

System

  • Database you are using - irrelative
  • Java Version - 1.8
  • JSqlParser version - 4.0

Activity

  1. wumpz commented on Apr 28, 2021

    @wumpz
    Member

    You are right, that not expressions are not truly hierarchical handled by JSqlParser. This would lead to heavy grammar refactoring, I think.

    Is this a pressing feature you need?

  2. fudianchn commented on Sep 6, 2026

    @fudianchn
    Contributor

    Fixed in #2556.

    Root cause: Condition() in JSqlParserCC.jjt consumed at most one leading NOT / ! token. A second one leaked into PrimaryExpression() and attached to the left operand, so not not 1 = 1 parsed as NOT (NOT 1) = 1 instead of NOT (NOT (1 = 1)), and a third one raised the reported ParseException. The prefix is now a loop that wraps one NotExpression per token, leftmost token outermost.

    Both reported cases still reproduce on current master and are fixed by the PR; adjacent single-NOT forms (NOT a LIKE, NOT a IN, value-position a = NOT 1, ...) produce identical trees as before.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions