From 99644868bdd33fe1ef061bc6375295bb159ca513 Mon Sep 17 00:00:00 2001 From: Bauke Scholtz Date: Thu, 26 Dec 2024 12:37:23 -0400 Subject: [PATCH] Fix identity of BindingFacesMessage; it broke since introduction of equals/hashCode for FacesMessage in https://github.com/jakartaee/faces/issues/1823 Reproducer: trigger 2 different bean validation errors on the same property --- .../java/com/sun/faces/util/MessageFactory.java | 14 ++++++++++++++ .../jakarta/faces/validator/MessageFactory.java | 14 ++++++++++++++ 2 files changed, 28 insertions(+) diff --git a/impl/src/main/java/com/sun/faces/util/MessageFactory.java b/impl/src/main/java/com/sun/faces/util/MessageFactory.java index 83fc14ed16..c4f96c2f2e 100644 --- a/impl/src/main/java/com/sun/faces/util/MessageFactory.java +++ b/impl/src/main/java/com/sun/faces/util/MessageFactory.java @@ -19,6 +19,7 @@ import java.text.MessageFormat; import java.util.Locale; import java.util.MissingResourceException; +import java.util.Objects; import java.util.ResourceBundle; import jakarta.el.ValueExpression; @@ -322,6 +323,19 @@ private String getFormattedString(String msgtext, Object[] params) { private final Locale locale; private final Object[] parameters; private Object[] resolvedParameters; + + @Override + public int hashCode() { + return Objects.hash(super.hashCode(), locale, parameters, resolvedParameters); + } + + @Override + public boolean equals(Object object) { + return super.equals(object) + && Objects.equals(locale, ((BindingFacesMessage) object).locale) + && Objects.equals(parameters, ((BindingFacesMessage) object).parameters) + && Objects.equals(resolvedParameters, ((BindingFacesMessage) object).resolvedParameters); + } } } // end of class MessageFactory diff --git a/impl/src/main/java/jakarta/faces/validator/MessageFactory.java b/impl/src/main/java/jakarta/faces/validator/MessageFactory.java index c38e8aaef1..3a6e9abeff 100644 --- a/impl/src/main/java/jakarta/faces/validator/MessageFactory.java +++ b/impl/src/main/java/jakarta/faces/validator/MessageFactory.java @@ -19,6 +19,7 @@ import java.text.MessageFormat; import java.util.Locale; import java.util.MissingResourceException; +import java.util.Objects; import java.util.ResourceBundle; import jakarta.el.ValueExpression; @@ -322,6 +323,19 @@ private String getFormattedString(String msgtext, Object[] params) { private Locale locale; private Object[] parameters; private Object[] resolvedParameters; + + @Override + public int hashCode() { + return Objects.hash(super.hashCode(), locale, parameters, resolvedParameters); + } + + @Override + public boolean equals(Object object) { + return super.equals(object) + && Objects.equals(locale, ((BindingFacesMessage) object).locale) + && Objects.equals(parameters, ((BindingFacesMessage) object).parameters) + && Objects.equals(resolvedParameters, ((BindingFacesMessage) object).resolvedParameters); + } } } // end of class MessageFactory