[java-analysis] InferNullityAnnotationsAction: avoid storing myUi after the dialog is finished

Otherwise, resource leaks are possible through it.
Fixes IDEA-346071 com.intellij.codeInspection.inferNullity.InferNullityAnnotationsAction holds disposed ProjectImpl

GitOrigin-RevId: f84ae2575a8ef6d0f88fc3bde769d913ae664ac5
This commit is contained in:
Tagir Valeev
2024-09-13 12:09:12 +02:00
committed by intellij-monorepo-bot
parent 6a1be79f27
commit e40396352c

View File

@@ -50,7 +50,6 @@ import com.intellij.refactoring.RefactoringBundle;
import com.intellij.usageView.UsageInfo;
import com.intellij.usageView.UsageViewUtil;
import com.intellij.usages.*;
import com.intellij.util.LazyInitializer;
import com.intellij.util.ObjectUtils;
import com.intellij.util.Processor;
import com.intellij.util.SequentialModalProgressTask;
@@ -67,7 +66,7 @@ import java.util.*;
public class InferNullityAnnotationsAction extends BaseAnalysisAction {
private static final String SUGGEST_ANNOTATION_DEPENDENCY = "java.suggest.annotation.dependency";
private static final @NonNls String ANNOTATE_LOCAL_VARIABLES = "checkbox.annotate.local.variables";
private final LazyInitializer.@NotNull LazyValue<InferNullityAdditionalUi> myUi = LazyInitializer.create(InferNullityAdditionalUi::new);
private InferNullityAdditionalUi myUi;
private static final NotificationGroup NOTIFICATION_GROUP = NotificationGroupManager
.getInstance()
.getNotificationGroup("Infer Nullity");
@@ -78,6 +77,21 @@ public class InferNullityAnnotationsAction extends BaseAnalysisAction {
@Override
protected void analyze(final @NotNull Project project, final @NotNull AnalysisScope scope) {
try {
doAnalysis(project, scope);
}
finally {
dispose();
}
}
@Override
protected void canceled() {
super.canceled();
dispose();
}
private void doAnalysis(@NotNull Project project, @NotNull AnalysisScope scope) {
PropertiesComponent.getInstance().setValue(ANNOTATE_LOCAL_VARIABLES, isAnnotateLocalVariables());
final ProgressManager progressManager = ProgressManager.getInstance();
@@ -236,7 +250,7 @@ public class InferNullityAnnotationsAction extends BaseAnalysisAction {
}
protected boolean isAnnotateLocalVariables() {
return myUi.get().getCheckBox().isSelected();
return myUi.getCheckBox().isSelected();
}
private static @NotNull Runnable applyRunnable(final @NotNull Project project, final @NotNull Computable<UsageInfo[]> computable) {
@@ -343,11 +357,15 @@ public class InferNullityAnnotationsAction extends BaseAnalysisAction {
};
}
private void dispose() {
myUi = null;
}
@Override
protected @Nullable JComponent getAdditionalActionSettings(@NotNull Project project, BaseAnalysisActionDialog dialog) {
InferNullityAdditionalUi ui = myUi.get();
ui.getCheckBox().setSelected(PropertiesComponent.getInstance().getBoolean(ANNOTATE_LOCAL_VARIABLES));
return ui.getPanel();
myUi = new InferNullityAdditionalUi();
myUi.getCheckBox().setSelected(PropertiesComponent.getInstance().getBoolean(ANNOTATE_LOCAL_VARIABLES));
return myUi.getPanel();
}
/**