From ea2ac73af805827ab54e259508482d03bd4f2e4a Mon Sep 17 00:00:00 2001 From: "Roman.Ivanov" Date: Tue, 22 May 2018 17:12:46 +0700 Subject: [PATCH] ChangeUIDAction: fix review issues: IDEA-CR-32493 --- .../intellij/codeInsight/intention/impl/ChangeUIDAction.java | 5 +++-- .../intentionDescriptions/ChangeUIDAction/description.html | 2 +- .../daemonCodeAnalyzer/quickFix/changeUid/afterChange.java | 2 +- .../daemonCodeAnalyzer/quickFix/changeUid/beforeChange.java | 2 +- .../src/messages/CodeInsightBundle.properties | 2 +- 5 files changed, 7 insertions(+), 6 deletions(-) diff --git a/java/java-impl/src/com/intellij/codeInsight/intention/impl/ChangeUIDAction.java b/java/java-impl/src/com/intellij/codeInsight/intention/impl/ChangeUIDAction.java index 8c0f2565e922..d2d4cb0ed80b 100644 --- a/java/java-impl/src/com/intellij/codeInsight/intention/impl/ChangeUIDAction.java +++ b/java/java-impl/src/com/intellij/codeInsight/intention/impl/ChangeUIDAction.java @@ -15,6 +15,7 @@ import com.siyeh.ig.psiutils.CommentTracker; import org.jetbrains.annotations.Nls; import org.jetbrains.annotations.NotNull; +import java.security.SecureRandom; import java.util.Random; @@ -37,11 +38,11 @@ public class ChangeUIDAction extends PsiElementBaseIntentionAction { PsiField field = PsiTreeUtil.getParentOfType(element, PsiField.class); if (field == null) return; PsiExpression initializer = field.getInitializer(); + if (initializer == null) return; PsiElementFactory factory = JavaPsiFacade.getElementFactory(project); Application application = ApplicationManager.getApplication(); - Random random = application.isUnitTestMode() ? new Random(42) : new Random(); + Random random = application.isUnitTestMode() ? new Random(42) : new SecureRandom(); PsiExpression newInitializer = factory.createExpressionFromText(Long.toString(random.nextLong()) + "L", null); - if (initializer == null) return; new CommentTracker().replaceAndRestoreComments(initializer, newInitializer); } diff --git a/java/java-impl/src/intentionDescriptions/ChangeUIDAction/description.html b/java/java-impl/src/intentionDescriptions/ChangeUIDAction/description.html index 8d10ce9ccaf3..428361cc3fcf 100644 --- a/java/java-impl/src/intentionDescriptions/ChangeUIDAction/description.html +++ b/java/java-impl/src/intentionDescriptions/ChangeUIDAction/description.html @@ -1,5 +1,5 @@ -

Intention to change serialVersionUID initializer to randomly generated one

+

Changes the initializer of a serialVersionUID field to a randomly generated one

\ No newline at end of file diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/changeUid/afterChange.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/changeUid/afterChange.java index cc6cf51afb0d..e7d0b2bcd3aa 100644 --- a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/changeUid/afterChange.java +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/changeUid/afterChange.java @@ -1,4 +1,4 @@ -// "Randomly change serial version UID" "true" +// "Randomly change 'serialVersionUID' initializer" "true" import java.util.function.BinaryOperator; import java.util.function.Function; diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/changeUid/beforeChange.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/changeUid/beforeChange.java index 9d586809c668..668911bd4804 100644 --- a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/changeUid/beforeChange.java +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/changeUid/beforeChange.java @@ -1,4 +1,4 @@ -// "Randomly change serial version UID" "true" +// "Randomly change 'serialVersionUID' initializer" "true" import java.util.function.BinaryOperator; import java.util.function.Function; diff --git a/platform/platform-resources-en/src/messages/CodeInsightBundle.properties b/platform/platform-resources-en/src/messages/CodeInsightBundle.properties index b08d82b071a8..6ca4a4b7e665 100644 --- a/platform/platform-resources-en/src/messages/CodeInsightBundle.properties +++ b/platform/platform-resources-en/src/messages/CodeInsightBundle.properties @@ -568,4 +568,4 @@ collapse.selection.overlapping.warning.text=Overlapping fold region(s) exist collapse.selection.overlapping.warning.ok=Remove collapse.selection.overlapping.warning.cancel=Cancel -change.uid.action.name=Randomly change serial version UID \ No newline at end of file +change.uid.action.name=Randomly change 'serialVersionUID' initializer \ No newline at end of file