kotlin:S6518 reports indexed operator should be used for chained mutating calls

I am using a Java library called Jooq. It has a class UpdateSetStep with a function

<T> UpdateSetMoreStep<R> set(Field<T> field, T value);

Which I am using as intended:

    return set(GENERIC_TOKEN.IS_REVOKED, true)
        .set(GENERIC_TOKEN.EXPIRES_AT_UTC, LocalDateTime.now(clock))
        .set(GENERIC_TOKEN.REVOKED_CAUSE, revokedCause)

But Sonar says Element access should use indexed access operators and if I were to do

this[GENERIC_TOKEN.IS_REVOKED] = true

then there would be no way to access the return value and chain into the next call.

Sonar should probably ignore this rule for chained access like .set(...).set(...)

SonarSource 8.3.0.71062
SonarQube Version 10.1 (build 73491)
Java 17.0.6
Kotlin 1.8.22

Hello Lars,

Good catch, thank you for the report! I opened a ticket where you can track the issue.

1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.