Non-serializable service references | Community
Skip to main content
New Participant
March 23, 2021
Solved

Non-serializable service references

  • March 23, 2021
  • 1 reply
  • 1248 views

Re-posting this question in the Adobe Experience Manager section

Hi, we recently started using the Cloud Manager pipelines to run analysis on our code and one of the critical code smells that keep popping up is the following:

 

IssueTypeSeverityEffortRuleTagsDocumentation
Make "cryptoSupport" transient or serializable.Code SmellCritical30minsquid:S1948cwe,serializationhttps://www.adobe.com/go/aem_cmcq_s1948_en

 

In this case "cryptoSupport" refers to an injected service that implements the com.adobe.granite.crypto.CryptoSupport interface.

 

@reference
private CryptoSupport cryptoSupport;

 

My question is: Since we can't make CryptoSupport serializable, is it safe to declare the field as transient? Is there any danger of our servlet (that contains the above service reference) being flushed to disk at some point and failing to restore the service reference later?

 

Thank you,

William.

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
Best answer by Asutosh_Jena_

Hi @williamvdev 

You should be able to make it as transient and it should not have any issue as they will not be part of persistent state.

@Reference
private transient CryptoSupport cryptoSupport;

Thanks! 

1 reply

Asutosh_Jena_
Asutosh_Jena_Accepted solution
New Participant
March 23, 2021

Hi @williamvdev 

You should be able to make it as transient and it should not have any issue as they will not be part of persistent state.

@Reference
private transient CryptoSupport cryptoSupport;

Thanks!