SONARJAVA-6106 ScopedValue instances should be assigned to a stable reference#5480
SONARJAVA-6106 ScopedValue instances should be assigned to a stable reference#5480aurelien-coet-sonarsource wants to merge 4 commits intomasterfrom
Conversation
2f0a9e6 to
6102a25
Compare
|
rombirli
left a comment
There was a problem hiding this comment.
Looks good overall, I need to continue this review tomorrow
| @Override | ||
| protected void onMethodInvocationFound(MethodInvocationTree mit) { | ||
| // It only makes sense to assign a new instance of a ScopedValue to a variable or a field. | ||
| if (!VALID_PARENTS.contains(mit.parent().kind())) { |
There was a problem hiding this comment.
I think that this condition does not cover all possible cases : for instance this snippet breaks the test when added to ScopedValueStableReferenceCheckSample.java:
public String trytobreak() {
ScopedValue<String> scopedVal = (ScopedValue.newInstance());
return "";
}Here the issue is that the parenthesis expression is not included in VALID_PARENTS, a scopedvalue could also be instantiated when calling a function (given as argument), we should explore if there are other exceptions (for example in a lambda, ... .map(i -> ScopedValue.newInstance()) )




No description provided.