728x90
[오류내용]
Define a constant instead of duplicating this literal "sndRqRspCd" 7 times.
String literals should not be duplicated.
[해결방안]
문자열이 중복되어 사용이 되는게 문제이며 해결방안으로는 멤버변수를 두고 재사용해야된다.
아래 샘플 소스코드는 해결방안으로만 참고하길 바란다.
package deploy;
public class Deploy3Controller {
private static final String RETURN_ERR_CODE = "returnErrCd"; // 멤버변수
private static final String RETURN_MESSAGE = "returnMessage"; // 멤버변수
@PostMapping ~~~~~~~~~
public @ResponseBody Object sendMsg(@RequestBody Map<String, Object> paramMap) {
Map<String, Object> retMap = new HashMap<>();
if(StringUtil.isEmpty(paramMap.get("telNo"))) {
retMap.put(RETURN_ERR_CODE, "-1");
retMap.put(RETURN_MESSAGE, "전화번호가 없습니다.");
} else if(StringUtil.isEmpty(paramMap.get("addr"))) {
retMap.put(RETURN_ERR_CODE, "-1");
retMap.put(RETURN_MESSAGE, "주소가 없습니다.");
} else {
retMap.put(RETURN_ERR_CODE, "0000");
retMap.put(RETURN_MESSAGE, "정상 처리되었습니다.");
}
return retMap;
}
}
소나큐브에서 개발 언어별 Rules 를 공유한게 있는거 같은데 아래 사이트를 참고하자.
https://rules.sonarsource.com/java/RSPEC-6437
Java static code analysis: Credentials should not be hard-coded
A hard-coded secret has been found in your code. You should quickly list where this secret is used, revoke it, and then change it in every system that uses it. Passwords, secrets, and any type of credentials should only be used to authenticate a single ent
rules.sonarsource.com
728x90
반응형
'IT 인터넷 > 소나큐브' 카테고리의 다른 글
[소나큐브] Format specifiers should be used instead of string concatenation. (0) | 2022.10.13 |
---|---|
[소나큐브] Collection.isEmpty() should be used to test for emptiness (0) | 2022.10.12 |
[소나큐브] Field names should comply with a naming convention (0) | 2022.10.12 |
[소나큐브] Cognitive Complexity of methods should not be too high (0) | 2022.10.12 |
[소나큐브] Composed "@RequestMapping" variants should be preferred (0) | 2022.10.12 |