admin管理员组文章数量:1415652
I have very crucial encrytion decrytion file and getting this Sonar warning
Make the enclosing method "static" or remove this set
Now, because variables are static, the method in which their values are setting should be static, but we are also autowiring them, and static methods cannot be autowired
And if I make the variable non-static, then I get this error
An unexpected error occurred: Error occurred while patient update. Cannot invoke "com.docasap.patientmanagementservice.helpers.EncryptDecryptHelper.buildEncryptDecryptServiceImpl()" because "this.encryptDecryptHelper" is null
@Slf4j
@Component
public class StudentEventListener {
private static OptStudentRepo optStudentRepo;
private static IntStudentRepo intStudentRepo;
private static EncryptDecryptHelper encryptDecryptHelper;
@Autowired
public void setEncryptDecryptHelper(EncryptDecryptHelper encryptDecryptHelp) {
encryptDecryptHelper = encryptDecryptHelp;
}
@Autowired
public void setOasPatientRepo(IntStudentRepo intStudentRepo1) {
intStudentRepo = intStudentRepo1;
}
@Autowired
public void setOrgPatientRepo(OptStudentRepo optStudentRepo1) {
optStudentRepo = optStudentRepo1;
}
protected EncryptDecryptService determineEncryptionKey(StudentRecord sr) {
HashMap<String, Integer> encIds = sr.getEncryptionIds(intStudentRepo, optStudentRepo);
EncryptDecryptService encryptDecryptService = encryptDecryptHelper.buildEncryptDecryptServiceImpl();
try {
encryptDecryptService.setValue(encIds.get("schoolId").toString(), encIds.get("classId"), SupportedEncryption.AES256);
return encryptDecryptService;
} catch (InvalidPropertiesFormatException | RuntimeException e) {
try {
encryptDecryptService.setValue("0", 0, SupportedEncryption.AES256);
return encryptDecryptService;
} catch (InvalidPropertiesFormatException ex) {
throw new RuntimeException(ex);
}
}
}
}
This class is being extended in several other classes where we are making records encrypted or decrypted
@Slf4j
@Component
public class OptStudentEventListener extends StudentEventListener {
@PrePersist
public void encryptRecord(OptStudent os) throws Throwable {
if (os.getIsEncrypted()) {
return;
}
EncryptDecryptService encryptDecryptService = determineEncryptionKey(os);
os.setFirstName(encryptDecryptService.encryptString(pc.getFirstName()));
os.setLastName(encryptDecryptService.encryptString(pc.getLastName()));
os.setMiddleName(encryptDecryptService.encryptString(pc.getMiddleName()));
os.setIsEncrypted(true);
}
}
How can I make this work without Sonar warnings?
本文标签:
版权声明:本文标题:java - Sonar issue, encryption logic, Make the enclosing method "static" or remove this set - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744716736a2621447.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论