From fb9bd6e851733d18824681a17f3c42465858c797 Mon Sep 17 00:00:00 2001 From: Zbynek Konecny Date: Wed, 3 Jun 2026 23:38:57 +0200 Subject: [PATCH 1/3] Fix empty ID assertion, simplify equality check --- user/src/com/google/gwt/aria/client/Id.java | 2 +- .../event/shared/testing/CountingEventBus.java | 12 +++--------- 2 files changed, 4 insertions(+), 10 deletions(-) diff --git a/user/src/com/google/gwt/aria/client/Id.java b/user/src/com/google/gwt/aria/client/Id.java index 3f43adb9c26..6b75cdb1954 100644 --- a/user/src/com/google/gwt/aria/client/Id.java +++ b/user/src/com/google/gwt/aria/client/Id.java @@ -66,7 +66,7 @@ public String getAriaValue() { } private void init(String elementId) { - assert elementId != null || elementId.equals("") : + assert elementId != null && !elementId.isEmpty() : "Invalid elementId: cannot be null or empty."; this.id = elementId; } diff --git a/user/src/com/google/web/bindery/event/shared/testing/CountingEventBus.java b/user/src/com/google/web/bindery/event/shared/testing/CountingEventBus.java index 3b717fa7d39..30ebd82f438 100644 --- a/user/src/com/google/web/bindery/event/shared/testing/CountingEventBus.java +++ b/user/src/com/google/web/bindery/event/shared/testing/CountingEventBus.java @@ -23,6 +23,7 @@ import java.util.HashMap; import java.util.Map; +import java.util.Objects; /** * Wraps an {@link EventBus} to keep a count of registered handlers and how many times events have @@ -130,8 +131,8 @@ public boolean equals(Object o) { return false; } - TypeSourcePair pair = (TypeSourcePair) o; - return doNullEquals(type, pair.type) && doNullEquals(source, pair.source); + TypeSourcePair pair = (TypeSourcePair) o; + return Objects.equals(type, pair.type) && Objects.equals(source, pair.source); } @Override @@ -141,13 +142,6 @@ public int hashCode() { hash = (hash * 31) + (source == null ? 0 : source.hashCode()); return hash; } - - private boolean doNullEquals(Object a, Object b) { - if ((a == null) ^ (b == null)) { - return false; - } - return ((a == null) && (b == null)) || a.equals(b); - } } private class KeyedCounter { From df3085f4dbf01099ee8eee65c37aab2c11ffae79 Mon Sep 17 00:00:00 2001 From: Zbynek Konecny Date: Thu, 4 Jun 2026 00:36:34 +0200 Subject: [PATCH 2/3] Missing instanceof check, remove duplications of Objects.equals --- user/src/com/google/gwt/cell/client/EditTextCell.java | 11 ++++------- .../gwt/user/cellview/client/ColumnSortList.java | 7 ++----- .../google/gwt/view/client/SingleSelectionModel.java | 9 +++------ 3 files changed, 9 insertions(+), 18 deletions(-) diff --git a/user/src/com/google/gwt/cell/client/EditTextCell.java b/user/src/com/google/gwt/cell/client/EditTextCell.java index 86a0788c41f..54abcc0e9e6 100644 --- a/user/src/com/google/gwt/cell/client/EditTextCell.java +++ b/user/src/com/google/gwt/cell/client/EditTextCell.java @@ -33,6 +33,7 @@ import com.google.gwt.text.shared.SimpleSafeHtmlRenderer; import java.util.Locale; +import java.util.Objects; /** * An editable text cell. Click to edit, escape to cancel, return to commit. @@ -83,12 +84,12 @@ public ViewData(String text) { @Override public boolean equals(Object o) { - if (o == null) { + if (!(o instanceof ViewData)) { return false; } ViewData vd = (ViewData) o; - return equalsOrBothNull(original, vd.original) - && equalsOrBothNull(text, vd.text) && isEditing == vd.isEditing + return Objects.equals(original, vd.original) + && Objects.equals(text, vd.text) && isEditing == vd.isEditing && isEditingAgain == vd.isEditingAgain; } @@ -129,10 +130,6 @@ public void setEditing(boolean isEditing) { public void setText(String text) { this.text = text; } - - private boolean equalsOrBothNull(Object o1, Object o2) { - return (o1 == null) ? o2 == null : o1.equals(o2); - } } private static Template template; diff --git a/user/src/com/google/gwt/user/cellview/client/ColumnSortList.java b/user/src/com/google/gwt/user/cellview/client/ColumnSortList.java index ad662303f75..59078241127 100644 --- a/user/src/com/google/gwt/user/cellview/client/ColumnSortList.java +++ b/user/src/com/google/gwt/user/cellview/client/ColumnSortList.java @@ -17,6 +17,7 @@ import java.util.ArrayList; import java.util.List; +import java.util.Objects; /** * An ordered list containing the sort history of {@link Column}s in a table. @@ -67,7 +68,7 @@ public boolean equals(Object obj) { } ColumnSortInfo other = (ColumnSortInfo) obj; - return equalsOrBothNull(getColumn(), other.getColumn()) + return Objects.equals(getColumn(), other.getColumn()) && isAscending() == other.isAscending(); } @@ -93,10 +94,6 @@ public int hashCode() { public boolean isAscending() { return ascending; } - - private boolean equalsOrBothNull(Object a, Object b) { - return a == null ? b == null : a.equals(b); - } } /** diff --git a/user/src/com/google/gwt/view/client/SingleSelectionModel.java b/user/src/com/google/gwt/view/client/SingleSelectionModel.java index 9c84c8b7c3a..2d7a22e25f2 100644 --- a/user/src/com/google/gwt/view/client/SingleSelectionModel.java +++ b/user/src/com/google/gwt/view/client/SingleSelectionModel.java @@ -18,6 +18,7 @@ import com.google.gwt.view.client.SelectionModel.AbstractSelectionModel; import java.util.HashSet; +import java.util.Objects; import java.util.Set; /** @@ -93,7 +94,7 @@ public void setSelected(T item, boolean selected) { if (!selected) { Object oldKey = newSelectedPending ? getKey(newSelectedItem) : curKey; Object newKey = getKey(item); - if (!equalsOrBothNull(oldKey, newKey)) { + if (!Objects.equals(oldKey, newKey)) { return; } } @@ -111,17 +112,13 @@ protected void fireSelectionChangeEvent() { resolveChanges(); } - private boolean equalsOrBothNull(Object a, Object b) { - return (a == null) ? (b == null) : a.equals(b); - } - private void resolveChanges() { if (!newSelectedPending) { return; } Object key = getKey(newSelectedItem); - boolean sameKey = equalsOrBothNull(curKey, key); + boolean sameKey = Objects.equals(curKey, key); boolean changed = false; if (newSelected) { changed = !sameKey; From e8c0b3e9e9371c171e98bb3dc1ea75f3320c68e6 Mon Sep 17 00:00:00 2001 From: Zbynek Konecny Date: Mon, 8 Jun 2026 18:02:27 +0200 Subject: [PATCH 3/3] Remove extra whitespace Co-authored-by: Colin Alworth --- user/src/com/google/gwt/cell/client/EditTextCell.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/user/src/com/google/gwt/cell/client/EditTextCell.java b/user/src/com/google/gwt/cell/client/EditTextCell.java index 54abcc0e9e6..b64e4ca2085 100644 --- a/user/src/com/google/gwt/cell/client/EditTextCell.java +++ b/user/src/com/google/gwt/cell/client/EditTextCell.java @@ -84,7 +84,7 @@ public ViewData(String text) { @Override public boolean equals(Object o) { - if (!(o instanceof ViewData)) { + if (!(o instanceof ViewData)) { return false; } ViewData vd = (ViewData) o;