infer는 Meta에서 개발한 정적 분석 tool이다.
https://fbinfer.com/
Install
https://github.com/facebook/infer/blob/main/INSTALL.md
# install dependencies
brew install autoconf automake cmake opam pkg-config sqlite gmp mpfr java
# Checkout Infer
git clone https://github.com/facebook/infer.git
cd infer
# Compile Infer
./build-infer.sh java
# install Infer system-wide...
sudo make install
Analyze
다음과 같이 command line을 입력하면 infer-out
디렉토리와 터미널 창에 빌드 후 각 source file들의 analyze report 결과가 나타난다.
infer -- gradle clean build
현재 진행 중이었던 프로젝트에 적용을 해보았을 때 infer-out/report.txt
에 다음과 같이 문제가 있는 부분을 잡아내주는 것을 확인해볼 수 있었다.
#0
src/main/java/joo/project/my3d/dto/ArticleWithCommentsDto.java:73: error: Null Dereference
`parentComment` could be null (null value originating from line 72) and is dereferenced.
71. map.values().stream().filter(ArticleCommentDto::hasParentComment).forEach(comment -> {
72. ArticleCommentDto parentComment = map.get(comment.parentCommentId());
73. > parentComment.childComments().add(comment);
74. });
75.
#1
src/main/java/joo/project/my3d/dto/security/OAuthAttributes.java:47: error: Null Dereference
`response` could be null (null value originating from line 44) and is dereferenced.
45.
46. return OAuthAttributes.of(
47. > (String) response.get("name"),
48. (String) response.get("email"),
49. "Naver",
#2
src/main/java/joo/project/my3d/dto/security/OAuthAttributes.java:57: error: Null Dereference
`response` could be null (null value originating from line 56) and is dereferenced.
55. private static OAuthAttributes ofKakao(String userNameAttributeName, Map<String, Object> attributes) {
56. Map<String, Object> response = (Map<String, Object>) attributes.get("kakao_account");
57. > Map<String, Object> account = (Map<String, Object>) response.get("profile");
58.
59. return OAuthAttributes.of(
#3
src/main/java/joo/project/my3d/dto/security/OAuthAttributes.java:60: error: Null Dereference
`account` could be null (null value originating from line 57) and is dereferenced.
58.
59. return OAuthAttributes.of(
60. > (String) account.get("nickname"),
61. (String) response.get("email"),
62. "Kakao",
#4
src/main/java/joo/project/my3d/security/TokenProvider.java:57: error: Null Dereference
`spec` could be null (null value originating from line 56) and is dereferenced.
55. Map<String, String> decoded = decodeExpiredToken(token);
56. String spec = decoded.get(KEY_SPEC);
57. > long userAccountId = Long.parseLong(spec.split(":")[0]);
58. // 조회하려는 refresh token은 재발행 횟수 제한보다 적게 재발행이 되어야한다.
59. UserRefreshToken refreshToken = userRefreshTokenRepository
#5
src/main/java/joo/project/my3d/security/TokenProvider.java:82: error: Null Dereference
null (null value originating from line 82) is dereferenced.
80. parseOrValidateClaims(refreshToken); // validation
81. long userAccountId =
82. > Long.parseLong(decodeExpiredToken(accessToken).get(KEY_SPEC).split(":")[0]);
83. // 조회하려는 refresh token은 현재 유저의 실제 refresh token과 일치해야한다.
84. userRefreshTokenRepository
Found 6 issues
Issue Type(ISSUED_TYPE_ID): #
Null Dereference(NULLPTR_DEREFERENCE): 6