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

[plsql] Parsing exception "Less than or equal to/Greater than or equal to" operators in DML statements #3746

Closed
hgodinez89 opened this issue Jan 20, 2022 · 5 comments · Fixed by #3783
Labels
a:bug PMD crashes or fails to analyse a file. in:grammar About the grammar of a lexer or parser, eg, a parse/lex exception
Milestone

Comments

@hgodinez89
Copy link

Affects PMD Version:

This error was testing in the following versions:

  • 6.41.0
  • 6.40.0
  • 6.39.0

Description:

Trying to analyze pl/sql code that has "Less than or equal to/Greater than or equal to" operators (<=; >=), but these operators have a blank space between two characters, for instance > = or < =, PMD raises an exception error indicating "Error while parsing".

Note: This is totally correct in DML statements for Oracle databases engines.

Exception Stacktrace:

net.sourceforge.pmd.PMDException: Error while parsing C:\testfolder\example_procedure.prc
	at net.sourceforge.pmd.SourceCodeProcessor.processSourceCodeWithoutCache(SourceCodeProcessor.java:124)
	at net.sourceforge.pmd.SourceCodeProcessor.processSourceCode(SourceCodeProcessor.java:100)
	at net.sourceforge.pmd.SourceCodeProcessor.processSourceCode(SourceCodeProcessor.java:62)
	at net.sourceforge.pmd.processor.PmdRunnable.call(PmdRunnable.java:85)
	at net.sourceforge.pmd.processor.PmdRunnable.call(PmdRunnable.java:29)
	at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
	at java.base/java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:515)
	at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
	at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)
	at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)
	at java.base/java.lang.Thread.run(Thread.java:834)
Caused by: net.sourceforge.pmd.lang.plsql.ast.ParseException: Encountered " "=" "= "" at line 10, column 23.
Was expecting one of:
    "LOG" ...
    "(" ...
    "REF" ...
    "LAST" ...
    "*" ...
    "+" ...
    "OVER" ...
    "UNBOUNDED" ...
    "PRECEDING" ...
    ...
    "TRIM" ...
	at net.sourceforge.pmd.lang.plsql.ast.PLSQLParser.generateParseException(PLSQLParser.java)
	at net.sourceforge.pmd.lang.plsql.ast.PLSQLParser.jj_consume_token(PLSQLParser.java)
	at net.sourceforge.pmd.lang.plsql.ast.PLSQLParser.UnaryExpression(PLSQLParser.java:41132)
	at net.sourceforge.pmd.lang.plsql.ast.PLSQLParser.MultiplicativeExpression(PLSQLParser.java:40679)
	at net.sourceforge.pmd.lang.plsql.ast.PLSQLParser.AdditiveExpression(PLSQLParser.java:40565)
	at net.sourceforge.pmd.lang.plsql.ast.PLSQLParser.SqlExpression(PLSQLParser.java:13560)
	at net.sourceforge.pmd.lang.plsql.ast.PLSQLParser.ComparisonCondition(PLSQLParser.java:12848)
	at net.sourceforge.pmd.lang.plsql.ast.PLSQLParser.Condition2(PLSQLParser.java:12165)
	at net.sourceforge.pmd.lang.plsql.ast.PLSQLParser.CompoundCondition(PLSQLParser.java:12703)
	at net.sourceforge.pmd.lang.plsql.ast.PLSQLParser.Condition(PLSQLParser.java:11754)
	at net.sourceforge.pmd.lang.plsql.ast.PLSQLParser.CompoundCondition(PLSQLParser.java:12675)
	at net.sourceforge.pmd.lang.plsql.ast.PLSQLParser.Condition(PLSQLParser.java:11754)
	at net.sourceforge.pmd.lang.plsql.ast.PLSQLParser.CompoundCondition(PLSQLParser.java:12697)
	at net.sourceforge.pmd.lang.plsql.ast.PLSQLParser.Condition(PLSQLParser.java:11754)
	at net.sourceforge.pmd.lang.plsql.ast.PLSQLParser.CompoundCondition(PLSQLParser.java:12675)
	at net.sourceforge.pmd.lang.plsql.ast.PLSQLParser.Condition(PLSQLParser.java:11754)
	at net.sourceforge.pmd.lang.plsql.ast.PLSQLParser.CompoundCondition(PLSQLParser.java:12697)
	at net.sourceforge.pmd.lang.plsql.ast.PLSQLParser.Condition(PLSQLParser.java:11754)
	at net.sourceforge.pmd.lang.plsql.ast.PLSQLParser.CompoundCondition(PLSQLParser.java:12697)
	at net.sourceforge.pmd.lang.plsql.ast.PLSQLParser.Condition(PLSQLParser.java:11754)
	at net.sourceforge.pmd.lang.plsql.ast.PLSQLParser.CompoundCondition(PLSQLParser.java:12675)
	at net.sourceforge.pmd.lang.plsql.ast.PLSQLParser.Condition(PLSQLParser.java:11754)
	at net.sourceforge.pmd.lang.plsql.ast.PLSQLParser.CompoundCondition(PLSQLParser.java:12724)
	at net.sourceforge.pmd.lang.plsql.ast.PLSQLParser.Condition(PLSQLParser.java:11754)
	at net.sourceforge.pmd.lang.plsql.ast.PLSQLParser.CompoundCondition(PLSQLParser.java:12724)
	at net.sourceforge.pmd.lang.plsql.ast.PLSQLParser.Condition(PLSQLParser.java:11754)
	at net.sourceforge.pmd.lang.plsql.ast.PLSQLParser.CompoundCondition(PLSQLParser.java:12724)
	at net.sourceforge.pmd.lang.plsql.ast.PLSQLParser.Condition(PLSQLParser.java:11754)
	at net.sourceforge.pmd.lang.plsql.ast.PLSQLParser.WhereClause(PLSQLParser.java:11712)
	at net.sourceforge.pmd.lang.plsql.ast.PLSQLParser.RestOfStatement(PLSQLParser.java:10606)
	at net.sourceforge.pmd.lang.plsql.ast.PLSQLParser.SelectStatement(PLSQLParser.java:28448)
	at net.sourceforge.pmd.lang.plsql.ast.PLSQLParser.CursorUnit(PLSQLParser.java:38877)
	at net.sourceforge.pmd.lang.plsql.ast.PLSQLParser.CursorSpecification(PLSQLParser.java:38919)
	at net.sourceforge.pmd.lang.plsql.ast.PLSQLParser.DeclarativeUnit(PLSQLParser.java:2728)
	at net.sourceforge.pmd.lang.plsql.ast.PLSQLParser.DeclarativeSection(PLSQLParser.java:3154)
	at net.sourceforge.pmd.lang.plsql.ast.PLSQLParser.ProgramUnit(PLSQLParser.java:6446)
	at net.sourceforge.pmd.lang.plsql.ast.PLSQLParser.Global(PLSQLParser.java:879)
	at net.sourceforge.pmd.lang.plsql.ast.PLSQLParser.Input(PLSQLParser.java:153)
	at net.sourceforge.pmd.lang.plsql.PLSQLParser.parse(PLSQLParser.java:61)
	at net.sourceforge.pmd.lang.AbstractParser.doParse(AbstractParser.java:44)
	at net.sourceforge.pmd.SourceCodeProcessor.parse(SourceCodeProcessor.java:136)
	at net.sourceforge.pmd.SourceCodeProcessor.processSource(SourceCodeProcessor.java:200)
	at net.sourceforge.pmd.SourceCodeProcessor.processSourceCodeWithoutCache(SourceCodeProcessor.java:118)
	... 10 more

