Skip to content

Commit 3691335

Browse files
Merge remote-tracking branch 'origin/develop' into develop.next
2 parents 5829e7e + 97e76ea commit 3691335

File tree

1 file changed

+22
-4
lines changed
  • PluginsAndFeatures/azure-toolkit-for-intellij/azure-intellij-plugin-java-sdk/src/main/java/com/microsoft/azure/toolkit/intellij/java/sdk/utils

1 file changed

+22
-4
lines changed

PluginsAndFeatures/azure-toolkit-for-intellij/azure-intellij-plugin-java-sdk/src/main/java/com/microsoft/azure/toolkit/intellij/java/sdk/utils/RuleConfigLoader.java

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,18 +16,29 @@
1616
@Slf4j
1717
public class RuleConfigLoader {
1818
private static final String CONFIG_FILE_PATH = "./ruleConfigs.json";
19-
private static RuleConfigLoader INSTANCE;
19+
private static volatile RuleConfigLoader INSTANCE = new RuleConfigLoader();
2020
private Map<String, RuleConfig> ruleConfigs;
21+
private volatile boolean initialized = false;
2122

2223
private RuleConfigLoader() {
2324
this.ruleConfigs = new HashMap<>();
2425
this.initialize();
2526
}
2627

28+
static {
29+
try {
30+
// Eagerly load configuration at class load time
31+
INSTANCE.initialize();
32+
} catch (Exception e) {
33+
// Never fail class loading; keep instance alive with empty configs
34+
log.warn("Failed to eagerly initialize RuleConfigLoader: " + e.getMessage(), e);
35+
}
36+
}
37+
2738
/**
2839
* Gets the singleton instance of RuleConfigLoader.
2940
*
30-
* @return The singleton instance of RuleConfigLoader.
41+
* @return The singleton instance of RuleConfigLoader (never null).
3142
*/
3243
@Nonnull
3344
public static RuleConfigLoader getInstance() {
@@ -43,12 +54,19 @@ public Map<String, RuleConfig> getRuleConfigs() {
4354
return Collections.unmodifiableMap(ruleConfigs);
4455
}
4556

46-
private void initialize(){
57+
private synchronized void initialize() {
58+
if (initialized) {
59+
return;
60+
}
4761
try {
62+
this.ruleConfigs.clear();
4863
this.ruleConfigs.putAll(this.loadRuleConfigurations());
49-
INSTANCE = this;
64+
// INSTANCE is already assigned in the static initializer; avoid reassigning it here
65+
initialized = true;
5066
} catch (IOException e) {
67+
// Keep INSTANCE non-null, but proceed with empty configs
5168
log.warn("Failed to initialize RuleConfigLoader: " + e.getMessage(), e);
69+
initialized = true;
5270
}
5371
}
5472

0 commit comments

Comments
 (0)