You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[BUG] ABAP Cleaner doesn't detect variable is changed in code and changes it to final #297
Today I've discovered a in my opinion a bug. When you have rule 'Use FINAL for immutable variables' enabled and you try to format the code below:
methodif_oo_adt_classrun~main.
types: begin of test_type,
attribute1 type string,
attribute2 type string,
end of test_type.
data tmp type test_type.
field-symbols<fieldx> type any.
data(struct) =cast cl_abap_structdescr( cl_abap_typedescr=>describe_by_data( p_data = tmp ) ).
data(shouldnt_be_final) =value test_type( attribute1 ='test' ).
loop at struct->components intofinal(component).
assigncomponent component-name of structure shouldnt_be_final to<fieldx>.
<fieldx>='will_fail'.
endloop.
endmethod.
then variable 'shouldnt_be_final' gets transformed into FINAL like this:
methodif_oo_adt_classrun~main.
types: begin of test_type,
attribute1 type string,
attribute2 type string,
end of test_type.
data tmp type test_type.
field-symbols<fieldx> type any.
data(struct) =cast cl_abap_structdescr( cl_abap_typedescr=>describe_by_data( p_data = tmp ) ).
final(shouldnt_be_final) =value test_type( attribute1 ='test' ).
loop at struct->components intofinal(component).
assigncomponent component-name of structure shouldnt_be_final to<fieldx>.
<fieldx>='will_fail'.
endloop.
endmethod.
This will of course fail on runtime exception "MOVE_TO_LIT_NOTALLOWED_NODATA" and results in a short dump.
The issue seems to be, that ABAP Cleaner doesn't recognize changing of variable via field-symbol.
Could you please check this?
For the time being I was forced to turn off the formatting rule for FINAL.
Activity
jmgrassau commentedon May 10, 2024
Hi Denis,
thank you very much for reporting this, I indeed missed this case! This will be fixed with the next release, so DATA is kept:
Kind regards,
Jörgt-Michael
fix FinalVariableRule for ASSIGN COMPONENT ... OF STRUCTURE (SAP#297)
fix FinalVariableRule for ASSIGN COMPONENT ... OF STRUCTURE (#297)
jmgrassau commentedon May 13, 2024
Hi Denis,
thanks again for reporting this bug – this should now be fixed with version 1.16.1, which was just released!
Kind regards,
Jörg-Michael