Skip to content

Comments

SONARJAVA-6106 ScopedValue instances should be assigned to a stable reference#5480

Open
aurelien-coet-sonarsource wants to merge 4 commits intomasterfrom
ac/SONARJAVA-6106
Open

SONARJAVA-6106 ScopedValue instances should be assigned to a stable reference#5480
aurelien-coet-sonarsource wants to merge 4 commits intomasterfrom
ac/SONARJAVA-6106

Conversation

@aurelien-coet-sonarsource
Copy link
Contributor

No description provided.

@hashicorp-vault-sonar-prod
Copy link

hashicorp-vault-sonar-prod bot commented Feb 23, 2026

SONARJAVA-6106

@sonarqube-next
Copy link

@aurelien-coet-sonarsource aurelien-coet-sonarsource marked this pull request as ready for review February 24, 2026 07:48
Copy link
Contributor

@rombirli rombirli left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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())) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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()) )

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants