Trivadis / plsql-cop-sonar

db* CODECOP for SonarQube
13 stars 3 forks source link

Exception raised when scanning some SQL files #1

Closed deboiph closed 4 years ago

deboiph commented 4 years ago

The following exception is raised when scanning some SQL files with the version 7.9.0.0 beta of the PL/SQL Cop plugin:

ERROR: Exception while processing <sql-file>: <nn> is not a valid line for pointer. File <sql-file> has <nn-1> line(s)

Example for one file:

ERROR: Exception while processing opsys/qc_opsys_aux_settings.sql: 241 is not a valid line for pointer. File opsys/qc_opsys_aux_settings.sql has 240 line(s)

The file (qc_opsys_aux_settings.txt) has exacltly 240 lines. Note: GitHub does not allow to attach ".sql" files so I changed its extension to ".txt".

Despite this reported error, the file seems to be scanned correctly (some code smells are reported).

No error is reported when PL/SQL Cop rules are disabled. This was tested on SonarQube 8.0 running on Windows 7. See also the full log file: sonar-log.txt

PhilippSalvisberg commented 4 years ago

Thanks @deboiph for reporting this issue in such a detailed way. It helped me to reproduce it.

There are several issues:

  1. The file is encoded in UTF-8 with BOM We do not support them. SQL Developer cannot process them as well.

  2. The are / instead of ; to terminate an UPDATE statement I replaced the slash with a semicolon on line 30, 135 and 223. There seems to be a problem with the statement splitter (splitting the SQL*Plus statements and passing the relevant SQL & PL/SQL statements to another parser). There seems something wrong on our side (needs further analysis).

  3. Issues (guideline violations) should not be reported for files with syntax errors In such cases only "E-0002: Syntax error. Please contact the author if the code compiles successfully in your environment." issues should be reported.

  4. Issues should never be reported on non-existing lines This may happen in some corner cases. You've seen that in the log. The error was reported in the log, but the processing continued. Nonetheless we should not try to create such an issue.

You can reproduce issue (1) and (2) in your SQL Developer installation. We do not plan to fix the first one. created Jira ticket for the second one (PLSQLCOP-280). We'll address it in one of our next releases.

Regarding issue (3) and (4). I have fixed in my development environment. I'll release it later today. Here's a screen shot for your provided file (now E-0002 is shown, caused by the previous /).

image

And the issues are reported for the fixed attached file (.txt instead of .sql). qc_opsys_aux_settings2.txt

PhilippSalvisberg commented 4 years ago

Fixed with https://github.com/Trivadis/plsql-cop-sonar/releases/tag/v7.9.0.1-zpa

PhilippSalvisberg commented 4 years ago

fixed with in PL/SQL parser for v3.0.0 (PLSQLCOP-280)