Skip to content

Commit 18877fe

Browse files
committed
fix(runtime): ensure instance publication occurs after potential exceptions during construction
1 parent 6b12678 commit 18877fe

1 file changed

Lines changed: 6 additions & 4 deletions

File tree

test-app/runtime/src/main/java/com/tns/Runtime.java

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -239,13 +239,15 @@ public Runtime(StaticConfiguration config, DynamicConfiguration dynamicConfigura
239239
}
240240

241241
classResolver = new ClassResolver(classStorageService);
242-
currentRuntime.set(this);
243-
244-
runtimeCache.put(this.runtimeId, this);
245-
246242
gcListener = GcListener.getInstance(config.appConfig.getGcThrottleTime(), config.appConfig.getMemoryCheckInterval(), config.appConfig.getFreeMemoryRatio());
247243
// capture static configuration to allow native lookups when currentRuntime is unavailable
248244
staticConfiguration = config;
245+
246+
// publish the instance only after everything that can throw has
247+
// completed, so a failed construction is never reachable through
248+
// the thread-local or the cache
249+
currentRuntime.set(this);
250+
runtimeCache.put(this.runtimeId, this);
249251
} finally {
250252
frame.close();
251253
}

0 commit comments

Comments
 (0)