Skip to content

[BUG] ABAP Cleaner doesn't detect variable is changed in code and changes it to final #297

Closed

Description

@xkollar2

Hello!

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:

method if_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 into final(component).
    assign component 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:

  method if_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 into final(component).
      assign component 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.

My ABAP Cleaner version is currently 1.16.0

Thank you in advance.
With regards
Denis

Activity

  1. self-assigned this
    on May 10, 2024
  2. jmgrassau commented on May 10, 2024

    @jmgrassau
    Member

    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:

    image

    Kind regards,
    Jörgt-Michael

  3. jmgrassau commented on May 13, 2024

    @jmgrassau
    Member

    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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions