GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — [plsql] Parsing exception EXECUTE IMMEDIATE l_sql BULK COLLECT INTO statement · Issue #3687 · pmd/pmd

[plsql] Parsing exception EXECUTE IMMEDIATE l_sql BULK COLLECT INTO statement #3687

New issue
Copy link
New issue
Copy link
Closed
#3935
Closed
[plsql] Parsing exception EXECUTE IMMEDIATE l_sql BULK COLLECT INTO statement#3687
#3935
Copy link
Assignees
Scrsloota
Labels
a:bugPMD crashes or fails to analyse a file.
Milestone
6.45.0

Description

@hgodinez89
hgodinez89
opened on Dec 14, 2021
Issue body actions

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 EXECUTE IMMEDIATE l_sql BULK COLLECT INTO statement, PMD raises an exception error that indicates "Error while parsing".

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 " "BULK" "BULK "" at line 26, column 36.
Was expecting one of:
    ";" ...
    "||" ...
    "INTO" ...
    "RETURN" ...
    "RETURNING" ...
    "USING" ...
	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.EmbeddedSqlStatement(PLSQLParser.java:36684)
	at net.sourceforge.pmd.lang.plsql.ast.PLSQLParser.UnlabelledStatement(PLSQLParser.java:23959)
	at net.sourceforge.pmd.lang.plsql.ast.PLSQLParser.Statement(PLSQLParser.java:24754)
	at net.sourceforge.pmd.lang.plsql.ast.PLSQLParser.ProgramUnit(PLSQLParser.java:6835)
	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
   --
   TYPE r_data IS RECORD(
      data_key         NUMBER(10),
      data_description VARCHAR2(100));
   --
   TYPE t_data IS TABLE OF r_data INDEX BY BINARY_INTEGER;
   --
   l_data t_data;
   l_sql  VARCHAR2(500);
   --
BEGIN
   --
   l_sql := 'SELECT 1, ' || CHR(39) || 'First key' || CHR(39) || 
             ' FROM DUAL '||
            'UNION ALL '||
            'SELECT 2, ' || CHR(39) || 'Second key ' || CHR(39) || 
             ' FROM DUAL';
   --
   EXECUTE IMMEDIATE l_sql BULK COLLECT
      INTO l_data;
   --
   FOR x IN l_data.first .. l_data.last LOOP
      DBMS_OUTPUT.Put_Line(l_data(x).data_key);
      DBMS_OUTPUT.Put_Line(l_data(x).data_description);
   END LOOP;
   --
END EXAMPLE_PROCEDURE;

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]

Activity

  1. hgodinez89
    added
    a:bugPMD crashes or fails to analyse a file.
    on Dec 14, 2021
  2. Scrsloota commented on Apr 22, 2022

    @Scrsloota
    Scrsloota
    on Apr 22, 2022
    Contributor
    More actions

    I'm new here, and I want to contribute to this. Could you please assign this to me? 😊

  3. adangel
    assigned
    Scrsloota
    on Apr 22, 2022
  4. adangel commented on Apr 22, 2022

    @adangel
    adangel
    on Apr 22, 2022
    Member
    More actions

    @Scrsloota Thanks for looking into this!

  5. Scrsloota
    removed their assignment
    on Apr 23, 2022
  6. Scrsloota commented on Apr 23, 2022

    @Scrsloota
    Scrsloota
    on Apr 23, 2022
    Contributor
    More actions

    I am really sorry for this!😭 I clicked the wrong place and removed the assgin. Could you please assign this to me again?🥺

  7. Scrsloota commented on Apr 23, 2022

    @Scrsloota
    Scrsloota
    on Apr 23, 2022
    Contributor
    More actions
    • Considering the sample code, the main problem happens in:

      BEGIN
         --
         l_sql := 'SELECT 1, ' || CHR(39) || 'First key' || CHR(39) || 
                   ' FROM DUAL '||
                  'UNION ALL '||
                  'SELECT 2, ' || CHR(39) || 'Second key ' || CHR(39) || 
                   ' FROM DUAL';
         --
         EXECUTE IMMEDIATE l_sql BULK COLLECT
            INTO l_data;
         --
         FOR x IN l_data.first .. l_data.last LOOP
            DBMS_OUTPUT.Put_Line(l_data(x).data_key);
            DBMS_OUTPUT.Put_Line(l_data(x).data_description);
         END LOOP;
         --
      END EXAMPLE_PROCEDURE;
      
    • The exception message reported in this statement :

      EXECUTE IMMEDIATE l_sql BULK COLLECT
            INTO l_data;
      
    • The related BNF for parsing the EXECUTE IMMEDIATE is :

      ASTEmbeddedSqlStatement EmbeddedSqlStatement()  :
      {}
      {
         <EXECUTE> <IMMEDIATE> StringExpression()
      	[ <INTO> Name() ("," Name())* ]
      	[ UsingClause() ]
      	[ ( <RETURN> | <RETURNING> )  <INTO> Expression() ("," Expression())*] ";"
      	// PIPELINED FUNCTION OUTPUT
            { return jjtThis ; }
      }
      

      These three productions are unable to parse BULK COLLECT INTO l_data.

      This method only supported for something like : INTO, RETURN,RETURNING, USING

    • When searching in the PldocAST.jjt, I found that there is a method called BulkCollectIntoClause() can parse BULK COLLECT INTO l_data

      ASTBulkCollectIntoClause BulkCollectIntoClause() :
      {}
      {
          <BULK> <COLLECT> <INTO> BulkCollectIntoClauseEntry() ("," BulkCollectIntoClauseEntry())*
          { return jjtThis; }
      }
      
      void BulkCollectIntoClauseEntry() #void :
      {}
      {
          CollectionName() | ":" HostArrayName()
      }
      
      ASTCollectionName CollectionName() :
      { ASTID id; }
      {
          id = ID() {jjtThis.setImage(id.getImage());}
          { return jjtThis; }
      }
      
    • In order to fix this issue, I edit the EmbeddedSqlStatement() by invoking the BulkCollectIntoClause():

      ASTEmbeddedSqlStatement EmbeddedSqlStatement()  :
      {}
      {
         <EXECUTE> <IMMEDIATE> StringExpression()
          [ LOOKAHEAD(<BULK>) BulkCollectIntoClause() ] 
          //#3687 Invoke this method to parse "BULK COLLECT"
      	[ <INTO> Name() ("," Name())* ]
      	[ UsingClause() ]
      	[ ( <RETURN> | <RETURNING> )  <INTO> Expression() ("," Expression())*] ";"
      	// PIPELINED FUNCTION OUTPUT
            { return jjtThis ; }
      }
      
  8. adangel
    assigned
    hgodinez89
    and
    Scrsloota
    and unassigned
    hgodinez89
    on Apr 26, 2022
  9. adangel
    added this to the 6.45.0 milestone on Apr 26, 2022
  10. adangel
    added 2 commits that reference this issue on Apr 28, 2022

    [doc] Update release notes (pmd#3687, pmd#3935)

    84b6cfe

    Merge pull request pmd#3935 from Scrsloota:master

    1e5d69d
  11. adangel
    closed this as completedin #3935on Apr 28, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

  • @Scrsloota
    Scrsloota

Labels

a:bugPMD crashes or fails to analyse a file.

Type

No type

Projects

No projects

    Milestone

    • 6.45.0

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

    You are visitor 01402775 — GeezerVison does not store the pages you look up.
    Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.