Skip to content

[plsql] Parse exception when comparing parenthesized arithmetic expression in WHERE clause #6609

Closed

Description

@rmatamoros

Affects PMD Version:
7.23.0

Description:

A parser exception is thrown on the following line of code:

AND (NVL(ap.cantidad, 0) - NVL(ap.cant_pend_salida, 0)) > 0

If the outer parentheses are removed, the error disappears:

AND NVL(ap.cantidad, 0) - NVL(ap.cant_pend_salida, 0) > 0

Both expressions are valid PL/SQL and semantically equivalent, so the parser should accept the parenthesized form as well.

Exception Stacktrace:

net.sourceforge.pmd.lang.ast.ParseException: Parse exception in file XXX at line 169, column 71: Encountered ")".
Was expecting one of:
    "=" ...
    "<" ...
    "!" ...
    "+" ...
    "-" ...
    "^" ...
    ">" ...
    "OVER" ...
    "WITHIN" ...
    "||" ...
    "IS" ...
	at net.sourceforge.pmd.lang.plsql.ast.PLSQLParserImpl.generateParseException(PLSQLParserImpl.java)
	at net.sourceforge.pmd.lang.plsql.ast.PLSQLParserImpl.jj_consume_token(PLSQLParserImpl.java)
	at net.sourceforge.pmd.lang.plsql.ast.PLSQLParserImpl.ComparisonOp(PLSQLParserImpl.java:13573)
	at net.sourceforge.pmd.lang.plsql.ast.PLSQLParserImpl.ComparisonCondition(PLSQLParserImpl.java:13598)
	at net.sourceforge.pmd.lang.plsql.ast.PLSQLParserImpl.Condition2(PLSQLParserImpl.java:12872)
	at net.sourceforge.pmd.lang.plsql.ast.PLSQLParserImpl.CompoundCondition(PLSQLParserImpl.java:13410)
	at net.sourceforge.pmd.lang.plsql.ast.PLSQLParserImpl.Condition(PLSQLParserImpl.java:12468)
	at net.sourceforge.pmd.lang.plsql.ast.PLSQLParserImpl.CompoundCondition(PLSQLParserImpl.java:13382)
	at net.sourceforge.pmd.lang.plsql.ast.PLSQLParserImpl.Condition(PLSQLParserImpl.java:12468)
	at net.sourceforge.pmd.lang.plsql.ast.PLSQLParserImpl.CompoundCondition(PLSQLParserImpl.java:13431)
	at net.sourceforge.pmd.lang.plsql.ast.PLSQLParserImpl.Condition(PLSQLParserImpl.java:12468)
	at net.sourceforge.pmd.lang.plsql.ast.PLSQLParserImpl.CompoundCondition(PLSQLParserImpl.java:13431)
	at net.sourceforge.pmd.lang.plsql.ast.PLSQLParserImpl.Condition(PLSQLParserImpl.java:12468)
	at net.sourceforge.pmd.lang.plsql.ast.PLSQLParserImpl.CompoundCondition(PLSQLParserImpl.java:13431)
	at net.sourceforge.pmd.lang.plsql.ast.PLSQLParserImpl.Condition(PLSQLParserImpl.java:12468)
	at net.sourceforge.pmd.lang.plsql.ast.PLSQLParserImpl.CompoundCondition(PLSQLParserImpl.java:13431)
	at net.sourceforge.pmd.lang.plsql.ast.PLSQLParserImpl.Condition(PLSQLParserImpl.java:12468)
	at net.sourceforge.pmd.lang.plsql.ast.PLSQLParserImpl.CompoundCondition(PLSQLParserImpl.java:13431)
	at net.sourceforge.pmd.lang.plsql.ast.PLSQLParserImpl.Condition(PLSQLParserImpl.java:12468)
	at net.sourceforge.pmd.lang.plsql.ast.PLSQLParserImpl.CompoundCondition(PLSQLParserImpl.java:13431)
	at net.sourceforge.pmd.lang.plsql.ast.PLSQLParserImpl.Condition(PLSQLParserImpl.java:12468)
	at net.sourceforge.pmd.lang.plsql.ast.PLSQLParserImpl.CompoundCondition(PLSQLParserImpl.java:13431)
	at net.sourceforge.pmd.lang.plsql.ast.PLSQLParserImpl.Condition(PLSQLParserImpl.java:12468)
	at net.sourceforge.pmd.lang.plsql.ast.PLSQLParserImpl.CompoundCondition(PLSQLParserImpl.java:13431)
	at net.sourceforge.pmd.lang.plsql.ast.PLSQLParserImpl.Condition(PLSQLParserImpl.java:12468)
	at net.sourceforge.pmd.lang.plsql.ast.PLSQLParserImpl.WhereClause(PLSQLParserImpl.java:12426)
	at net.sourceforge.pmd.lang.plsql.ast.PLSQLParserImpl.QueryBlock(PLSQLParserImpl.java:11787)
	at net.sourceforge.pmd.lang.plsql.ast.PLSQLParserImpl.Subquery(PLSQLParserImpl.java:11476)
	at net.sourceforge.pmd.lang.plsql.ast.PLSQLParserImpl.MergeStatement(PLSQLParserImpl.java:34400)
	at net.sourceforge.pmd.lang.plsql.ast.PLSQLParserImpl.UnlabelledStatement(PLSQLParserImpl.java:25410)
	at net.sourceforge.pmd.lang.plsql.ast.PLSQLParserImpl.Statement(PLSQLParserImpl.java:26277)
	at net.sourceforge.pmd.lang.plsql.ast.PLSQLParserImpl.ProgramUnit(PLSQLParserImpl.java:7844)
	at net.sourceforge.pmd.lang.plsql.ast.PLSQLParserImpl.DeclarativeUnit(PLSQLParserImpl.java:3799)
	at net.sourceforge.pmd.lang.plsql.ast.PLSQLParserImpl.DeclarativeSection(PLSQLParserImpl.java:3878)
	at net.sourceforge.pmd.lang.plsql.ast.PLSQLParserImpl.PackageBody(PLSQLParserImpl.java:2986)
	at net.sourceforge.pmd.lang.plsql.ast.PLSQLParserImpl.Input(PLSQLParserImpl.java:131)
	at net.sourceforge.pmd.lang.plsql.ast.PLSQLParser.parseImpl(PLSQLParser.java:86)
	at net.sourceforge.pmd.lang.plsql.ast.PLSQLParser.parseImpl(PLSQLParser.java:21)
	at net.sourceforge.pmd.lang.ast.impl.javacc.JjtreeParserAdapter.parse(JjtreeParserAdapter.java:36)
	at net.sourceforge.pmd.lang.impl.PmdRunnable.parse(PmdRunnable.java:112)
	at net.sourceforge.pmd.lang.impl.PmdRunnable.processSource(PmdRunnable.java:132)
	at net.sourceforge.pmd.lang.impl.PmdRunnable.run(PmdRunnable.java:80)
	at java.base/java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:572)
	at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:317)
	at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1144)
	at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:642)
	at java.base/java.lang.Thread.run(Thread.java:1583)

