Rule Definition
A method handled by an event must not reactivate this event directly or indirectly via other called methods. Such a cycle based on event and methods can cause unpredictable behaviors.
Remediation
Try to remove cyclic calls between events and handled methods.
Violation Code Sample
CLASS myClass DEFINITION.
PUBLIC SECTION.
METHODS increment_counter.
METHODS handle_excess
FOR EVENT critical_value OF myClass
IMPORTING excess.
METHODS increment.
EVENTS critical_value EXPORTING value(excess) TYPE i.
PRIVATE SECTION.
DATA: count1 TYPE i,
threshold TYPE i VALUE 10.
ENDCLASS.
CLASS myClass IMPLEMENTATION.
METHOD increment_counter.
DATA diff TYPE i.
ADD 1 TO count1.
IF count1 > threshold.
diff = count1 - threshold.
RAISE EVENT critical_value EXPORTING excess = diff.
ENDIF.
ENDMETHOD.
METHOD handle_excess.
* In the following lines, a cycle occurs
IF threshold > 5
CALL METHOD me->increment.
ENDIF.
ENDMETHOD.
METHOD increment.
ADD 1 TO count1.
ENDMETHOD.
ENDCLASS.
Fixed Code Sample
CLASS myClass DEFINITION.
PUBLIC SECTION.
METHODS increment_counter.
METHODS handle_excess
FOR EVENT critical_value OF myClass
IMPORTING excess.
METHODS increment.
EVENTS critical_value EXPORTING value(excess) TYPE i.
PRIVATE SECTION.
DATA: count1 TYPE i,
threshold TYPE i VALUE 10.
ENDCLASS.
CLASS myClass IMPLEMENTATION.
METHOD increment_counter.
DATA diff TYPE i.
ADD 1 TO count1.
IF count1 > threshold.
diff = count1 - threshold.
RAISE EVENT critical_value EXPORTING excess = diff.
ENDIF.
ENDMETHOD.
METHOD handle_excess.
IF threshold > 5
* CALL METHOD me->increment.
write / count1.
ENDIF.
ENDMETHOD.
METHOD increment.
ADD 1 TO count1.
ENDMETHOD.
ENDCLASS.
Related Technologies
Technical Criterion
CWE-1047 - Modules with Circular Dependencies
About CAST Appmarq
CAST Appmarq is by far the biggest repository of data about real IT systems. It's built on thousands of analyzed applications, made of 35 different technologies, by over 300 business organizations across major verticals. It provides IT Leaders with factual key analytics to let them know if their applications are on track.