SonarQube Error: TagManager as a field is not thread safe | Community
Skip to main content
Level 2
Jul 28, 2022 9:51 PM UTC
Solved

SonarQube Error: TagManager as a field is not thread safe

Currently stuck on code scanning part of Cloud Manager where my projects fails to build due to SonarQube errors

 

I'm currently trying to get around the following error:

Usage of com.day.cq.tagging.TagManager as a field is not thread safe.

 

It states that TagManager object should not be used in Servlets/Filters however I'm getting this error while being used in a component/service.

Official SonarQube DOC (AEM-3): https://github.com/wttech/AEM-Rules-for-SonarQube#rule-set 

 

Here is my implementations:

@8220494 public class SomeServiceImpl implements SomeService { ... private TagManager tagManager; ... public String someFunction () { try{ tagManager = resourceResolver.adaptTo(TagManager.class); ... do tagManager methods ... catch(RepositoryException e){ ... } }

 

I even tried declaring TagManager object locally within a function rather than as a class field and still get same SonarQube error.

What is the best practice on handling this object within a Component/Service?

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
arunpatidar
arunpatidarAccepted solution
New Participant
Jul 29, 2022 11:54 AM UTC

Hi,

Try autoclosable try for resourceResolver. The resource Resolver is also not closed here

Arun Patidar

2 replies

arunpatidar
arunpatidarAccepted solution
New Participant
Jul 29, 2022 11:54 AM UTC

Hi,

Try autoclosable try for resourceResolver. The resource Resolver is also not closed here

Translate
Arun Patidar
Shivam153
Level 3
Jul 29, 2022 9:14 AM UTC

Seems like this is a service in which you are using tag manager. Service is a Session based concept. You can create a different class and define the tag logic there and call it in your service implementation and check if its working.

Translate