Avoid IS INSTANCE OF and CASE TYPE OF Type Tests
WarningClean ABAP & Modern Syntax#EC NO_INSTANCE_OFRemote Enabled
Overview
Avoid IS INSTANCE OF / CASE TYPE OF checks.
ATC Finding Message:
Avoid runtime type checks via IS INSTANCE OF; use polymorphism
Rationale
Checking concrete object types at runtime via IS INSTANCE OF or CASE TYPE OF breaks polymorphism, violates the Open-Closed Principle, and introduces fragile type coupling. Instead of conditional type inspection, introduce polymorphic methods on common interfaces.
Non-Compliant
abap
IF io_shape IS INSTANCE OF cl_circle.
render_circle( ).
ENDIF.Compliant
abap
io_shape->render( ).Configuration & Thresholds
This check can be fine-tuned directly in the ATC Check Variant Editor (CHKV) in Eclipse ADT:
| Parameter Name | Data Type | Default Value | Description & Guidance |
|---|---|---|---|
CHECK_CASE_TYPE | Boolean | true | Report CASE TYPE OF type tests in addition to IS INSTANCE OF |
Suppression
To suppress findings for this rule, append the pseudo-comment to the statement:
abap
" Standard pseudo-comment:
... "#EC NO_INSTANCE_OF
" SAP CI_ prefix format:
... "#EC CI_NO_INSTANCE_OFRelated Rules
- Avoid Calling Static Methods via Instance References (->) —
#EC NO_STATIC_ARROW - Avoid Exposed Mutable Data in Classes and Interfaces —
#EC PUBLIC_ATTR - Prefer NEW #( ) over CREATE OBJECT —
#EC PREF_NEW_OPERATOR
Technical Details
- Native ATC Class:
ZCL_SKYLINT_NO_INSTANCE_OF - Implementation File: zcl_skylint_no_instance_of.clas.abap