Open
Description
Create inspections similar to AEM SonarQube rules by Cognifide
Good practices
- AEM-1 Inspections: AEM-1 & AEM-2 #148: Use predefined constant in annotation instead of hardcoded value.
- Use constants available in AEM instead of repeating inline literals
- AEM-2 Inspections: AEM-1 & AEM-2 #148: Use predefined constant instead of hardcoded value.
- Use constants available in AEM instead of repeating inline literals.
- AEM-8 Prefer cleaner
@SlingServlet
annotation.- Prefer cleaner
@SlingServlet
annotation over@Properties
approach. Do not mix up both approaches.
- Prefer cleaner
- AEM-14 Using http literal hardcoded makes it difficult to switch to https later on.
- We should not use http as a literal in our projects because if we want to switch to https, our code will be not ready.
- AEM-15 Usage of
synchronized
keyword should be avoided if possible.- Usage of
synchronized
keyword should be avoided if possible. Check if usingsynchronized
can be replaced with more sophisticated solution.
- Usage of
- AEM-17 No mutator methods invoked on
ModifiableValueMap
ModifiableValueMap
should be replaced byValueMap
if no mutator methods are invoked.
Possible bugs
- AEM-3 Inspections: AEM-3 #159 Non-thread safe object used as a field of Servlet/Filter etc.
- It if not safe to keep session based object as a field in
Servlet
orFilter
. Rule checks for the occurrence of any instance or static fields of following types:org.apache.sling.api.resource.ResourceResolver
javax.jcr.Session
com.day.cq.wcm.api.PageManager
com.day.cq.wcm.api.components.ComponentManager
com.day.cq.wcm.api.designer.Designer
com.day.cq.dam.api.AssetManager
com.day.cq.tagging.TagManager
com.day.cq.security.UserManager
org.apache.jackrabbit.api.security.user.Authorizable
org.apache.jackrabbit.api.security.user.User
org.apache.jackrabbit.api.security.user.UserManager
- It if not safe to keep session based object as a field in
- AEM-6 Inspections: AEM 6 implementation #162 ResourceResolver should be closed in finally block.
- According to its Javadoc, Resource Resolver has a life cycle which begins with the creation of the Resource Resolver using any of the factory methods and ends with calling the
close
method. It is very important to call theclose
method once the resource resolver is not used any more to ensure any system resources are properly clean up.
- According to its Javadoc, Resource Resolver has a life cycle which begins with the creation of the Resource Resolver using any of the factory methods and ends with calling the
- AEM-7 Session should be logged out in finally block.
- Manually created
javax.jcr.Session
should be logged out after it is no longer needed. Thelogout
method releases all resources associated withSession
.
- Manually created
- AEM-11 Do not use deprecated administrative access methods
- Administrative access to the resource tree and JCR Repository by means of usage of
ResourceResolverFactory.getAdministrativeResourceResolver
andSlingRepository.loginAdministrative
has been deprecated. UseResourceResolverFactory.getServiceResourceResolver
orSlingRepository.loginServicer
respectively.
- Administrative access to the resource tree and JCR Repository by means of usage of
Sling Models related
- AEM-16 Inspections: AEM-16 #157 Optional is defined as
DefaultInjectionStrategy
- Usage of
@Optional
annotation is redundant, whendefaultInjectionStrategy
isOPTIONAL
.
- Usage of
Description of inspection is taken from Cognifide/AEM-Rules-for-SonarQube
github page