cziegeler closed pull request #2: SLING-7375 Moving order using overlapping 
children causing IndexOutOf?
URL: https://github.com/apache/sling-org-apache-sling-resourcemerger/pull/2
 
 
   

This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:

As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):

diff --git 
a/src/main/java/org/apache/sling/resourcemerger/impl/MergingResourceProvider.java
 
b/src/main/java/org/apache/sling/resourcemerger/impl/MergingResourceProvider.java
index 3ba9c9e..d34d219 100644
--- 
a/src/main/java/org/apache/sling/resourcemerger/impl/MergingResourceProvider.java
+++ 
b/src/main/java/org/apache/sling/resourcemerger/impl/MergingResourceProvider.java
@@ -385,7 +385,11 @@ public Resource getResource(final ResolveContext<Void> 
ctx, final String path, f
                             if (childPositionInCandidateList < 
previousChildPositionInCandidateList) {
                                 previousChildPositionInCandidateList--;
                             }
-                            
candidates.add(previousChildPositionInCandidateList+1, holder);
+                            if(previousChildPositionInCandidateList+1 > 
candidates.size()){
+                                candidates.add(holder);
+                            } else {
+                                
candidates.add(previousChildPositionInCandidateList + 1, holder);
+                            }
                             previousChildPositionInCandidateList++;
                         }
                     }
diff --git 
a/src/test/java/org/apache/sling/resourcemerger/impl/CommonMergedResourceProviderTest.java
 
b/src/test/java/org/apache/sling/resourcemerger/impl/CommonMergedResourceProviderTest.java
index 07c1904..900f7ad 100644
--- 
a/src/test/java/org/apache/sling/resourcemerger/impl/CommonMergedResourceProviderTest.java
+++ 
b/src/test/java/org/apache/sling/resourcemerger/impl/CommonMergedResourceProviderTest.java
@@ -343,7 +343,8 @@ public void 
testOrderOfPartiallyOverlappingChildrenWithDifferentOrder() throws P
         
         Assert.assertThat(iterable, 
Matchers.contains(ResourceMatchers.name("child5"),ResourceMatchers.name("child2"),
 ResourceMatchers.name("child3"), 
ResourceMatchers.name("child4"),ResourceMatchers.name("child1")));
     }
-    
+
+
     @Test
     public void testOrderOfNonOverlappingChildren() throws 
PersistenceException {
         // create new child nodes below base and overlay
@@ -418,4 +419,23 @@ public void testOrderBeingModifiedThroughOrderBefore() 
throws PersistenceExcepti
         
         Assert.assertThat(iterable, 
Matchers.contains(ResourceMatchers.name("child1"),ResourceMatchers.name("child5"),
 ResourceMatchers.name("child6"), ResourceMatchers.name("child2"), 
ResourceMatchers.name("child8"),ResourceMatchers.name("child9"), 
ResourceMatchers.name("child7"),ResourceMatchers.name("child4"),ResourceMatchers.name("child10"),ResourceMatchers.name("child3")));
     }
+
+    @Test
+    public void 
testOrderBeingModifiedThroughOrderBeforeAndFullyOverlappingChildren() throws 
PersistenceException {
+
+        // create new child nodes below base and overlay
+        MockHelper.create(this.resolver)
+                .resource("/apps/base/child1")
+                .resource("/apps/base/child2")
+                .resource("/apps/overlay/child1")
+                
.resource("/apps/overlay/child3").p(MergedResourceConstants.PN_ORDER_BEFORE, 
"child2")
+                .resource("/apps/overlay/child2")
+                .commit();
+
+        Resource mergedResource = this.provider.getResource(ctx, "/merged", 
ResourceContext.EMPTY_CONTEXT, null);
+        // convert the iterator returned by list children into an iterable (to 
be able to perform some tests)
+        IteratorIterable<Resource> iterable = new 
IteratorIterable<Resource>(provider.listChildren(ctx, mergedResource), true);
+
+        Assert.assertThat(iterable, 
Matchers.contains(ResourceMatchers.name("child1"),ResourceMatchers.name("child3"),ResourceMatchers.name("child2")));
+    }
 }


 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
[email protected]


With regards,
Apache Git Services

Reply via email to