Repository navigation
Improved: Copy item groups parent first in the ShoppingCart copy constructor (OFBIZ-13753) - #2510
Merged
Merged
Conversation
- 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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.