Skip to content

Commit b867d1a

Browse files
SONARJAVA-4209 Fix cache context initialization in test kit and and context creation in VisitorsBridge
* Fix overwriting of CacheContext in InternalCheckVerifier * Fix InputFileScannerContext creation to use the write file when scanning without parsing
1 parent fe7fc0d commit b867d1a

2 files changed

Lines changed: 5 additions & 9 deletions

File tree

java-checks-testkit/src/main/java/org/sonar/java/checks/verifier/internal/InternalCheckVerifier.java

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -294,8 +294,8 @@ private void verifyAll() {
294294

295295
List<InputFile> filesToParse = files;
296296
if (isCacheEnabled) {
297-
filesToParse = astScanner.scanWithoutParsing(files).get(false);
298297
visitorsBridge.setCacheContext(cacheContext);
298+
filesToParse = astScanner.scanWithoutParsing(files).get(false);
299299
}
300300
astScanner.scan(filesToParse);
301301

@@ -629,11 +629,6 @@ private SonarComponents sonarComponents() {
629629
SensorContext sensorContext;
630630
if (isCacheEnabled) {
631631
sensorContext = new CacheEnabledSensorContext(readCache, writeCache);
632-
cacheContext = new InternalCacheContext(
633-
sensorContext.isCacheEnabled(),
634-
new JavaReadCacheImpl(sensorContext.previousCache()),
635-
new JavaWriteCacheImpl(sensorContext.nextCache())
636-
);
637632
} else {
638633
sensorContext = new InternalSensorContext();
639634
}

java-frontend/src/main/java/org/sonar/java/model/VisitorsBridge.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ public void setCacheContext(CacheContext cacheContext) {
177177
public boolean scanWithoutParsing(InputFile inputFile) {
178178
if (sonarComponents != null && sonarComponents.fileCanBeSkipped(inputFile)) {
179179
boolean allScansSucceeded = true;
180-
var fileScannerContext = createScannerContext();
180+
var fileScannerContext = createScannerContext(sonarComponents, inputFile, javaVersion, inAndroidContext, cacheContext);
181181
for (var scanner: scannersThatCannotBeSkipped) {
182182
try {
183183
allScansSucceeded &= scanner.scanWithoutParsing(fileScannerContext);
@@ -285,10 +285,11 @@ private static String ruleKey(JavaFileScanner scanner) {
285285
return "";
286286
}
287287

288-
protected InputFileScannerContext createScannerContext() {
288+
protected static InputFileScannerContext createScannerContext(
289+
SonarComponents sonarComponents, InputFile inputFile, JavaVersion javaVersion, boolean inAndroidContext, CacheContext cacheContext) {
289290
return new DefaultInputFileScannerContext(
290291
sonarComponents,
291-
currentFile,
292+
inputFile,
292293
javaVersion,
293294
inAndroidContext,
294295
cacheContext

0 commit comments

Comments
 (0)