Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
337c414
Add reproducer test/sample
rombirli Feb 5, 2026
533959b
small refactoring
rombirli Feb 5, 2026
3b643f8
Full initial implementation - variable usage, escaping, unused career…
rombirli Feb 5, 2026
5e071cb
Add edge cases "multi-level carrier used" to test sample
rombirli Feb 5, 2026
e690e72
Add support for many edge cases : escaping in variable, control flow.…
rombirli Feb 5, 2026
8f29bdd
Convert UnusedScopedValueWhereResultSampleEdgeCases.java to compact s…
rombirli Feb 5, 2026
06d6000
Rename UnusedScopedValueWhereResultSampleEdgeCases.java to UnusedScop…
rombirli Feb 5, 2026
a69a584
Fix path
rombirli Feb 5, 2026
c067460
Fix small edge case
rombirli Feb 5, 2026
bada4bf
Refine edge cases integration tests
rombirli Feb 6, 2026
023c0da
Refine basic integration tests
rombirli Feb 6, 2026
db3c7b2
Refactor UnusedScopedValueWhereResultCheck - rename functions, groupi…
rombirli Feb 6, 2026
fedf3b1
Add missing tests, remove useless code
rombirli Feb 6, 2026
fc159d7
Remove useless methods in UnusedScopedValueWhereResultCheck
rombirli Feb 6, 2026
935c520
Fix code style : line breaks
rombirli Feb 6, 2026
a267e9d
Add rule specification
rombirli Feb 9, 2026
6985985
Try to fix : autoscan tests
rombirli Feb 9, 2026
ff295af
Try to fix : autoscan tests | 2
rombirli Feb 9, 2026
3edaab2
Remove useless parent null checks (negative hits only)
rombirli Feb 9, 2026
ba971e9
Try to fix autoscan tests | 3
rombirli Feb 10, 2026
f5032ec
Try to fix autoscan tests | 4
rombirli Feb 10, 2026
cbbea11
Fix conflicts (S8433 gone)
rombirli Feb 10, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ public void javaCheckTestSources() throws Exception {
softly.assertThat(newDiffs).containsExactlyInAnyOrderElementsOf(knownDiffs.values());
softly.assertThat(newTotal).isEqualTo(knownTotal);
softly.assertThat(rulesCausingFPs).hasSize(10);
softly.assertThat(rulesNotReporting).hasSize(14);
softly.assertThat(rulesNotReporting).hasSize(15);

/**
* 4. Check total number of differences (FPs + FNs)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2872,5 +2872,11 @@
"hasTruePositives": false,
"falseNegatives": 0,
"falsePositives": 0
},
{
"ruleKey": "8432",
"hasTruePositives": false,
"falseNegatives": 0,
"falsePositives": 0
}
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"ruleKey": "S8432",
"hasTruePositives": false,
"falseNegatives": 0,
"falsePositives": 0
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,136 @@
import static java.lang.ScopedValue.where;


static final ScopedValue<String> SCOPED = ScopedValue.newInstance();
static final ScopedValue<String> SCOPED2 = ScopedValue.newInstance();

// Field storage - shouldn't be flagged as we can't track field usage reliably
ScopedValue.Carrier carrierField;
static ScopedValue.Carrier staticCarrierField;

// ===== CONTROL FLOW =====

void conditionalUsage(boolean condition) {
var carrier = ScopedValue.where(SCOPED, "Conditional usage"); // Compliant - used conditionally
if (condition) {
carrier.run(() -> {
});
}
}

// ===== VARIABLE SCENARIOS =====

void variableReassignedBeforeUse() {
var carrier = ScopedValue.where(SCOPED, "Initial instance"); // Noncompliant
carrier = ScopedValue.where(SCOPED, "Second instance"); // Compliant - this instance is used
carrier.run(() -> {
});
}

void multipleVariablesSameCarrierUsed() {
var carrier1 = ScopedValue.where(SCOPED, "Single instance"); // Compliant
var carrier2 = carrier1; // Carrier2 points to same object
carrier2.run(() -> {
});
}

void multipleVariablesSameCarrierUsed2() {
var carrier1 = ScopedValue.where(SCOPED, "Single instance"); // Compliant
var carrier2 = carrier1; // Carrier2 points to same object
carrier1.run(() -> {
});
}

void multipleVariablesSameCarrierUnused() {
var carrier1 = ScopedValue.where(SCOPED, "Single instance unused"); // Noncompliant
var carrier2 = carrier1; // Carrier2 points to same object but is never used
}

void carrierStoredInField() {
carrierField = ScopedValue.where(SCOPED, "Stored in instance field"); // Compliant - way of escaping
}

void carrierStoredInStaticField() {
staticCarrierField = ScopedValue.where(SCOPED, "Stored in static field"); // Compliant - way of escaping
}

void escapingInFieldTwice() {
carrierField = ScopedValue.where(SCOPED, "Instance 1"); // Compliant - escapes, we can't track field usage
carrierField = ScopedValue.where(SCOPED, "Instance 2"); // Compliant - reassigned but still escapes
}

// ===== RETURN VARIATIONS =====

ScopedValue.Carrier ternaryReturn(boolean condition) {
var carrier1 = ScopedValue.where(SCOPED, "Ternary return - true"); // Compliant - potentially returned
var carrier2 = ScopedValue.where(SCOPED, "Ternary return - false"); // Compliant - potentially returned
return condition ? carrier1 : carrier2;
}

// ===== NON-CONSUMING METHOD CALLS =====

void standardFunctinsOnCarrier() {
var carrier = ScopedValue.where(SCOPED, "Standard functions"); // Noncompliant
carrier.toString();
carrier.hashCode();
carrier.equals(null);
}

void getOnCarrier() {
var carrier = ScopedValue.where(SCOPED, "Get function"); // Noncompliant
carrier.get(SCOPED);
}

// ===== LAMBDA/CLOSURE =====

void carrierUsedInsideLambda() {
var carrier = ScopedValue.where(SCOPED, "hello"); // Compliant - used inside lambda
Runnable r = () -> {
carrier.run(() -> {
});
};
r.run();
}

// ===== STATIC IMPORT =====

void staticImportWhere() {
where(SCOPED, "Static import unused"); // Noncompliant
}

void staticImportWhereUsed() {
where(SCOPED, "Static import used").run(() -> {
}); // Compliant - used immediately
}

void staticImportWhereVariable() {
var carrier = where(SCOPED, "Static import unused variable"); // Noncompliant
}

void staticImportWhereVariableUsed() {
var carrier = where(SCOPED, "Static import used variable "); // Compliant - used
carrier.run(() -> {
});
}

// ===== CONSTRUCTOR ARGUMENT =====

void carrierAsConstructorArgument() {
var carrier = ScopedValue.where(SCOPED, "Carrier in constructor argument"); // Compliant - escapes via constructor
new CarrierHolder(carrier);
}

// ===== HELPER METHODS AND CLASSES =====


static class CarrierHolder {
CarrierHolder(ScopedValue.Carrier carrier) // Noncompliant
{
}

CarrierHolder(ScopedValue.Carrier carrier, int i) // Compliant
{
carrier.run(() -> {
});
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
static final ScopedValue myScopedValue = ScopedValue.newInstance();
static final ScopedValue myScopedValue2 = ScopedValue.newInstance();

void main() {
ScopedValue.where(myScopedValue, "Simple chained with get").get(myScopedValue); // Noncompliant
ScopedValue.where(myScopedValue, "Simple chained with run").run(() -> {
}); // Compliant, the result is used immediately
ScopedValue.where(myScopedValue, "Chained two").where(myScopedValue2, "times with run").run(() -> {
}); // Compliant, the result is used immediately
ScopedValue.where(myScopedValue, "Simple carrier creation"); // Noncompliant
var myUnusedCarrier = ScopedValue.where(myScopedValue, "Unused carrier in variable"); // Noncompliant
var myUnused2LevelCarrier = ScopedValue.where(myScopedValue, "Unused carrrier in variable").where(myScopedValue2, "2 levels of where"); // Noncompliant
var myUsedCarrier = ScopedValue.where(myScopedValue, "Used carrier in variable"); // Compliant, the result is assigned to a variable and used
var myUsed2LevelCarrier = ScopedValue.where(myScopedValue, "Used carrier in variable").where(myScopedValue2, "2 levels of where"); // Compliant, the result is assigned to a variable and used
myUsedCarrier.run(() -> {
});
myUsed2LevelCarrier.run(() -> {
});
}

void escapedCarrierFunctionCall() {
var carrier = ScopedValue.where(myScopedValue, "Escape a carrier with a function call"); // compliant - the result escapes
usedCarrierArgument(carrier);
}

void escapedCarrierFunctionCall2() {
usedCarrierArgument(ScopedValue.where(myScopedValue, "Escape a carrier with a function call")); // compliant - the result escapes
}

void usedCarrierArgument(ScopedValue.Carrier carrier) { // compliant - the carrier is used in the function
carrier.run(() -> {
});
}

void unusedCarrierArgument(ScopedValue.Carrier carrier) { // Noncompliant
}

ScopedValue.Carrier escapedCarrierReturn() {
var carrier = ScopedValue.where(myScopedValue, "Escape a carrier with a return"); // compliant - the result escapes
return carrier;
}

ScopedValue.Carrier escapedCarrierReturn2() {
return ScopedValue.where(myScopedValue, "Escape a carrier with a return"); // compliant - the result escapes
}

void escapedCarrierArgument(ScopedValue.Carrier carrier) { // compliant - the carrier is used in the function
usedCarrierArgument(carrier);
}
Loading
Loading