Skip to content

Improved: Copy item groups parent first in the ShoppingCart copy constructor (OFBIZ-13753) - #2510

Merged
mridulpathak merged 1 commit into
apache:trunkfrom
mridulpathak:OFBIZ-13753
Oct 30, 2026
Merged

mridulpathak merged 1 commit into
apache:trunkfrom
mridulpathak:OFBIZ-13753

Conversation

@mridulpathak

Copy link
Copy Markdown
Contributor

The ShoppingCart copy constructor, also used by WebShoppingCart, cloned the item groups in HashMap iteration order and looked each parent up among the groups cloned so far through the overridable getItemGroupByNumber method. javac reports that call as this-escape, and the order made a group returned before its parent lose its parent: with groups 01 to 11, the map returns group 11 first. A private static copyItemGroup now copies each parent before its children, which removes the warning. The copied items, which kept the groups of the original cart, now belong to the copied groups, and the copy continues nextGroupNumber and nextItemSeq instead of restarting them at 1, so a group added to the copy no longer replaces group 01. Nothing in the framework, applications, themes or plugins calls the copy constructor, so this is fixed on trunk only. ShoppingCart, WebShoppingCart and ShoppingCartItem stay open for extension, and no constructor changes. This removes the this-escape warning for the shopping cart under JDK 25.

- The copy constructor cloned the item groups in HashMap order and looked each parent up among the groups cloned so far, so a group returned before its parent (group 11 among groups 01 to 11) lost its parent. A private static copyItemGroup now copies each parent before its children, which also removes the this-escape warning from the getItemGroupByNumber call.
- The copied items kept the groups of the original cart; they now belong to the copied groups.
- The copy now continues nextGroupNumber and nextItemSeq instead of restarting them at 1, so a group added to the copy no longer replaces group 01.
@mridulpathak
mridulpathak merged commit eabcf68 into apache:trunk Oct 30, 2026
7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant