Skip to content

[CQ] fix nullability problems for flutter/settings #8308

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 1, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 17 additions & 10 deletions flutter-idea/src/io/flutter/settings/FlutterSettings.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import com.intellij.util.EventDispatcher;
import com.jetbrains.lang.dart.analyzer.DartClosingLabelManager;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import java.util.EventListener;
import java.util.Objects;
Expand All @@ -35,13 +36,13 @@ public class FlutterSettings {
private static final String sdkVersionOutdatedWarningAcknowledgedKey = "io.flutter.sdkVersionOutdatedWarningAcknowledged";
private static final String androidStudioBotAcknowledgedKey = "io.flutter.androidStudioBotAcknowledgedKey";

private static FlutterSettings testInstance;
private static @Nullable FlutterSettings testInstance;

/**
* This is only used for testing.
*/
@VisibleForTesting
public static void setInstance(FlutterSettings instance) {
public static void setInstance(@Nullable FlutterSettings instance) {
testInstance = instance;
}

Expand All @@ -53,8 +54,10 @@ public static void setInstance(FlutterSettings instance) {
return Objects.requireNonNull(Objects.requireNonNull(ApplicationManager.getApplication()).getService(FlutterSettings.class));
}

protected static PropertiesComponent getPropertiesComponent() {
return PropertiesComponent.getInstance();
protected static @NotNull PropertiesComponent getPropertiesComponent() {
var component = PropertiesComponent.getInstance();
assert component != null;
return component;
}

public interface Listener extends EventListener {
Expand All @@ -63,7 +66,7 @@ public interface Listener extends EventListener {

private final EventDispatcher<Listener> dispatcher = EventDispatcher.create(Listener.class);

public void addListener(Listener listener) {
public void addListener(@NotNull Listener listener) {
dispatcher.addListener(listener);
}

Expand Down Expand Up @@ -177,11 +180,15 @@ public void setShowBuildMethodGuides(boolean value) {
}

public boolean isShowClosingLabels() {
return DartClosingLabelManager.getInstance().getShowClosingLabels();
var labelManager = DartClosingLabelManager.getInstance();
return labelManager != null && labelManager.getShowClosingLabels();
}

public void setShowClosingLabels(boolean value) {
DartClosingLabelManager.getInstance().setShowClosingLabels(value);
var labelManager = DartClosingLabelManager.getInstance();
if (labelManager != null) {
labelManager.setShowClosingLabels(value);
}
}

public String getFontPackages() {
Expand Down Expand Up @@ -235,15 +242,15 @@ public void setShowBazelIosRunNotification(boolean value) {
/**
* See {FlutterSdkVersion#MIN_SDK_SUPPORTED}.
*/
public boolean isSdkVersionOutdatedWarningAcknowledged(String versionText, boolean isBeforeSunset) {
public boolean isSdkVersionOutdatedWarningAcknowledged(@Nullable String versionText, boolean isBeforeSunset) {
return getPropertiesComponent().getBoolean(getSdkVersionKey(versionText, isBeforeSunset));
}

public void setSdkVersionOutdatedWarningAcknowledged(String versionText, boolean isBeforeSunset, boolean value) {
public void setSdkVersionOutdatedWarningAcknowledged(@Nullable String versionText, boolean isBeforeSunset, boolean value) {
getPropertiesComponent().setValue(getSdkVersionKey(versionText, isBeforeSunset), value);
}

private String getSdkVersionKey(String versionText, boolean isBeforeSunset) {
private String getSdkVersionKey(@Nullable String versionText, boolean isBeforeSunset) {
return sdkVersionOutdatedWarningAcknowledgedKey + "_" + versionText + "_" + (isBeforeSunset ? "beforeSunset" : "afterSunset");
}

Expand Down
6 changes: 4 additions & 2 deletions flutter-idea/src/io/flutter/settings/FlutterUIConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,20 @@
*/
package io.flutter.settings;

import org.jetbrains.annotations.NotNull;

/**
* Persists Flutter settings for a session.
*/
public class FlutterUIConfig {
private static final FlutterUIConfig INSTANCE = new FlutterUIConfig();
private static final @NotNull FlutterUIConfig INSTANCE = new FlutterUIConfig();

private boolean ignoreOutOfDateFlutterSdks;

private FlutterUIConfig() {
}

public static FlutterUIConfig getInstance() {
public static @NotNull FlutterUIConfig getInstance() {
return INSTANCE;
}

Expand Down