Expand my Community achievements bar.

SOLVED

SonarQube Issues - ThreadSafe and finally block

Avatar

Level 4

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-ma...

 

Thanks,
Kiran Parab

1 Accepted Solution

Avatar

Correct answer by
Community Advisor

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-r...

 

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

View solution in original post

1 Reply

Avatar

Correct answer by
Community Advisor

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-r...

 

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