[plsql] Fix TomKytesDespair for more complex exception handlers

Fixes #5132
This commit is contained in:
Andreas Dangel 2024-07-25 12:09:29 +02:00
parent 39750cf158
commit 44d25c41e1
No known key found for this signature in database
GPG Key ID: 93450DF2DF9A3FA3
3 changed files with 27 additions and 1 deletions

View File

@ -15,6 +15,8 @@ This is a {{ site.pmd.release_type }} release.
### 🚀 New and noteworthy
### 🐛 Fixed Issues
* plsql-bestpractices
* [#5132](https://github.com/pmd/pmd/issues/5132): \[plsql] TomKytesDespair - exception for more complex exception handler
### 🚨 API Changes

View File

@ -24,7 +24,9 @@ Rules which enforce generally accepted best practices.
<property name="xpath">
<value>
<![CDATA[
//ExceptionHandler[QualifiedName/@Image='OTHERS' and upper-case(Statement/UnlabelledStatement/Expression/@Image)='NULL']
//ExceptionHandler[QualifiedName/@Image='OTHERS']
[count(Statement)=1]
[Statement/UnlabelledStatement/Expression/PrimaryPrefix/Literal/NullLiteral]
]]>
</value>
</property>

View File

@ -98,4 +98,26 @@ END update_planned_hrs;
/
]]></code>
</test-code>
<test-code>
<description>#5132 [plsql] TomKytesDespair - exception for more complex exception handler</description>
<expected-problems>0</expected-problems>
<code><![CDATA[
create or replace procedure x
is
v_cursor number;
begin
v_cursor := DBMS_SQL.open_cursor;
dbms_output.put_line('Blah');
exception
WHEN OTHERS THEN
IF DBMS_SQL.is_open(v_cursor) THEN
DBMS_SQL.close_cursor(v_cursor);
END IF;
DBMS_OUTPUT.Put_Line('Blah');
DBMS_OUTPUT.Put_Line(SQLERRM);
end;
/
]]></code>
</test-code>
</test-data>