You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@sling.apache.org by "RemoLiechti (via GitHub)" <gi...@apache.org> on 2025/05/27 07:32:20 UTC

[PR] SLING-12801 call reset for errors also when dispatcher contract viola… [sling-org-apache-sling-engine]

RemoLiechti opened a new pull request, #62:
URL: https://github.com/apache/sling-org-apache-sling-engine/pull/62

   …tion checks are enabled
   
   Setting a dispatching info of type error to indicate the error flow so that this can be respected during reset


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscribe@sling.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] SLING-12801 - Error handler does not reset the response during include [sling-org-apache-sling-engine]

Posted by "sonarqubecloud[bot] (via GitHub)" <gi...@apache.org>.
sonarqubecloud[bot] commented on PR #62:
URL: https://github.com/apache/sling-org-apache-sling-engine/pull/62#issuecomment-2933473897

   ## [![Quality Gate Passed](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/checks/QualityGateBadge/qg-passed-20px.png 'Quality Gate Passed')](https://sonarcloud.io/dashboard?id=apache_sling-org-apache-sling-engine&pullRequest=62) **Quality Gate passed**  
   Issues  
   ![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/passed-16px.png '') [1 New issue](https://sonarcloud.io/project/issues?id=apache_sling-org-apache-sling-engine&pullRequest=62&issueStatuses=OPEN,CONFIRMED&sinceLeakPeriod=true)  
   ![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/accepted-16px.png '') [0 Accepted issues](https://sonarcloud.io/project/issues?id=apache_sling-org-apache-sling-engine&pullRequest=62&issueStatuses=ACCEPTED)
   
   Measures  
   ![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/passed-16px.png '') [0 Security Hotspots](https://sonarcloud.io/project/security_hotspots?id=apache_sling-org-apache-sling-engine&pullRequest=62&issueStatuses=OPEN,CONFIRMED&sinceLeakPeriod=true)  
   ![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/passed-16px.png '') [93.5% Coverage on New Code](https://sonarcloud.io/component_measures?id=apache_sling-org-apache-sling-engine&pullRequest=62&metric=new_coverage&view=list)  
   ![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/passed-16px.png '') [0.0% Duplication on New Code](https://sonarcloud.io/component_measures?id=apache_sling-org-apache-sling-engine&pullRequest=62&metric=new_duplicated_lines_density&view=list)  
     
   [See analysis details on SonarQube Cloud](https://sonarcloud.io/dashboard?id=apache_sling-org-apache-sling-engine&pullRequest=62)
   
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscribe@sling.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] SLING-12801 - Error handler does not reset the response during include [sling-org-apache-sling-engine]

Posted by "cziegeler (via GitHub)" <gi...@apache.org>.
cziegeler commented on code in PR #62:
URL: https://github.com/apache/sling-org-apache-sling-engine/pull/62#discussion_r2108519034


##########
src/main/java/org/apache/sling/engine/impl/SlingHttpServletResponseImpl.java:
##########
@@ -325,7 +330,7 @@ private String getCurrentStackTrace() {
 
     @Override
     public void setContentType(final String type) {
-        if (super.getResponse().isCommitted() || !isInclude()) {
+        if (super.isCommitted() || !isInclude()) {

Review Comment:
   this.isCommitted



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscribe@sling.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] SLING-12801 - Error handler does not reset the response during include [sling-org-apache-sling-engine]

Posted by "sonarqubecloud[bot] (via GitHub)" <gi...@apache.org>.
sonarqubecloud[bot] commented on PR #62:
URL: https://github.com/apache/sling-org-apache-sling-engine/pull/62#issuecomment-2921735415

   ## [![Quality Gate Passed](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/checks/QualityGateBadge/qg-passed-20px.png 'Quality Gate Passed')](https://sonarcloud.io/dashboard?id=apache_sling-org-apache-sling-engine&pullRequest=62) **Quality Gate passed**  
   Issues  
   ![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/passed-16px.png '') [2 New issues](https://sonarcloud.io/project/issues?id=apache_sling-org-apache-sling-engine&pullRequest=62&issueStatuses=OPEN,CONFIRMED&sinceLeakPeriod=true)  
   ![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/accepted-16px.png '') [0 Accepted issues](https://sonarcloud.io/project/issues?id=apache_sling-org-apache-sling-engine&pullRequest=62&issueStatuses=ACCEPTED)
   
   Measures  
   ![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/passed-16px.png '') [0 Security Hotspots](https://sonarcloud.io/project/security_hotspots?id=apache_sling-org-apache-sling-engine&pullRequest=62&issueStatuses=OPEN,CONFIRMED&sinceLeakPeriod=true)  
   ![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/passed-16px.png '') [93.5% Coverage on New Code](https://sonarcloud.io/component_measures?id=apache_sling-org-apache-sling-engine&pullRequest=62&metric=new_coverage&view=list)  
   ![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/passed-16px.png '') [0.0% Duplication on New Code](https://sonarcloud.io/component_measures?id=apache_sling-org-apache-sling-engine&pullRequest=62&metric=new_duplicated_lines_density&view=list)  
     
   [See analysis details on SonarQube Cloud](https://sonarcloud.io/dashboard?id=apache_sling-org-apache-sling-engine&pullRequest=62)
   
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscribe@sling.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] SLING-12801 - Error handler does not reset the response during include [sling-org-apache-sling-engine]

Posted by "cziegeler (via GitHub)" <gi...@apache.org>.
cziegeler commented on code in PR #62:
URL: https://github.com/apache/sling-org-apache-sling-engine/pull/62#discussion_r2108657279


##########
src/main/java/org/apache/sling/engine/impl/SlingHttpServletResponseImpl.java:
##########
@@ -220,12 +225,12 @@ public void setStatus(final int sc, final String msg) {
 
     @Override
     public void reset() {
-        if (!this.isProtectHeadersOnInclude()) {
+        if (!this.isProtectHeadersOnInclude() || isError()) {
             super.reset();
         } else {
             // ignore if not committed
-            if (getResponse().isCommitted()) {
-                getResponse().reset();
+            if (super.isCommitted()) {

Review Comment:
   yes cleaner



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscribe@sling.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] SLING-12801 - Error handler does not reset the response during include [sling-org-apache-sling-engine]

Posted by "raducotescu (via GitHub)" <gi...@apache.org>.
raducotescu commented on code in PR #62:
URL: https://github.com/apache/sling-org-apache-sling-engine/pull/62#discussion_r2108526466


##########
src/main/java/org/apache/sling/engine/impl/filter/ErrorFilterChain.java:
##########
@@ -118,6 +121,10 @@ public void doFilter(final ServletRequest request, final ServletResponse respons
                 return;
             }
             // reset the response to clear headers and body
+            if (response instanceof SlingHttpServletResponseImpl) {
+                final DispatchingInfo dispatchInfo = new DispatchingInfo(DispatcherType.ERROR);
+                ((SlingHttpServletResponseImpl) response).getRequestData().setDispatchingInfo(dispatchInfo);
+            }

Review Comment:
   Why don't you reuse the existing `DispachingInfo`? I would expose a setter in it for the `DispatcherType`, call it and then reset.



##########
src/main/java/org/apache/sling/engine/impl/SlingHttpServletResponseImpl.java:
##########
@@ -220,12 +225,12 @@ public void setStatus(final int sc, final String msg) {
 
     @Override
     public void reset() {
-        if (!this.isProtectHeadersOnInclude()) {
+        if (!this.isProtectHeadersOnInclude() || isError()) {
             super.reset();
         } else {
             // ignore if not committed
-            if (getResponse().isCommitted()) {
-                getResponse().reset();
+            if (super.isCommitted()) {
+                super.reset();

Review Comment:
   The code did and still does something else than the comment says:
   ```suggestion
               if (!isCommitted()) {
                   super.reset();
   ```



##########
src/main/java/org/apache/sling/engine/impl/SlingHttpServletResponseImpl.java:
##########
@@ -325,7 +330,7 @@ private String getCurrentStackTrace() {
 
     @Override
     public void setContentType(final String type) {
-        if (super.getResponse().isCommitted() || !isInclude()) {
+        if (super.isCommitted() || !isInclude()) {

Review Comment:
   ```suggestion
           if (!isCommitted() || !isInclude()) {
   ```



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscribe@sling.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] SLING-12801 - Error handler does not reset the response during include [sling-org-apache-sling-engine]

Posted by "cziegeler (via GitHub)" <gi...@apache.org>.
cziegeler commented on code in PR #62:
URL: https://github.com/apache/sling-org-apache-sling-engine/pull/62#discussion_r2108551035


##########
src/main/java/org/apache/sling/engine/impl/filter/ErrorFilterChain.java:
##########
@@ -118,6 +121,10 @@ public void doFilter(final ServletRequest request, final ServletResponse respons
                 return;
             }
             // reset the response to clear headers and body
+            if (response instanceof SlingHttpServletResponseImpl) {
+                final DispatchingInfo dispatchInfo = new DispatchingInfo(DispatcherType.ERROR);
+                ((SlingHttpServletResponseImpl) response).getRequestData().setDispatchingInfo(dispatchInfo);
+            }

Review Comment:
   and I think the dispatching info should be reset to what it was before after the filter is called



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscribe@sling.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] SLING-12801 - Error handler does not reset the response during include [sling-org-apache-sling-engine]

Posted by "cziegeler (via GitHub)" <gi...@apache.org>.
cziegeler commented on code in PR #62:
URL: https://github.com/apache/sling-org-apache-sling-engine/pull/62#discussion_r2122756575


##########
src/main/java/org/apache/sling/engine/impl/filter/ErrorFilterChain.java:
##########
@@ -117,8 +120,30 @@ public void doFilter(final ServletRequest request, final ServletResponse respons
                 }
                 return;
             }
+
             // reset the response to clear headers and body
-            response.reset();
+            if (response instanceof SlingHttpServletResponseImpl) {
+                SlingHttpServletResponseImpl slingResponse = (SlingHttpServletResponseImpl) response;
+                /*
+                 * Below section stores the original dispatching info for later restoration.
+                 * This is necessary to ensure that the dispatching info is set to ERROR
+                 * while the error is being handled and the response is reset, but restored to
+                 * its original state after the error handling is complete. This is important
+                 * for correct request processing and to avoid side effects on subsequent
+                 * filters or request processing steps.
+                 */
+                DispatchingInfo originalInfo = null;
+                try {
+                    originalInfo = slingResponse.getRequestData().getDispatchingInfo();
+                    final DispatchingInfo dispatchInfo = new DispatchingInfo(DispatcherType.ERROR);
+                    slingResponse.getRequestData().setDispatchingInfo(dispatchInfo);
+                    response.reset();

Review Comment:
   The super.doFilter() needs to be included here as well. The actual error handler might want to set a content type or any other header which otherwise might be ignored



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscribe@sling.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] SLING-12801 - Error handler does not reset the response during include [sling-org-apache-sling-engine]

Posted by "RemoLiechti (via GitHub)" <gi...@apache.org>.
RemoLiechti commented on code in PR #62:
URL: https://github.com/apache/sling-org-apache-sling-engine/pull/62#discussion_r2109055218


##########
src/main/java/org/apache/sling/engine/impl/SlingHttpServletResponseImpl.java:
##########
@@ -325,7 +330,7 @@ private String getCurrentStackTrace() {
 
     @Override
     public void setContentType(final String type) {
-        if (super.getResponse().isCommitted() || !isInclude()) {
+        if (super.isCommitted() || !isInclude()) {

Review Comment:
   this was introduced to avoid false positives because when the response is commited, changes to the content type are ignored



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscribe@sling.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] SLING-12801 - Error handler does not reset the response during include [sling-org-apache-sling-engine]

Posted by "raducotescu (via GitHub)" <gi...@apache.org>.
raducotescu commented on code in PR #62:
URL: https://github.com/apache/sling-org-apache-sling-engine/pull/62#discussion_r2121330810


##########
src/test/java/org/apache/sling/engine/impl/SlingHttpServletResponseImplTest.java:
##########
@@ -107,24 +107,33 @@ public void testNoViolationChecksOnCommitedResponse() {
 
     @Test
     public void testReset() {
-        final SlingHttpServletResponse orig = mock(SlingHttpServletResponse.class);
+        final SlingHttpServletResponse originalResponse = mock(SlingHttpServletResponse.class);
         final RequestData requestData = mock(RequestData.class);
-        final DispatchingInfo info = new DispatchingInfo(DispatcherType.INCLUDE);
-        when(requestData.getDispatchingInfo()).thenReturn(info);
-        info.setProtectHeadersOnInclude(true);
-
-        final HttpServletResponse include = new SlingHttpServletResponseImpl(requestData, orig);
-
-        when(orig.isCommitted()).thenReturn(false);
-        include.reset();
-        verify(orig, times(1)).isCommitted();
-        Mockito.verifyNoMoreInteractions(orig);
-
-        when(orig.isCommitted()).thenReturn(true);
-        include.reset();
-        verify(orig, times(2)).isCommitted();
-        verify(orig, times(1)).reset();
-        Mockito.verifyNoMoreInteractions(orig);
+        DispatchingInfo dispatchingInfo = new DispatchingInfo(DispatcherType.INCLUDE);
+        when(requestData.getDispatchingInfo()).thenReturn(dispatchingInfo);
+        dispatchingInfo.setProtectHeadersOnInclude(true);
+
+        final HttpServletResponse includeResponse = new SlingHttpServletResponseImpl(requestData, originalResponse);
+
+        when(originalResponse.isCommitted()).thenReturn(false);
+        includeResponse.reset();
+        verify(originalResponse, times(1)).isCommitted();
+        Mockito.verifyNoMoreInteractions(originalResponse);
+
+        when(originalResponse.isCommitted()).thenReturn(true);
+        includeResponse.reset();
+        verify(originalResponse, times(2)).isCommitted();
+        verify(originalResponse, times(1)).reset();
+        Mockito.verifyNoMoreInteractions(originalResponse);
+
+        // check if reset is called on error handling
+        dispatchingInfo = new DispatchingInfo(DispatcherType.ERROR);
+        when(requestData.getDispatchingInfo()).thenReturn(dispatchingInfo);
+        dispatchingInfo.setProtectHeadersOnInclude(true);
+        when(originalResponse.isCommitted()).thenReturn(false);
+        includeResponse.reset();
+        verify(originalResponse, times(2)).reset();
+        Mockito.verifyNoMoreInteractions(originalResponse);

Review Comment:
   I would follow through with this comment and create different mocks for each test.



##########
src/test/java/org/apache/sling/engine/impl/filter/ErrorFilterChainTest.java:
##########
@@ -80,4 +85,29 @@ public void testResponseNotCommitted() throws IOException, ServletException {
         chain2.doFilter(request, response);
         Mockito.verify(errorHandler, times(1)).handleError(anyInt(), anyString(), eq(request), eq(response));
     }
+
+    @Test
+    public void testResponseDispatcherInfoOnError() throws IOException, ServletException {
+        // mocks a final method in SlingHttpServletResponseImpl, needs mockito-inline
+        final DefaultErrorHandler handler = new DefaultErrorHandler();
+        final ErrorHandler errorHandler = Mockito.mock(ErrorHandler.class);
+        handler.setDelegate(errorHandler);
+
+        final SlingHttpServletRequest request = Mockito.mock(SlingHttpServletRequest.class);
+        final SlingHttpServletResponseImpl response = Mockito.mock(SlingHttpServletResponseImpl.class);
+        RequestData requestData = Mockito.mock(RequestData.class);
+        when(response.getRequestData()).thenReturn(requestData);
+
+        final ErrorFilterChain chain2 = new ErrorFilterChain(new FilterHandle[0], handler, 404, "not found");
+        chain2.doFilter(request, response);
+        verify(response, times(1)).reset();
+
+        // called ones with thew error dispatcher info

Review Comment:
   I don't understand this comment.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscribe@sling.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] SLING-12801 - Error handler does not reset the response during include [sling-org-apache-sling-engine]

Posted by "raducotescu (via GitHub)" <gi...@apache.org>.
raducotescu commented on code in PR #62:
URL: https://github.com/apache/sling-org-apache-sling-engine/pull/62#discussion_r2108623024


##########
src/main/java/org/apache/sling/engine/impl/filter/ErrorFilterChain.java:
##########
@@ -118,6 +121,10 @@ public void doFilter(final ServletRequest request, final ServletResponse respons
                 return;
             }
             // reset the response to clear headers and body
+            if (response instanceof SlingHttpServletResponseImpl) {
+                final DispatchingInfo dispatchInfo = new DispatchingInfo(DispatcherType.ERROR);
+                ((SlingHttpServletResponseImpl) response).getRequestData().setDispatchingInfo(dispatchInfo);
+            }

Review Comment:
   Yes, we never needed to until now and hopefully we won't need to do it in other places either. That being said, I think we need to reuse that object rather than creating a new one and losing all that information – we might find other uses for it inside this bundle.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscribe@sling.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] SLING-12801 call reset for errors also when dispatcher contract viola… [sling-org-apache-sling-engine]

Posted by "sonarqubecloud[bot] (via GitHub)" <gi...@apache.org>.
sonarqubecloud[bot] commented on PR #62:
URL: https://github.com/apache/sling-org-apache-sling-engine/pull/62#issuecomment-2911486674

   ## [![Quality Gate Passed](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/checks/QualityGateBadge/qg-passed-20px.png 'Quality Gate Passed')](https://sonarcloud.io/dashboard?id=apache_sling-org-apache-sling-engine&pullRequest=62) **Quality Gate passed**  
   Issues  
   ![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/passed-16px.png '') [1 New issue](https://sonarcloud.io/project/issues?id=apache_sling-org-apache-sling-engine&pullRequest=62&issueStatuses=OPEN,CONFIRMED&sinceLeakPeriod=true)  
   ![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/accepted-16px.png '') [0 Accepted issues](https://sonarcloud.io/project/issues?id=apache_sling-org-apache-sling-engine&pullRequest=62&issueStatuses=ACCEPTED)
   
   Measures  
   ![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/passed-16px.png '') [0 Security Hotspots](https://sonarcloud.io/project/security_hotspots?id=apache_sling-org-apache-sling-engine&pullRequest=62&issueStatuses=OPEN,CONFIRMED&sinceLeakPeriod=true)  
   ![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/passed-16px.png '') [92.0% Coverage on New Code](https://sonarcloud.io/component_measures?id=apache_sling-org-apache-sling-engine&pullRequest=62&metric=new_coverage&view=list)  
   ![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/passed-16px.png '') [0.0% Duplication on New Code](https://sonarcloud.io/component_measures?id=apache_sling-org-apache-sling-engine&pullRequest=62&metric=new_duplicated_lines_density&view=list)  
     
   [See analysis details on SonarQube Cloud](https://sonarcloud.io/dashboard?id=apache_sling-org-apache-sling-engine&pullRequest=62)
   
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscribe@sling.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] SLING-12801 - Error handler does not reset the response during include [sling-org-apache-sling-engine]

Posted by "cziegeler (via GitHub)" <gi...@apache.org>.
cziegeler commented on code in PR #62:
URL: https://github.com/apache/sling-org-apache-sling-engine/pull/62#discussion_r2108517645


##########
src/main/java/org/apache/sling/engine/impl/SlingHttpServletResponseImpl.java:
##########
@@ -220,12 +225,12 @@ public void setStatus(final int sc, final String msg) {
 
     @Override
     public void reset() {
-        if (!this.isProtectHeadersOnInclude()) {
+        if (!this.isProtectHeadersOnInclude() || isError()) {
             super.reset();
         } else {
             // ignore if not committed
-            if (getResponse().isCommitted()) {
-                getResponse().reset();
+            if (super.isCommitted()) {

Review Comment:
   This should use "this.isCommitted()"



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscribe@sling.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] SLING-12801 - Error handler does not reset the response during include [sling-org-apache-sling-engine]

Posted by "RemoLiechti (via GitHub)" <gi...@apache.org>.
RemoLiechti commented on code in PR #62:
URL: https://github.com/apache/sling-org-apache-sling-engine/pull/62#discussion_r2115470080


##########
src/main/java/org/apache/sling/engine/impl/SlingHttpServletResponseImpl.java:
##########
@@ -220,12 +225,12 @@ public void setStatus(final int sc, final String msg) {
 
     @Override
     public void reset() {
-        if (!this.isProtectHeadersOnInclude()) {
+        if (!this.isProtectHeadersOnInclude() || isError()) {
             super.reset();
         } else {
             // ignore if not committed
-            if (getResponse().isCommitted()) {
-                getResponse().reset();
+            if (super.isCommitted()) {
+                super.reset();

Review Comment:
   reviews this with @cziegeler , check the new comment



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscribe@sling.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] SLING-12801 - Error handler does not reset the response during include [sling-org-apache-sling-engine]

Posted by "RemoLiechti (via GitHub)" <gi...@apache.org>.
RemoLiechti commented on code in PR #62:
URL: https://github.com/apache/sling-org-apache-sling-engine/pull/62#discussion_r2108583045


##########
src/main/java/org/apache/sling/engine/impl/filter/ErrorFilterChain.java:
##########
@@ -118,6 +121,10 @@ public void doFilter(final ServletRequest request, final ServletResponse respons
                 return;
             }
             // reset the response to clear headers and body
+            if (response instanceof SlingHttpServletResponseImpl) {
+                final DispatchingInfo dispatchInfo = new DispatchingInfo(DispatcherType.ERROR);
+                ((SlingHttpServletResponseImpl) response).getRequestData().setDispatchingInfo(dispatchInfo);
+            }

Review Comment:
   because so far, we do not change the dispatch info but create a new one in the two other places. There might be no dispatcher info that comes with the response might be null at that time as well?



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscribe@sling.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] SLING-12801 - Error handler does not reset the response during include [sling-org-apache-sling-engine]

Posted by "sonarqubecloud[bot] (via GitHub)" <gi...@apache.org>.
sonarqubecloud[bot] commented on PR #62:
URL: https://github.com/apache/sling-org-apache-sling-engine/pull/62#issuecomment-2933614110

   ## [![Quality Gate Passed](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/checks/QualityGateBadge/qg-passed-20px.png 'Quality Gate Passed')](https://sonarcloud.io/dashboard?id=apache_sling-org-apache-sling-engine&pullRequest=62) **Quality Gate passed**  
   Issues  
   ![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/passed-16px.png '') [1 New issue](https://sonarcloud.io/project/issues?id=apache_sling-org-apache-sling-engine&pullRequest=62&issueStatuses=OPEN,CONFIRMED&sinceLeakPeriod=true)  
   ![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/accepted-16px.png '') [0 Accepted issues](https://sonarcloud.io/project/issues?id=apache_sling-org-apache-sling-engine&pullRequest=62&issueStatuses=ACCEPTED)
   
   Measures  
   ![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/passed-16px.png '') [0 Security Hotspots](https://sonarcloud.io/project/security_hotspots?id=apache_sling-org-apache-sling-engine&pullRequest=62&issueStatuses=OPEN,CONFIRMED&sinceLeakPeriod=true)  
   ![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/passed-16px.png '') [90.9% Coverage on New Code](https://sonarcloud.io/component_measures?id=apache_sling-org-apache-sling-engine&pullRequest=62&metric=new_coverage&view=list)  
   ![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/passed-16px.png '') [0.0% Duplication on New Code](https://sonarcloud.io/component_measures?id=apache_sling-org-apache-sling-engine&pullRequest=62&metric=new_duplicated_lines_density&view=list)  
     
   [See analysis details on SonarQube Cloud](https://sonarcloud.io/dashboard?id=apache_sling-org-apache-sling-engine&pullRequest=62)
   
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscribe@sling.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] SLING-12801 - Error handler does not reset the response during include [sling-org-apache-sling-engine]

Posted by "Copilot (via GitHub)" <gi...@apache.org>.
Copilot commented on code in PR #62:
URL: https://github.com/apache/sling-org-apache-sling-engine/pull/62#discussion_r2115526543


##########
src/test/java/org/apache/sling/engine/impl/SlingHttpServletResponseImplTest.java:
##########
@@ -107,24 +107,33 @@ public void testNoViolationChecksOnCommitedResponse() {
 
     @Test
     public void testReset() {
-        final SlingHttpServletResponse orig = mock(SlingHttpServletResponse.class);
+        final SlingHttpServletResponse originalResponse = mock(SlingHttpServletResponse.class);
         final RequestData requestData = mock(RequestData.class);
-        final DispatchingInfo info = new DispatchingInfo(DispatcherType.INCLUDE);
-        when(requestData.getDispatchingInfo()).thenReturn(info);
-        info.setProtectHeadersOnInclude(true);
-
-        final HttpServletResponse include = new SlingHttpServletResponseImpl(requestData, orig);
-
-        when(orig.isCommitted()).thenReturn(false);
-        include.reset();
-        verify(orig, times(1)).isCommitted();
-        Mockito.verifyNoMoreInteractions(orig);
-
-        when(orig.isCommitted()).thenReturn(true);
-        include.reset();
-        verify(orig, times(2)).isCommitted();
-        verify(orig, times(1)).reset();
-        Mockito.verifyNoMoreInteractions(orig);
+        DispatchingInfo dispatchingInfo = new DispatchingInfo(DispatcherType.INCLUDE);
+        when(requestData.getDispatchingInfo()).thenReturn(dispatchingInfo);
+        dispatchingInfo.setProtectHeadersOnInclude(true);
+
+        final HttpServletResponse includeResponse = new SlingHttpServletResponseImpl(requestData, originalResponse);
+
+        when(originalResponse.isCommitted()).thenReturn(false);
+        includeResponse.reset();
+        verify(originalResponse, times(1)).isCommitted();
+        Mockito.verifyNoMoreInteractions(originalResponse);
+
+        when(originalResponse.isCommitted()).thenReturn(true);
+        includeResponse.reset();
+        verify(originalResponse, times(2)).isCommitted();
+        verify(originalResponse, times(1)).reset();
+        Mockito.verifyNoMoreInteractions(originalResponse);
+
+        // check if reset is called on error handling
+        dispatchingInfo = new DispatchingInfo(DispatcherType.ERROR);
+        when(requestData.getDispatchingInfo()).thenReturn(dispatchingInfo);
+        dispatchingInfo.setProtectHeadersOnInclude(true);
+        when(originalResponse.isCommitted()).thenReturn(false);
+        includeResponse.reset();
+        verify(originalResponse, times(2)).reset();
+        Mockito.verifyNoMoreInteractions(originalResponse);

Review Comment:
   Multiple test scenarios in testReset rely on cumulative interactions on the same mock; consider resetting the mock between scenarios or isolating tests to avoid potential verification conflicts.



##########
src/main/java/org/apache/sling/engine/impl/SlingHttpServletResponseImpl.java:
##########
@@ -90,7 +90,7 @@ public SlingHttpServletResponseImpl(RequestData requestData, HttpServletResponse
         }
     }
 
-    protected final RequestData getRequestData() {
+    public final RequestData getRequestData() {

Review Comment:
   Changing the access modifier of getRequestData() from protected to public may expose internal implementation details and affect the API contract; please ensure this change is intentional and well documented.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscribe@sling.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] SLING-12801 - Error handler does not reset the response during include [sling-org-apache-sling-engine]

Posted by "RemoLiechti (via GitHub)" <gi...@apache.org>.
RemoLiechti commented on code in PR #62:
URL: https://github.com/apache/sling-org-apache-sling-engine/pull/62#discussion_r2108578879


##########
src/main/java/org/apache/sling/engine/impl/SlingHttpServletResponseImpl.java:
##########
@@ -220,12 +225,12 @@ public void setStatus(final int sc, final String msg) {
 
     @Override
     public void reset() {
-        if (!this.isProtectHeadersOnInclude()) {
+        if (!this.isProtectHeadersOnInclude() || isError()) {
             super.reset();
         } else {
             // ignore if not committed
-            if (getResponse().isCommitted()) {
-                getResponse().reset();
+            if (super.isCommitted()) {

Review Comment:
   true, we could also use that, currently points to the same anyway, but would be cleaner?



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscribe@sling.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] SLING-12801 - Error handler does not reset the response during include [sling-org-apache-sling-engine]

Posted by "raducotescu (via GitHub)" <gi...@apache.org>.
raducotescu commented on PR #62:
URL: https://github.com/apache/sling-org-apache-sling-engine/pull/62#issuecomment-2911717737

   @RemoLiechti, will you also open a similar PR for the `master` branch?


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscribe@sling.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] SLING-12801 - Error handler does not reset the response during include [sling-org-apache-sling-engine]

Posted by "sonarqubecloud[bot] (via GitHub)" <gi...@apache.org>.
sonarqubecloud[bot] commented on PR #62:
URL: https://github.com/apache/sling-org-apache-sling-engine/pull/62#issuecomment-2933460195

   ## [![Quality Gate Passed](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/checks/QualityGateBadge/qg-passed-20px.png 'Quality Gate Passed')](https://sonarcloud.io/dashboard?id=apache_sling-org-apache-sling-engine&pullRequest=62) **Quality Gate passed**  
   Issues  
   ![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/passed-16px.png '') [2 New issues](https://sonarcloud.io/project/issues?id=apache_sling-org-apache-sling-engine&pullRequest=62&issueStatuses=OPEN,CONFIRMED&sinceLeakPeriod=true)  
   ![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/accepted-16px.png '') [0 Accepted issues](https://sonarcloud.io/project/issues?id=apache_sling-org-apache-sling-engine&pullRequest=62&issueStatuses=ACCEPTED)
   
   Measures  
   ![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/passed-16px.png '') [0 Security Hotspots](https://sonarcloud.io/project/security_hotspots?id=apache_sling-org-apache-sling-engine&pullRequest=62&issueStatuses=OPEN,CONFIRMED&sinceLeakPeriod=true)  
   ![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/passed-16px.png '') [93.5% Coverage on New Code](https://sonarcloud.io/component_measures?id=apache_sling-org-apache-sling-engine&pullRequest=62&metric=new_coverage&view=list)  
   ![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/passed-16px.png '') [0.0% Duplication on New Code](https://sonarcloud.io/component_measures?id=apache_sling-org-apache-sling-engine&pullRequest=62&metric=new_duplicated_lines_density&view=list)  
     
   [See analysis details on SonarQube Cloud](https://sonarcloud.io/dashboard?id=apache_sling-org-apache-sling-engine&pullRequest=62)
   
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscribe@sling.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] SLING-12801 - Error handler does not reset the response during include [sling-org-apache-sling-engine]

Posted by "cziegeler (via GitHub)" <gi...@apache.org>.
cziegeler merged PR #62:
URL: https://github.com/apache/sling-org-apache-sling-engine/pull/62


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscribe@sling.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org