TRY around cast with empty CATCH

 home quick fix  example  edit

try_cast_empty_catch

Description

Finds a down cast in TRY with an empty CATCH cx_sy_move_cast_error, use IS INSTANCE OF

Extended Information

Reports TRY. a ?= b. CATCH cx_sy_move_cast_error. ENDTRY. when all of the following hold:

* the cast is the only statement of the TRY block, there is exactly one CATCH, for cx_sy_move_cast_error only,
without INTO or BEFORE UNWIND, its block is empty, and there is no CLEANUP
* the static type of a is a class or interface, not a generic REF TO object
* b is a plain data object: variable, attribute or a chain of components and attributes, without calls,
so evaluating it again has no side effects

a ?= b. also succeeds when b is initial, and then clears a, while b IS INSTANCE OF is false for an initial b,
so the quick fix replaces the TRY with IF b IS INSTANCE OF OR b IS INITIAL. a ?= b. ENDIF.

Requires IS INSTANCE OF, ie. 7.50 or above, ABAP Cloud or open-abap.
Objects with syntax errors, macros or unknown statements are skipped, as are procedures with dynamic code,
INCLUDE, test seams, enhancements or native SQL.

Default Configuration

Hover to see descriptions, Ctrl+Space for suggestions

Examples