From ac46c75fbc0387cb6daa45007ba1fa64f1885899 Mon Sep 17 00:00:00 2001 From: Nicholas Rayburn <52075362+nrayburn-tech@users.noreply.github.com> Date: Wed, 21 Aug 2024 07:43:53 -0700 Subject: [PATCH] Fix #1132 Load services outside of constructors and class initializers Fixes the error on startup by loading the service when needed and not when the class is initializing. IntelliJ docs on this, https://plugins.jetbrains.com/docs/intellij/plugin-services.html#retrieving-a-service. Tested locally with IntelliJ versions 2021.3 and 2024.2. #1134 has bug #1132 tagged, but I don't think it does anything to resolve the issue in it's current state. (I do agree that getting on the newer IntelliJ tooling is beneficial though, it offers inspections that catches issues like this.) Fixes #1132. Fixes #1138 COPYBARA_INTEGRATE_REVIEW=https://github.com/google/google-java-format/pull/1138 from nrayburn-tech:fix/1132 5866980075b52167834dfd9d2e25a739b3f06760 PiperOrigin-RevId: 665876052 --- .../intellij/InitialConfigurationStartupActivity.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/idea_plugin/src/main/java/com/google/googlejavaformat/intellij/InitialConfigurationStartupActivity.java b/idea_plugin/src/main/java/com/google/googlejavaformat/intellij/InitialConfigurationStartupActivity.java index 940def655..95e13d325 100644 --- a/idea_plugin/src/main/java/com/google/googlejavaformat/intellij/InitialConfigurationStartupActivity.java +++ b/idea_plugin/src/main/java/com/google/googlejavaformat/intellij/InitialConfigurationStartupActivity.java @@ -27,8 +27,6 @@ final class InitialConfigurationStartupActivity implements StartupActivity.Background { private static final String NOTIFICATION_TITLE = "Enable google-java-format"; - private static final NotificationGroup NOTIFICATION_GROUP = - NotificationGroupManager.getInstance().getNotificationGroup(NOTIFICATION_TITLE); @Override public void runActivity(@NotNull Project project) { @@ -43,9 +41,11 @@ public void runActivity(@NotNull Project project) { } private void displayNewUserNotification(Project project, GoogleJavaFormatSettings settings) { + NotificationGroupManager groupManager = NotificationGroupManager.getInstance(); + NotificationGroup group = groupManager.getNotificationGroup(NOTIFICATION_TITLE); Notification notification = new Notification( - NOTIFICATION_GROUP.getDisplayId(), + group.getDisplayId(), NOTIFICATION_TITLE, "The google-java-format plugin is disabled by default. " + "Enable for this project.",