Skip to content
New issue

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

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

Already on GitHub? # to your account

[CQ] nullability: make equality checks safe w/ Objects.equals() #7997

Merged
merged 1 commit into from
Apr 4, 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
4 changes: 2 additions & 2 deletions flutter-idea/src/io/flutter/FlutterUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ private static boolean isInTestOrSourceRoot(@Nullable Module module, @NotNull Da
}

public static boolean isIntegrationTestingMode() {
return System.getProperty("idea.required.plugins.id", "").equals("io.flutter.tests.gui.flutter-gui-tests");
return Objects.equals(System.getProperty("idea.required.plugins.id", ""), "io.flutter.tests.gui.flutter-gui-tests");
}

@Nullable
Expand Down Expand Up @@ -561,7 +561,7 @@ public static EmbeddedBrowser embeddedBrowser(Project project) {
}

public static boolean embeddedBrowserAvailable(JxBrowserStatus status) {
return status.equals(JxBrowserStatus.INSTALLED) || status.equals(JxBrowserStatus.INSTALLATION_SKIPPED) && FlutterSettings.getInstance()
return Objects.equals(status, JxBrowserStatus.INSTALLED) || status.equals(JxBrowserStatus.INSTALLATION_SKIPPED) && FlutterSettings.getInstance()
.isEnableJcefBrowser();
}
}
3 changes: 2 additions & 1 deletion flutter-idea/src/io/flutter/android/IntelliJAndroidSdk.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

import java.util.ArrayList;
import java.util.List;
import java.util.Objects;

