Expand my Community achievements bar.

Guidelines for the Responsible Use of Generative AI in the Experience Cloud Community.
SOLVED

Empty Activate function with @Activate annotation

Avatar

Level 2

In a project I am working on there are multiple servlets, services with an activate function with @activate annotation where the function has no body, said activate function is taking a configuration as parameter. The configuration has a single field. I am attaching code snippet for one such case below for reference. 
What is the reason behind these empty activate functions, as they are not passing any value from configuration. furthermore what impact might removing such activate function can cause.
service.PNG
config.PNG

comp.png

1 Accepted Solution

Avatar

Correct answer by
Community Advisor

Hi @shubham_naik to me it looks like a dead code. In my opinion having empty activate method does not bring any benefit. I think that removing such an empty activate method will not affect component/service functionality. In other words it should be safe to remove those methods. There is a nice documentation page that explains OSGi component lifecycle including activate, modify, deactivate annotation/methods usage - maybe this could be useful for you.

https://experienceleague.adobe.com/docs/experience-manager-learn/cloud-service/developing/osgi-servi...

 

View solution in original post

4 Replies

Avatar

Correct answer by
Community Advisor

Hi @shubham_naik to me it looks like a dead code. In my opinion having empty activate method does not bring any benefit. I think that removing such an empty activate method will not affect component/service functionality. In other words it should be safe to remove those methods. There is a nice documentation page that explains OSGi component lifecycle including activate, modify, deactivate annotation/methods usage - maybe this could be useful for you.

https://experienceleague.adobe.com/docs/experience-manager-learn/cloud-service/developing/osgi-servi...

 

Avatar

Level 2

Thanks @lukasz-m , even I thought the same, but it always helps to get a confirmation before decommissioning any code, thanks a lot for the help.

Avatar

Employee Advisor

Yes I agree with @lukasz-m here, if you want to understand OCD with @activate ,modify and deactivate annotations , please refer this : https://aem4beginner.blogspot.com/ocd-issue-with-activate-annotation