mbien commented on code in PR #8407:
URL: https://github.com/apache/netbeans/pull/8407#discussion_r2035291890


##########
platform/openide.dialogs/src/org/openide/NotifyDescriptor.java:
##########
@@ -129,24 +130,50 @@ public class NotifyDescriptor extends Object {
      */
     public static final String PROP_INFO_NOTIFICATION = "infoNotification"; // 
NOI18N
 
+    /**
+     * Used to be a <code>new Integer(JOptionPane.FOO_OPTION)</code> instance.
+     *
+     * For compatibility reasons the public Object constants must have distinct
+     * identity, but equals must behave like Integer's equals and compare only
+     * the wrapped int like a Record.
+     */
+    private record ReturnValue(int option) implements Serializable, 
Comparable<ReturnValue> {
+
+        @Override
+        public String toString() {
+            return String.valueOf(option);
+        }
+
+        @Override
+        public int hashCode() {
+            return Integer.hashCode(option);
+        }
+
+        @Override
+        public int compareTo(ReturnValue other) {
+            return Integer.compare(option, other.option);
+        }
+
+    }
+
     //
     // Return values
     //
 
     /** Return value if YES is chosen. */
-    public static final Object YES_OPTION = new 
Integer(JOptionPane.YES_OPTION);
+    public static final Object YES_OPTION = new 
ReturnValue(JOptionPane.YES_OPTION);

Review Comment:
   it could be a problem but is likely unavoidable. The API promises to return 
Object, by comparing it like that, you make the assumption that the object is 
an Integer, since the right hand side is a unboxed int:
   
   The way to mitigate it would be to let equals of `ReturnValue` accept 
Integer too. But this breaks the equals symmetry rule, since this can't be 
implemented for the other way around. This would cause other problems which are 
likely worse.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscr...@netbeans.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscr...@netbeans.apache.org
For additional commands, e-mail: notifications-h...@netbeans.apache.org

For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists

Reply via email to