Skip to content

Commit ba4e767

Browse files
author
Roger Riggs
committed
8366841: [lworld] Objects.equals without identity comparison
Reviewed-by: liach
1 parent 94cca4b commit ba4e767

File tree

2 files changed

+9
-3
lines changed

2 files changed

+9
-3
lines changed

src/java.base/share/classes/java/util/Objects.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
package java.util;
2727

2828
import jdk.internal.javac.PreviewFeature;
29+
import jdk.internal.misc.PreviewFeatures;
2930
import jdk.internal.util.Preconditions;
3031
import jdk.internal.vm.annotation.ForceInline;
3132

@@ -60,7 +61,12 @@ private Objects() {
6061
* @see Object#equals(Object)
6162
*/
6263
public static boolean equals(Object a, Object b) {
63-
return (a == b) || (a != null && a.equals(b));
64+
if (PreviewFeatures.isEnabled()) {
65+
// With --enable-preview avoid acmp
66+
return (a == null) ? b == null : a.equals(b);
67+
} else {
68+
return (a == b) || (a != null && a.equals(b));
69+
}
6470
}
6571

6672
/**

test/jdk/java/io/Serializable/valueObjects/SimpleValueGraphs.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 1999, 2024, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 1999, 2025, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -237,7 +237,7 @@ public SimpleValue(Serializable o, int i) {
237237

238238
public boolean equals(Object obj) {
239239
if (obj instanceof SimpleValue simpleValue) {
240-
return (i == simpleValue.i && Objects.equals(obj, simpleValue));
240+
return (i == simpleValue.i && Objects.equals(this.obj, simpleValue.obj));
241241
}
242242
return false;
243243
}

0 commit comments

Comments
 (0)