/**
* An Android SDK and its home directory; this references an IntelliJ @{@link Sdk} instance.
Expand Down Expand Up @@ -90,7 +91,7 @@ public static IntelliJAndroidSdk fromEnvironment() {
@Nullable
public static IntelliJAndroidSdk fromHome(VirtualFile file) {
for (IntelliJAndroidSdk candidate : findAll()) {
if (file.equals(candidate.getHome())) {
if (Objects.equals(file, candidate.getHome())) {
return candidate;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import org.jetbrains.annotations.Nullable;

import java.awt.*;
import java.util.Objects;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

Expand Down Expand Up @@ -170,7 +171,7 @@ public Result applyFilter(final String line, final int entireLength) {
highlightLength = pathPart.length();
break;
}
else if (split.length == 4 && split[0].equals("file")) {
else if (split.length == 4 && Objects.equals(split[0], "file")) {
// part = file:///Users/user/AndroidStudioProjects/flutter_app/test/widget_test.dart:23:18
try {
// Reconcile line number indexing.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,7 @@ private void processResponse(JsonObject response) {
private void processNotification(JsonObject response, @NotNull JsonElement eventName) {
// If we add code to handle more event types below, update the filter in processString().
final String event = eventName.getAsString();
if (event.equals(FLUTTER_NOTIFICATION_OUTLINE)) {
if (Objects.equals(event, FLUTTER_NOTIFICATION_OUTLINE)) {
final JsonObject paramsObject = response.get("params").getAsJsonObject();
final String file = paramsObject.get("file").getAsString();

Expand Down
5 changes: 3 additions & 2 deletions flutter-idea/src/io/flutter/editor/FlutterColorProvider.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import java.awt.*;
import java.util.Arrays;
import java.util.List;
import java.util.Objects;

import static io.flutter.dart.DartPsiUtil.getNewExprFromType;
import static io.flutter.dart.DartPsiUtil.topmostReferenceExpression;
Expand Down Expand Up @@ -136,7 +137,7 @@ else if (parent.getNode().getElementType() == DartTokenTypes.SIMPLE_TYPE) {

@Nullable
private PsiElement resolveReferencedElement(@NotNull PsiElement element) {
if (element instanceof DartCallExpression && element.getFirstChild().getText().equals("Color")) {
if (element instanceof DartCallExpression && Objects.equals(element.getFirstChild().getText(), "Color")) {
return element;
}
final PsiElement symbol = element.getLastChild();
Expand Down Expand Up @@ -216,7 +217,7 @@ private Color parseColorText(@NotNull String text, @NotNull String platform) {
public void setColorTo(@NotNull PsiElement element, @NotNull Color color) {
// Not trying to look up Material or Cupertino colors.
// Unfortunately, there is no way to prevent the color picker from showing (if clicked) for those expressions.
if (!element.getText().equals("Color")) return;
if (!Objects.equals(element.getText(), "Color")) return;
final Document document = PsiDocumentManager.getInstance(element.getProject()).getDocument(element.getContainingFile());
final Runnable command = () -> {
final PsiElement refExpr = topmostReferenceExpression(element);
Expand Down
4 changes: 3 additions & 1 deletion flutter-idea/src/io/flutter/editor/OutlineLocation.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
import org.dartlang.analysis.server.protocol.FlutterOutline;
import org.jetbrains.annotations.Nullable;

import java.util.Objects;

class TextRangeTracker {
private final TextRange rawRange;
private RangeMarker marker;
Expand Down Expand Up @@ -96,7 +98,7 @@ public boolean isConsistentEndingWord() {
// to update marker locations has hit a bad edge case as sometimes
// happens when there is a large document edit due to running a
// code formatter.
endingWord.equals(TextRangeTracker.getCurrentWord(marker.getDocument(), marker.getEndOffset() - 1));
Objects.equals(endingWord, TextRangeTracker.getCurrentWord(marker.getDocument(), marker.getEndOffset() - 1));
}
}

Expand Down
6 changes: 3 additions & 3 deletions flutter-idea/src/io/flutter/jxbrowser/EmbeddedJxBrowser.java
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ private EmbeddedJxBrowser(@NotNull Project project) {
}

JxBrowserManager.installation.thenAccept((JxBrowserStatus status) -> {
if (status.equals(JxBrowserStatus.INSTALLED)) {
if (Objects.equals(status, JxBrowserStatus.INSTALLED)) {
engineRef.compareAndSet(null, EmbeddedBrowserEngine.getInstance().getEngine());
}
});
Expand Down Expand Up @@ -268,7 +268,7 @@ protected void handleUpdatedJxBrowserStatusOnEventThread(JxBrowserStatus jxBrows
}

protected void handleUpdatedJxBrowserStatus(JxBrowserStatus jxBrowserStatus, ContentManager contentManager) {
if (jxBrowserStatus.equals(JxBrowserStatus.INSTALLED)) {
if (Objects.equals(jxBrowserStatus, JxBrowserStatus.INSTALLED)) {
return;
} else if (jxBrowserStatus.equals(JxBrowserStatus.INSTALLATION_FAILED)) {
handleJxBrowserInstallationFailed(contentManager);
Expand All @@ -286,7 +286,7 @@ protected void handleJxBrowserInstallationFailed(ContentManager contentManager)
if (!jxBrowserUtils.licenseIsSet()) {
// If the license isn't available, allow the user to open the equivalent page in a non-embedded browser window.
inputs.add(new LabelInput("The JxBrowser license could not be found."));
} else if (latestFailureReason != null && latestFailureReason.failureType.equals(FailureType.SYSTEM_INCOMPATIBLE)) {
} else if (latestFailureReason != null && Objects.equals(latestFailureReason.failureType, FailureType.SYSTEM_INCOMPATIBLE)) {
// If we know the system is incompatible, skip retry link and offer to open in browser.
inputs.add(new LabelInput(latestFailureReason.detail));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ public void setUp(@NotNull String projectName) {
return;
}

if (!jxBrowserUtils.skipInstallation() && status.get().equals(JxBrowserStatus.INSTALLATION_SKIPPED)) {
if (!jxBrowserUtils.skipInstallation() && Objects.equals(status.get(), JxBrowserStatus.INSTALLATION_SKIPPED)) {
// This check returns status to NOT_INSTALLED so that JxBrowser can be downloaded and installed in cases where it is enabled after being disabled.
status.compareAndSet(JxBrowserStatus.INSTALLATION_SKIPPED, JxBrowserStatus.NOT_INSTALLED);
}
Expand Down
11 changes: 4 additions & 7 deletions flutter-idea/src/io/flutter/logging/DiagnosticsNode.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,7 @@
import org.jetbrains.annotations.Nullable;

import javax.swing.*;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.*;
import java.util.concurrent.CompletableFuture;
import java.util.function.BiConsumer;

Expand Down Expand Up @@ -81,7 +78,7 @@ public DiagnosticsNode(JsonObject json,
@Override
public boolean equals(Object other) {
if (other instanceof DiagnosticsNode otherNode) {
return getDartDiagnosticRef().equals(otherNode.getDartDiagnosticRef());
return Objects.equals(getDartDiagnosticRef(), otherNode.getDartDiagnosticRef());
}
return false;
}
Expand Down Expand Up @@ -653,10 +650,10 @@ public boolean identicalDisplay(DiagnosticsNode node) {
}
for (Map.Entry<String, JsonElement> entry : entries) {
final String key = entry.getKey();
if (key.equals("objectId") || key.equals("valueId")) {
if (Objects.equals(key, "objectId") || key.equals("valueId")) {
continue;
}
if (!entry.getValue().equals(node.json.get(key))) {
if (!Objects.equals(entry.getValue(), node.json.get(key))) {
return false;
}
}
Expand Down
3 changes: 2 additions & 1 deletion flutter-idea/src/io/flutter/pub/PubRoot.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import java.io.File;
import java.util.List;
import java.util.Map;
import java.util.Objects;

/**
* A snapshot of the root directory of a pub package.
Expand Down Expand Up @@ -427,7 +428,7 @@ public boolean hasAndroidModule(Project project) {

for (Module module : ModuleManager.getInstance(project).getModules()) {
for (VirtualFile contentRoot : ModuleRootManager.getInstance(module).getContentRoots()) {
if (contentRoot.equals(androidDir)) {
if (Objects.equals(contentRoot, androidDir)) {
return true;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
import io.flutter.utils.FlutterModuleUtils;
import org.jetbrains.annotations.NotNull;

import java.util.Objects;

public class FlutterBazelRunConfigurationType extends ConfigurationTypeBase {
@VisibleForTesting final Factory factory = new Factory(this);

Expand Down Expand Up @@ -75,7 +77,7 @@ private boolean isNewlyGeneratedName(String name) {
// This is a hack based on what the code does in RunConfigurable.createUniqueName().
// If it fails to match, the new run config still works, just without any defaults set.
final String baseName = ExecutionBundle.message("run.configuration.unnamed.name.prefix");
return name.equals(baseName) || name.startsWith(baseName + " (");
return Objects.equals(name, baseName) || name.startsWith(baseName + " (");
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

import javax.swing.*;
import java.awt.event.ActionEvent;
import java.util.Objects;

import static io.flutter.run.bazelTest.BazelTestFields.Scope.*;

Expand Down Expand Up @@ -163,7 +164,7 @@ private void render(Scope next) {

// Because the scope of the underlying fields is calculated based on which parameters are assigned,
// we remove fields that aren't part of the selected scope.
if (next.equals(Scope.TARGET_PATTERN)) {
if (Objects.equals(next, Scope.TARGET_PATTERN)) {
myTestName.setText("");
myEntryFile.setText("");
}
Expand Down
4 changes: 3 additions & 1 deletion flutter-idea/src/io/flutter/run/common/RunMode.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
import org.jetbrains.annotations.NonNls;
import org.jetbrains.annotations.NotNull;

import java.util.Objects;

/**
* The IntelliJ launch mode.
*/
Expand Down Expand Up @@ -59,7 +61,7 @@ public static RunMode fromEnv(@NotNull ExecutionEnvironment env) throws Executio
else if (DefaultDebugExecutor.EXECUTOR_ID.equals(mode)) {
return DEBUG;
}
else if (COVERAGE.myModeString.equals(mode)) {
else if (Objects.equals(COVERAGE.myModeString, mode)) {
return COVERAGE;
}
else if (LaunchState.ANDROID_PROFILER_EXECUTOR_ID.equals(mode)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ private void tryParseStartupText(@NotNull String text) {

final JsonObject obj = element.getAsJsonObject();

if (JsonUtils.getStringMember(obj, "event").equals("server.started")) {
if (Objects.equals(JsonUtils.getStringMember(obj, "event"), "server.started")) {
final JsonObject params = obj.getAsJsonObject("params");
final String host = JsonUtils.getStringMember(params, "host");
final int port = JsonUtils.getIntMember(params, "port");
Expand Down
3 changes: 2 additions & 1 deletion flutter-idea/src/io/flutter/run/daemon/DeviceDaemon.java
Original file line number Diff line number Diff line change
Expand Up @@ -384,7 +384,8 @@ public void onDeviceAdded(@NotNull DaemonEvent.DeviceAdded event) {
final FlutterDevice newDevice = new FlutterDevice(event.id,
event.emulatorId == null
? (event.name == null ? event.id : event.name)
: (event.platformType.equals("android") ? event.emulatorId : event.name),
: (java.util.Objects.equals(event.platformType, "android")
? event.emulatorId : event.name),
event.platform,
event.emulator,
event.category,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Objects;

@SuppressWarnings("Duplicates")
public class DartTestLocationProviderZ implements SMTestLocator, DumbAware {
Expand Down Expand Up @@ -123,11 +124,11 @@ protected List<Location> getLocationByGroupAndTestNames(final PsiFile psiFile, f
public boolean execute(@NotNull final PsiElement element) {
if (element instanceof DartCallExpression expression) {
if (isTest(expression) || TestUtil.isGroup(expression)) {
if (nodes.get(nodes.size() - 1).equals(getTestLabel(expression))) {
if (Objects.equals(nodes.get(nodes.size() - 1), getTestLabel(expression))) {
boolean matches = true;
for (int i = nodes.size() - 2; i >= 0 && matches; --i) {
expression = getGroup(expression);
if (expression == null || !nodes.get(i).equals(getTestLabel(expression))) {
if (expression == null || !Objects.equals(nodes.get(i), getTestLabel(expression))) {
matches = false;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ private void fireChangeEvent(final List<AndroidEmulator> newEmulators, final Lis
if (project.isDisposed()) return;

// Don't fire if the list of devices is unchanged.
if (cachedEmulators.equals(newEmulators)) {
if (Objects.equals(cachedEmulators, newEmulators)) {
return;
}

Expand Down
2 changes: 1 addition & 1 deletion flutter-idea/src/io/flutter/sdk/FlutterSdk.java
Original file line number Diff line number Diff line change
Expand Up @@ -365,7 +365,7 @@ public FlutterCommand flutterTest(@NotNull PubRoot root, @NotNull VirtualFile fi

// Starting the app paused so the IDE can catch early errors is ideal. However, we don't have a way to resume for multiple test files
// yet, so we want to exclude directory scope tests from starting paused. See https://github.com/flutter/flutter-intellij/issues/4737.
if (mode == RunMode.DEBUG || (mode == RunMode.RUN && !scope.equals(TestFields.Scope.DIRECTORY))) {
if (mode == RunMode.DEBUG || (mode == RunMode.RUN && !Objects.equals(scope, TestFields.Scope.DIRECTORY))) {
args.add("--start-paused");
}
if (FlutterSettings.getInstance().isVerboseLogging()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
import javax.swing.text.JTextComponent;
import java.awt.datatransfer.StringSelection;
import java.util.List;
import java.util.Objects;
import java.util.concurrent.Semaphore;

// Note: when updating the settings here, update FlutterSearchableOptionContributor as well.
Expand Down Expand Up @@ -221,7 +222,7 @@ public boolean isModified() {
return true;
}

if (!settings.getFontPackages().equals(myFontPackagesTextArea.getText())) {
if (!Objects.equals(settings.getFontPackages(), myFontPackagesTextArea.getText())) {
return true;
}

Expand Down
11 changes: 4 additions & 7 deletions flutter-idea/src/io/flutter/test/DartTestEventsConverterZ.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,7 @@

import java.lang.reflect.Type;
import java.text.ParseException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.*;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

Expand Down Expand Up @@ -247,9 +244,9 @@ private static boolean shouldTestBeHiddenIfPassed(@NotNull final Test test) {
final Group group = test.getParent();
return group == null && (test.getName().startsWith(LOADING_PREFIX) || test.getName().startsWith(COMPILING_PREFIX))
||
group != null && group.getDoneTestsCount() == 0 && test.getBaseName().equals(SET_UP_ALL_VIRTUAL_TEST_NAME)
group != null && group.getDoneTestsCount() == 0 && Objects.equals(test.getBaseName(), SET_UP_ALL_VIRTUAL_TEST_NAME)
||
group != null && group.getDoneTestsCount() > 0 && test.getBaseName().equals(TEAR_DOWN_ALL_VIRTUAL_TEST_NAME);
group != null && group.getDoneTestsCount() > 0 && Objects.equals(test.getBaseName(), TEAR_DOWN_ALL_VIRTUAL_TEST_NAME);
}

private boolean handleTestDone(JsonObject obj) throws ParseException {
Expand Down Expand Up @@ -382,7 +379,7 @@ private boolean handlePrint(JsonObject obj) throws ParseException {
boolean result = true;

if (!test.myTestStartReported) {
if (test.getBaseName().equals(SET_UP_ALL_VIRTUAL_TEST_NAME) || test.getBaseName().equals(TEAR_DOWN_ALL_VIRTUAL_TEST_NAME)) {
if (Objects.equals(test.getBaseName(), SET_UP_ALL_VIRTUAL_TEST_NAME) || Objects.equals(test.getBaseName(), TEAR_DOWN_ALL_VIRTUAL_TEST_NAME)) {
return true; // output in successfully passing setUpAll/tearDownAll is not important enough to make these nodes visible
}

Expand Down
6 changes: 2 additions & 4 deletions flutter-idea/src/io/flutter/view/EmbeddedBrowser.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,8 @@

import javax.swing.*;
import java.awt.*;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.*;
import java.util.List;
import java.util.Map;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.function.Consumer;
Expand Down Expand Up @@ -126,7 +124,7 @@ public void openPanel(ToolWindow toolWindow, String tabName, DevToolsUrl devTool
tab.contentManager.removeAllContents(false);

for (final String otherTabName : tabs.keySet()) {
if (otherTabName.equals(tabName)) {
if (Objects.equals(otherTabName, tabName)) {
continue;
}
final BrowserTab browserTab = tabs.get(otherTabName);
Expand Down
Loading