fix(excel): 로드한 워크북을 finally에서 닫은 뒤 반환해 쓰기가 실패하는 문제 수정#264
Open
z3rotig4r wants to merge 1 commit into
Open
Conversation
loadWorkbook/loadExcelTemplate 계열 메서드가 finally 블록에서 Workbook을 (HSSF의 경우 POIFSFileSystem까지) 닫은 뒤 반환하여, '로드 -> 수정 -> 저장' 워크플로우에서 wb.write() 호출 시 예외가 발생했다. - XSSF: 'document seems to have been closed already' - HSSF: 'directory cannot be null' 반환할 Workbook은 호출자가 수명을 관리하도록 닫지 않고, 메서드가 연 파일 스트림만 닫도록 정리했다. HSSF는 POIFSFileSystem을 닫으면 write가 깨지므로 닫지 않는다(스트림은 생성자에서 전량 읽으므로 닫아도 안전). loadWorkbook(InputStream, XSSFWorkbook)에 이미 적용된 패턴과 동일하다. 로드 후 write 가능 여부를 검증하는 EgovExcelLoadThenWriteTest 추가.
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.
변경 이유
EgovExcelServiceImpl의 로딩 메서드 5개(loadWorkbook3개,loadExcelTemplate2개)가finally블록에서wb.close()를, InputStream을 받는 경우POIFSFileSystem의fs.close()까지 실행한 뒤return wb로 워크북을 돌려준다. 그래서 호출자가 받은 워크북은 이미 닫힌 상태다. "로드 → 수정 → 저장" 흐름에서wb.write()를 부르면 XSSF는 OPCPackage가 닫혀 IOException(document seems to have been closed already), HSSF는 directory가 무효라 NPE(directory cannot be null)가 난다. 기존 테스트는 읽기만 해서 이 결함을 잡지 못했다(쓰기 검증 공백).변경 내용
finally에서wb.close()와fs.close()호출을 제거했다. 파일 핸들fileIn.close()는 그대로 둔다. 스트림은 생성자에서 전량 메모리로 읽으므로 닫아도 워크북 동작에 영향이 없다.loadWorkbook(InputStream, XSSFWorkbook)에는 이미 같은 패턴이 적용돼 있고, 이번 변경은 그 구현과 동일한 방식이다.EgovExcelLoadThenWriteTest를 새로 추가했다. XSSF/HSSF × load/template 조합 4건으로, 로드한 워크북을 수정·저장한 결과 파일을 다시 읽어 검증한다.테스트 방법
mvn -pl Foundation/org.egovframe.rte.fdl.excel test모듈 테스트 34건이 통과한다. 신규
EgovExcelLoadThenWriteTest4건은 로드 후 write 산출물이 정상으로 열리는지 확인한다.영향 범위
fileIn은 계속 닫힌다).