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
The field is never written more than once within a given constructor, nor depends on the previous value. Therefore, the code can effectively be rewritten to make foo immutable, as it's never written after initialization, for instance, the code could be rewritten as:
I think this makes sense in theory, but it probably should be a new rule. I like that ImmutableField always recommends making things final if it actually can be done by just adding a final keyword, and there is no chance the compiler will reject the new code. The fix could in theory be done automatically. Recommending that the user adapts their initialization logic like you suggest is a different task for the programmer and requires more effort, also there are different ways to refactor that. The rule implementation would also likely be very different... So yeah I think it should be a new rule.
Under PMD 7.0.0 there is no report for the code:
The field is never written more than once within a given constructor, nor depends on the previous value. Therefore, the code can effectively be rewritten to make
foo
immutable, as it's never written after initialization, for instance, the code could be rewritten as:Originally posted by @jsotuyod in #4046 (comment)
The text was updated successfully, but these errors were encountered: