SonarQube Issues - ThreadSafe and finally block | Community
Skip to main content
June 29, 2021
Solved

SonarQube Issues - ThreadSafe and finally block

  • June 29, 2021
  • 1 reply
  • 5032 views

Hi Team,

 

Issue -

1. Usage of org.apache.sling.api.resource.ResourceResolver as a field is not thread safe.

2. Usage of javax.jcr.Session as a field is not thread safe.

3. ResourceResolver, Session should be closed in finally block.

 

Critical in SonarQube through CloudManager. What is the workaround for this scenario to handle in code. Below code quality documents not talks about the Thread safe scenario.

 

We are using serviceUser and we are taking serviceResourceResolver and there is no pointer how to resolve those scenario's.

 

If we close the resourceResolver and Session then it will not work as expected.

 

Reference -
https://experienceleague.adobe.com/docs/experience-manager-cloud-service/implementing/using-cloud-manager/test-results/code-quality-testing.html?lang=en#

 

Thanks,
Kiran Parab

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
Best answer by Shubham_borole

Are your service user based resolvers operated within a try-with-resources block? https://cqdump.joerghoh.de/2018/11/14/try-with-resource-or-i-will-never-forget-to-close-a-resource-resolver/

 

request resolvers and session resolvers need not be closed. Also curios if adding @SuppressWarnings annotation helps..

1 reply

Shubham_borole
Community Advisor
Shubham_boroleCommunity AdvisorAccepted solution
Community Advisor
July 18, 2021

Are your service user based resolvers operated within a try-with-resources block? https://cqdump.joerghoh.de/2018/11/14/try-with-resource-or-i-will-never-forget-to-close-a-resource-resolver/

 

request resolvers and session resolvers need not be closed. Also curios if adding @SuppressWarnings annotation helps..