Expand my Community achievements bar.

Dive into Adobe Summit 2024! Explore curated list of AEM sessions & labs, register, connect with experts, ask questions, engage, and share insights. Don't miss the excitement.
SOLVED

SonarQube Error: TagManager as a field is not thread safe

Avatar

Level 2

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:

@component
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?

1 Accepted Solution

Avatar

Correct answer by
Community Advisor

Hi,

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



Arun Patidar

View solution in original post

2 Replies

Avatar

Level 4

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.

Avatar

Correct answer by
Community Advisor

Hi,

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



Arun Patidar