try-finally로 자원을 정리하던 코드를 try-with-resource문으로 개선#241
Open
yjj8353 wants to merge 2 commits into
Open
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
수정 사유 Reason for modification
수정된 소스 내용 Modified source
개선해야 하는 이유
1. finally 절에서 리소스 정리 시 발생할 수 있는 휴먼 에러 원천 차단
자원을 여러 개 close 하는 도중 예외가 발생하면 후속 자원이 close 되지 않을 수 있음
2. 예외 묻힘 방지
finally 절에서 자원을 close 할 수 없는 경우 예외로 이를 처리하는데, 이 경우 예외 발생 시 이중으로 예외가 발생할 수 있음
3. 코드 간략화
finally 절을 제거함으로써 코드가 간략해짐
4. 오탐 방지
try-finally절은 정상적으로 자원정리를 하더라도 시큐어 코딩에서 매우 빈번하게 오탐 될 수 있음. (행안부의 소프트웨어 개발보안 가이드의 '부적절한 자원 해제 항목과 연관되어 있음)
수정 전
수정 후
JUnit 테스트 JUnit tests
테스트 브라우저 Test Browser
테스트 스크린샷 또는 캡처 영상 Test screenshots or captured video