Code Sample demonstrating the issue:

CREATE OR REPLACE PROCEDURE EXAMPLE_PROCEDURE IS
   --
   l_total_objects NUMBER(10);
   --
BEGIN
   --
   SELECT COUNT(1)
     INTO l_total_objects
     FROM USER_OBJECTS
    WHERE namespace < = 1
       OR namespace > = 0;
   --
   DBMS_OUTPUT.Put_Line('Total number of objects: ' || l_total_objects);
   --
END EXAMPLE_PROCEDURE;

Note: By removing all the blank spaces in the operators in the SELECT statement, you will have no parsing problems.

Steps to reproduce:

  1. Put the code above ("Code Sample demonstrating the issue" section) in example_procedure.prc
  2. Execute PMD analyzer from CLI.
  3. See the error showed in the "Exception Stacktrace" section.

Running PMD through: [CLI]

@hgodinez89 hgodinez89 added the a:bug PMD crashes or fails to analyse a file. label Jan 20, 2022
@oowekyala
Copy link
Member

Do you know if there can be a newline or comments between the two symbols, or just spaces?

@oowekyala oowekyala added the in:grammar About the grammar of a lexer or parser, eg, a parse/lex exception label Jan 28, 2022
@hgodinez89
Copy link
Author

Very good question @oowekyala. Yes, you can. Oracle allows you to put not just spaces, you can put new lines, even comments between the two symbols, and the database engine compiles the routine correctly.

@oowekyala
Copy link
Member

In that case I believe it would be enough to lex <= and such as two tokens < and =. I'm not sure what would be the fallout of this on the parser (lookaheads might need adjustments).

@hgodinez89
Copy link
Author

I am not sure about your comment @oowekyala, is it possible to fix it in PMD parser?

@oowekyala
Copy link
Member

Yes, this was more of a note to myself

oowekyala added a commit to oowekyala/pmd that referenced this issue Feb 12, 2022
…or equal to" operators in DML statements
oowekyala added a commit to oowekyala/pmd that referenced this issue Feb 12, 2022
…or equal to" operators in DML statements
@oowekyala oowekyala added this to the 6.43.0 milestone Feb 12, 2022
oowekyala added a commit to oowekyala/pmd that referenced this issue Feb 13, 2022
…or equal to" operators in DML statements
adangel added a commit to adangel/pmd that referenced this issue Feb 19, 2022
adangel added a commit to adangel/pmd that referenced this issue Feb 19, 2022
[plsql] Fix pmd#3746 - Parsing exception with operators containing spaces pmd#3783
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
a:bug PMD crashes or fails to analyse a file. in:grammar About the grammar of a lexer or parser, eg, a parse/lex exception
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants