Skip to content

Commit

Permalink
using instance of the service on-demand instead. #8473
Browse files Browse the repository at this point in the history
  • Loading branch information
wangmingliang-ms committed Aug 29, 2024
1 parent d16baaf commit 20f0c83
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,13 @@
import static com.intellij.credentialStore.CredentialAttributesKt.generateServiceName;

public class IntelliJSecureStore implements ISecureStore {
private static class LazyHolder {
static final IntelliJSecureStore INSTANCE = new IntelliJSecureStore();
}
static IntelliJSecureStore INSTANCE = null;

public static IntelliJSecureStore getInstance() {
return LazyHolder.INSTANCE;
public static synchronized IntelliJSecureStore getInstance() {
if (INSTANCE == null) {
INSTANCE = new IntelliJSecureStore();
}
return INSTANCE;
}

private IntelliJSecureStore() {
Expand Down Expand Up @@ -61,7 +62,7 @@ public String loadPassword(@Nonnull String serviceName, @Nullable String key, @N
@Override
public void forgetPassword(@Nonnull String serviceName, @Nullable String key, @Nullable String userName) {
CredentialAttributes oldKey = StringUtils.isNotBlank(userName) ? new CredentialAttributes(key, userName) :
new CredentialAttributes(key);
new CredentialAttributes(key);
passwordSafe.setPassword(oldKey, null);
passwordSafe.setPassword(makeKey(serviceName, key, userName), null);
}
Expand All @@ -70,7 +71,7 @@ public void forgetPassword(@Nonnull String serviceName, @Nullable String key, @N
public void migratePassword(@Nonnull String oldKeyOrServiceName, @Nullable String oldUsername,
@Nonnull String serviceName, @Nullable String key, @Nullable String userName) {
CredentialAttributes oldKey = StringUtils.isNotBlank(oldUsername) ? new CredentialAttributes(oldKeyOrServiceName, userName) :
new CredentialAttributes(oldKeyOrServiceName);
new CredentialAttributes(oldKeyOrServiceName);
CredentialAttributes newKey = makeKey(serviceName, key, userName);
if (StringUtils.isBlank(passwordSafe.getPassword(newKey))) {
passwordSafe.setPassword(newKey, passwordSafe.getPassword(oldKey));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,22 +10,20 @@
import org.apache.commons.lang3.StringUtils;

public final class TelemetryClientSingleton {
private final AzureTelemetryClient telemetry;
private AppInsightsConfiguration configuration = null;
private static AzureTelemetryClient telemetry;
private static AppInsightsConfiguration configuration = null;

private static final class SingletonHolder {
private static final TelemetryClientSingleton INSTANCE = new TelemetryClientSingleton();
}

public static AzureTelemetryClient getTelemetry() {
return SingletonHolder.INSTANCE.telemetry;
public static synchronized AzureTelemetryClient getTelemetry() {
if(TelemetryClientSingleton.telemetry==null){
TelemetryClientSingleton.telemetry = AzureTelemeter.getClient();
}
return TelemetryClientSingleton.telemetry;
}

public static void setConfiguration(final AppInsightsConfiguration configuration) {
SingletonHolder.INSTANCE.configuration = configuration;
TelemetryClientSingleton.configuration = configuration;
}

private TelemetryClientSingleton() {
telemetry = AzureTelemeter.getClient();
}
}

0 comments on commit 20f0c83

Please sign in to comment.