Code Sample demonstrating the issue:

Minimal reproducer (PL/SQL package body containing a MERGE with the offending WHERE condition):

CREATE OR REPLACE PACKAGE BODY test_pkg AS
  PROCEDURE test_proc IS
  BEGIN
    MERGE INTO destino d
    USING (
      SELECT ap.id, ap.cantidad, ap.cant_pend_salida
      FROM   articulos_pend ap
      WHERE  ap.activo = 'S'
      AND    (NVL(ap.cantidad, 0) - NVL(ap.cant_pend_salida, 0)) > 0
    ) src
    ON (d.id = src.id)
    WHEN MATCHED THEN UPDATE SET d.cantidad = src.cantidad;
  END test_proc;
END test_pkg;
/

Steps to reproduce:

  1. Save the snippet above as test_pkg.sql.
  2. Run PMD 7.23.0 against the file:
    pmd check -d test_pkg.sql -R rulesets/plsql/quickstart.xml -f text
    
  3. The parser fails with the stacktrace shown above.

Removing the outer parentheses around the arithmetic expression avoids the error.

Running PMD through: CLI

Environment:

  • PMD 7.23.0
  • JDK: OpenJDK 21
  • OS: Windows 11

Activity

  1. added
    a:bug
    on Apr 20, 2026
  2. added a commit that references this issue on Oct 23, 2026
  3. added this to the 7.29.0 milestone on Oct 23, 2026
  4. added a commit that references this issue on Oct 23, 2026
    c5a0ebf
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

    a:bug

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions