From e761dd8e97c4c770094b3118a2989b34fc8eecbc Mon Sep 17 00:00:00 2001 From: "Gregory.Shrago" Date: Thu, 29 May 2014 18:30:59 +0400 Subject: [PATCH 1/3] @NotNull'ed for EA-56831 - NPE: RemoteProcessSupport.release --- .../intellij/execution/rmi/RemoteProcessSupport.java | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/platform/lang-impl/src/com/intellij/execution/rmi/RemoteProcessSupport.java b/platform/lang-impl/src/com/intellij/execution/rmi/RemoteProcessSupport.java index aa2ec91c641b..8d2d422f947d 100644 --- a/platform/lang-impl/src/com/intellij/execution/rmi/RemoteProcessSupport.java +++ b/platform/lang-impl/src/com/intellij/execution/rmi/RemoteProcessSupport.java @@ -151,9 +151,9 @@ public abstract class RemoteProcessSupport { public void release(@NotNull Target target, @Nullable Parameters configuration) { ArrayList handlers = new ArrayList(); synchronized (myProcMap) { - for (Pair pair : myProcMap.keySet()) { - if (pair.first == target && (configuration == null || pair.second == configuration)) { - ContainerUtil.addIfNotNull(myProcMap.get(pair).handler, handlers); + for (Pair key : myProcMap.keySet()) { + if (key.first == target && (configuration == null || key.second == configuration)) { + ContainerUtil.addIfNotNull(myProcMap.get(key).handler, handlers); } } } @@ -164,7 +164,7 @@ public abstract class RemoteProcessSupport { fireModificationCountChanged(); } - private void startProcess(Target target, Parameters configuration, Pair key) { + private void startProcess(Target target, Parameters configuration, @NotNull Pair key) { ProgramRunner runner = new DefaultProgramRunner() { @Override @NotNull @@ -196,7 +196,7 @@ public abstract class RemoteProcessSupport { protected abstract RunProfileState getRunProfileState(Target target, Parameters configuration, Executor executor) throws ExecutionException; - private boolean getExistingInfo(Ref ref, Pair key) { + private boolean getExistingInfo(@NotNull Ref ref, @NotNull Pair key) { Info info; synchronized (myProcMap) { info = myProcMap.get(key); @@ -254,7 +254,7 @@ public abstract class RemoteProcessSupport { return (T)(to.isInstance(remote) ? remote : PortableRemoteObject.narrow(remote, to)); } - private ProcessListener getProcessListener(final Pair key) { + private ProcessListener getProcessListener(@NotNull final Pair key) { return new ProcessListener() { @Override public void startNotified(ProcessEvent event) { From c3c31bd78b00251e0b4a5b915d3168dd21ccf5eb Mon Sep 17 00:00:00 2001 From: "Gregory.Shrago" Date: Thu, 29 May 2014 19:08:56 +0400 Subject: [PATCH 2/3] EA-57052 - assert: MasterKeyPasswordSafe.decryptPassword --- .../masterKey/MasterKeyPasswordSafe.java | 20 ++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/platform/platform-impl/src/com/intellij/ide/passwordSafe/impl/providers/masterKey/MasterKeyPasswordSafe.java b/platform/platform-impl/src/com/intellij/ide/passwordSafe/impl/providers/masterKey/MasterKeyPasswordSafe.java index 9fee5cc552ce..1873f257a7c5 100644 --- a/platform/platform-impl/src/com/intellij/ide/passwordSafe/impl/providers/masterKey/MasterKeyPasswordSafe.java +++ b/platform/platform-impl/src/com/intellij/ide/passwordSafe/impl/providers/masterKey/MasterKeyPasswordSafe.java @@ -183,24 +183,26 @@ public class MasterKeyPasswordSafe extends BasePasswordSafeProvider { if (!isTestMode() && application.isHeadlessEnvironment()) { throw new MasterPasswordUnavailableException("The provider is not available in headless environment"); } - if (key.get().get() == null) { + final Ref result = Ref.create(key.get().get()); + if (result.isNull()) { if (isPasswordEncrypted()) { try { - String s = decryptPassword(database.getPasswordInfo()); - setMasterPassword(s); + setMasterPassword(decryptPassword(database.getPasswordInfo())); + result.set(key.get().get()); } catch (PasswordSafeException e) { // ignore exception and ask password } } - if (key.get().get() == null) { + if (result.isNull()) { final Ref ex = new Ref(); if (application.holdsReadLock()) { throw new IllegalStateException("Access from read action is not allowed, because it might lead to a deadlock."); } application.invokeAndWait(new Runnable() { public void run() { - if (key.get().get() == null) { + result.set(key.get().get()); + if (result.isNull()) { try { if (isTestMode()) { throw new MasterPasswordUnavailableException("Master password must be specified in test mode."); @@ -212,6 +214,7 @@ public class MasterKeyPasswordSafe extends BasePasswordSafeProvider { } else { MasterPasswordDialog.askPassword(project, MasterKeyPasswordSafe.this, requestor); + result.set(key.get().get()); } } catch (PasswordSafeException e) { @@ -230,7 +233,7 @@ public class MasterKeyPasswordSafe extends BasePasswordSafeProvider { } } } - return key.get().get(); + return result.get(); } /** @@ -336,7 +339,8 @@ public class MasterKeyPasswordSafe extends BasePasswordSafeProvider { * if decryption fails */ private static String decryptPassword(byte[] pw) throws MasterPasswordUnavailableException { - assert SystemInfo.isWindows; + if (!SystemInfo.isWindows) throw new AssertionError("Windows OS expected"); + try { return new String(WindowsCryptUtils.unprotect(pw), "UTF-8"); } @@ -349,6 +353,8 @@ public class MasterKeyPasswordSafe extends BasePasswordSafeProvider { * @return true, if the password is currently encrypted in the database */ public boolean isPasswordEncrypted() { + if (!isOsProtectedPasswordSupported()) return false; + byte[] i = database.getPasswordInfo(); return i != null && i.length > 0; } From 95bc1fb45d39cf2cf044e33fa08568f04aa47158 Mon Sep 17 00:00:00 2001 From: "Gregory.Shrago" Date: Fri, 30 May 2014 21:47:00 +0400 Subject: [PATCH 3/3] some more @MagicConstant --- .../src/com/intellij/codeInsight/CodeInsightSettings.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/platform/lang-impl/src/com/intellij/codeInsight/CodeInsightSettings.java b/platform/lang-impl/src/com/intellij/codeInsight/CodeInsightSettings.java index f389920b1be8..6d13f27e8671 100644 --- a/platform/lang-impl/src/com/intellij/codeInsight/CodeInsightSettings.java +++ b/platform/lang-impl/src/com/intellij/codeInsight/CodeInsightSettings.java @@ -113,6 +113,7 @@ public class CodeInsightSettings implements PersistentStateComponent, C public boolean AUTOINSERT_PAIR_QUOTE = true; public boolean REFORMAT_BLOCK_ON_RBRACE = true; + @MagicConstant(intValues = {NO_REFORMAT, INDENT_BLOCK, INDENT_EACH_LINE, REFORMAT_BLOCK}) public int REFORMAT_ON_PASTE = INDENT_EACH_LINE; public static final int NO_REFORMAT = 1; public static final int INDENT_BLOCK = 2; @@ -121,7 +122,8 @@ public class CodeInsightSettings implements PersistentStateComponent, C public boolean INDENT_TO_CARET_ON_PASTE = false; - public int ADD_IMPORTS_ON_PASTE = ASK; // YES, NO or ASK + @MagicConstant(intValues = {YES, NO, ASK}) + public int ADD_IMPORTS_ON_PASTE = ASK; public static final int YES = 1; public static final int NO = 2; public static final int ASK = 3;