Skip to content

Commit 21b851e

Browse files
eckterKhoyo
authored andcommitted
core: avoid adding an invalid cache entry when using an unloaded infra
1 parent 486129a commit 21b851e

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

core/src/main/java/fr/sncf/osrd/api/InfraManager.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -240,15 +240,15 @@ public InfraCacheEntry deleteFromInfraCache(String infraId) {
240240
public FullInfra getInfra(String infraId, String expectedVersion, DiagnosticRecorder diagnosticRecorder)
241241
throws OSRDError, InterruptedException {
242242
try {
243-
infraCache.putIfAbsent(infraId, new InfraCacheEntry());
244243
var cacheEntry = infraCache.get(infraId);
245-
// download the infra for tests
246-
if (loadIfMissing) {
247-
return load(infraId, expectedVersion, diagnosticRecorder);
244+
if (cacheEntry == null || !cacheEntry.status.isStable) {
245+
if (loadIfMissing) {
246+
// download the infra for tests
247+
return load(infraId, expectedVersion, diagnosticRecorder);
248+
} else
249+
throw new OSRDError(ErrorType.InfraNotLoadedException);
248250
}
249251
var obsoleteVersion = expectedVersion != null && !expectedVersion.equals(cacheEntry.version);
250-
if (!cacheEntry.status.isStable)
251-
throw new OSRDError(ErrorType.InfraNotLoadedException);
252252
if (obsoleteVersion) {
253253
deleteFromInfraCache(infraId);
254254
throw new OSRDError(ErrorType.InfraInvalidVersionException);

0 commit comments

Comments
 (0)