This is an automated email from the ASF dual-hosted git repository. jleroux pushed a commit to branch trunk in repository https://gitbox.apache.org/repos/asf/ofbiz-framework.git
The following commit(s) were added to refs/heads/trunk by this push: new 90995f0 Fixed: Webapp Position overrides older entries. (OFBIZ-12496) (#454) 90995f0 is described below commit 90995f090f820888b1aec06d93a546e07448fd55 Author: bjugl <61057136+bj...@users.noreply.github.com> AuthorDate: Fri Jan 28 10:25:11 2022 +0100 Fixed: Webapp Position overrides older entries. (OFBIZ-12496) (#454) --- .../src/main/java/org/apache/ofbiz/webapp/WebAppCache.java | 2 +- .../src/test/java/org/apache/ofbiz/webapp/WebAppCacheTest.java | 10 +++++++--- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/framework/webapp/src/main/java/org/apache/ofbiz/webapp/WebAppCache.java b/framework/webapp/src/main/java/org/apache/ofbiz/webapp/WebAppCache.java index 8a66060..dd5f543 100644 --- a/framework/webapp/src/main/java/org/apache/ofbiz/webapp/WebAppCache.java +++ b/framework/webapp/src/main/java/org/apache/ofbiz/webapp/WebAppCache.java @@ -107,7 +107,7 @@ public class WebAppCache { Integer key = null; try { key = Integer.valueOf(stringKey); - key = (key != null) ? key : emptyPosition.incrementAndGet(); + key = (key != null) && !acc.containsKey(key) ? key : emptyPosition.incrementAndGet(); } catch (NumberFormatException e) { key = emptyPosition.incrementAndGet(); } diff --git a/framework/webapp/src/test/java/org/apache/ofbiz/webapp/WebAppCacheTest.java b/framework/webapp/src/test/java/org/apache/ofbiz/webapp/WebAppCacheTest.java index 522b008..d54e772 100644 --- a/framework/webapp/src/test/java/org/apache/ofbiz/webapp/WebAppCacheTest.java +++ b/framework/webapp/src/test/java/org/apache/ofbiz/webapp/WebAppCacheTest.java @@ -93,17 +93,21 @@ public class WebAppCacheTest { } // Checks that when the same position is provided by the `WebappInfo` instance - // only one is retrieved + // both are received, but the later one is shifted to the end (position 999) @Test public void getAppBarWebInfosSamePosition() { WebappInfo wInfo0 = new WebappInfo.Builder().server("foo").title("foo").position("1").create(); wInfos.add(wInfo0); - WebappInfo wInfo1 = new WebappInfo.Builder().server("foo").title("foo").position("1").create(); + WebappInfo wInfo1 = new WebappInfo.Builder().server("foo").title("bar").position("14").create(); wInfos.add(wInfo1); + WebappInfo wInfo2 = new WebappInfo.Builder().server("foo").title("fo").position("1").create(); + wInfos.add(wInfo2); // Ensure that there is a collision between `wInfo0` and `wInfo1` // and only one of them are retrieved. - assertThat(wac.getAppBarWebInfos("foo").size(), is(1)); + assertThat(wac.getAppBarWebInfos("foo").get(0), is(wInfo0)); + assertThat(wac.getAppBarWebInfos("foo").get(1), is(wInfo1)); + assertThat(wac.getAppBarWebInfos("foo").get(2), is(wInfo2)); } // Checks that when the same title with no position is provided by the `WebappInfo` instance