You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@myfaces.apache.org by ta...@apache.org on 2026/10/12 12:18:29 UTC

(myfaces) branch 4.0.x updated: MYFACES-4770 viewscopecdimap.put() returns the previous value (#1114)

This is an automated email from the ASF dual-hosted git repository.

tandraschko pushed a commit to branch 4.0.x
in repository https://gitbox.apache.org/repos/asf/myfaces.git


The following commit(s) were added to refs/heads/4.0.x by this push:
     new 152bc9bee MYFACES-4770 viewscopecdimap.put() returns the previous value (#1114)
152bc9bee is described below

commit 152bc9bee9c7d3ff4e5a6fce854db080cbe50c01
Author: Markus Jung <ju...@apache.org>
AuthorDate: Mon Oct 12 14:18:23 2026 +0200

    MYFACES-4770 viewscopecdimap.put() returns the previous value (#1114)
---
 .../apache/myfaces/cdi/view/ViewScopeCDIMap.java   |  3 +-
 .../myfaces/cdi/view/ViewScopeCDIMapTest.java      | 43 ++++++++++++++++++++++
 .../apache/myfaces/cdi/view/viewScopeCDIMap.xhtml  | 29 +++++++++++++++
 3 files changed, 74 insertions(+), 1 deletion(-)

diff --git a/impl/src/main/java/org/apache/myfaces/cdi/view/ViewScopeCDIMap.java b/impl/src/main/java/org/apache/myfaces/cdi/view/ViewScopeCDIMap.java
index 2d6757c0e..9bfd38375 100644
--- a/impl/src/main/java/org/apache/myfaces/cdi/view/ViewScopeCDIMap.java
+++ b/impl/src/main/java/org/apache/myfaces/cdi/view/ViewScopeCDIMap.java
@@ -133,7 +133,8 @@ public Object put(String key, Object value)
 
         ContextualInstanceInfo info = new ContextualInstanceInfo();
         info.setContextualInstance(value);
-        return getCreationalContextInstances().put(beanKey, info);
+        ContextualInstanceInfo previous = getCreationalContextInstances().put(beanKey, info);
+        return previous == null ? null : previous.getContextualInstance();
     }
 
     @Override
diff --git a/impl/src/test/java/org/apache/myfaces/cdi/view/ViewScopeCDIMapTest.java b/impl/src/test/java/org/apache/myfaces/cdi/view/ViewScopeCDIMapTest.java
new file mode 100644
index 000000000..7fc2487c7
--- /dev/null
+++ b/impl/src/test/java/org/apache/myfaces/cdi/view/ViewScopeCDIMapTest.java
@@ -0,0 +1,43 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.myfaces.cdi.view;
+
+import java.util.Map;
+
+import org.apache.myfaces.test.core.AbstractMyFacesCDIRequestTestCase;
+import org.apache.myfaces.view.ViewScopeProxyMap;
+import org.junit.jupiter.api.Assertions;
+import org.junit.jupiter.api.Test;
+
+public class ViewScopeCDIMapTest extends AbstractMyFacesCDIRequestTestCase
+{
+    @Test
+    public void testPutReturnsPreviousValue() throws Exception
+    {
+        startViewRequest("/viewScopeCDIMap.xhtml");
+        processLifecycleExecuteAndRender();
+
+        Map<String, Object> viewMap = facesContext.getViewRoot().getViewMap();
+        Assertions.assertInstanceOf(ViewScopeCDIMap.class, ((ViewScopeProxyMap) viewMap).getDelegate());
+
+        Assertions.assertNull(viewMap.put("key", "first"));
+        Assertions.assertEquals("first", viewMap.put("key", "second"));
+        Assertions.assertEquals("second", viewMap.get("key"));
+    }
+}
diff --git a/impl/src/test/resources/org/apache/myfaces/cdi/view/viewScopeCDIMap.xhtml b/impl/src/test/resources/org/apache/myfaces/cdi/view/viewScopeCDIMap.xhtml
new file mode 100644
index 000000000..53a6394b6
--- /dev/null
+++ b/impl/src/test/resources/org/apache/myfaces/cdi/view/viewScopeCDIMap.xhtml
@@ -0,0 +1,29 @@
+<!--
+    Licensed to the Apache Software Foundation (ASF) under one
+    or more contributor license agreements.  See the NOTICE file
+    distributed with this work for additional information
+    regarding copyright ownership.  The ASF licenses this file
+    to you under the Apache License, Version 2.0 (the
+    "License"); you may not use this file except in compliance
+    with the License.  You may obtain a copy of the License at
+
+    http://www.apache.org/licenses/LICENSE-2.0
+
+    Unless required by applicable law or agreed to in writing,
+    software distributed under the License is distributed on an
+    "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+    KIND, either express or implied.  See the License for the
+    specific language governing permissions and limitations
+    under the License.
+-->
+<!DOCTYPE html>
+<html xmlns="http://www.w3.org/1999/xhtml"
+    xmlns:h="jakarta.faces.html">
+
+<h:head>
+    <title>ViewScopeCDIMap Test</title>
+</h:head>
+
+<h:body>
+</h:body>
+</html>