Skip to content

MYFACES-4770: ViewScopeCDIMap.put() returns the previous value - #1112

Merged
tandraschko merged 1 commit into
apache:mainfrom
jungm:MYFACES-4770
Oct 12, 2026
Merged

tandraschko merged 1 commit into
apache:mainfrom
jungm:MYFACES-4770

Conversation

@jungm

@jungm jungm commented Oct 12, 2026

Copy link
Copy Markdown
Member

https://issues.apache.org/jira/browse/MYFACES-4770

Summary

ViewScopeCDIMap.put() returned the previous internal ContextualInstanceInfo wrapper instead of the previous value, breaking the java.util.Map#put contract that UIViewRoot#getViewMap() exposes. It now unwraps the result the same way get() and remove() already do:

 ContextualInstanceInfo info = new ContextualInstanceInfo();
 info.setContextualInstance(value);
-return getCreationalContextInstances().put(beanKey, info);
+ContextualInstanceInfo previous = getCreationalContextInstances().put(beanKey, info);
+return previous == null ? null : previous.getContextualInstance();

Evidence

New ViewScopeCDIMapTest (CDI request test case, so the view map is backed by ViewScopeCDIMap):

viewMap.put("key", "first")   -> null
viewMap.put("key", "second")  -> "first"
viewMap.get("key")            -> "second"
  • Before: AssertionFailedError: expected: <first> but was: <org.apache.myfaces.cdi.util.ContextualInstanceInfo@42273aa0>
    After: passes; impl 1710 tests, 0 failures, 0 errors (JDK 17)

Merge Danger

Door: two-way

Blast Radius: small

Only callers that use the return value of getViewMap().put(...) with CDI enabled see a difference, and they now get the value the Map contract promises instead of a MyFaces-internal object. Nothing inside MyFaces reads that return value.

@tandraschko
tandraschko merged commit e66ffaf into apache:main Oct 12, 2026
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants