fix: ContentHandlerImpl 의 요소 시작·종료 로그가 안내 문구를 잃는 문제 수정 - #370
Open
wantaekchoi wants to merge 1 commit into
Open
Conversation
startElement 와 endElement 는 LOGGER.debug(name, "{}이 시작되었습니다.") 처럼
포맷 문자열과 값을 뒤바꿔 넘긴다. slf4j 는 첫 인자를 포맷으로 보므로 요소명이
포맷이 되고, {} 가 없으니 나머지 인자인 안내 문구는 그대로 버려진다.
`<person/>` 을 파싱하면 "person이 시작되었습니다." 대신 "person" 만 남는다.
같은 클래스의 startDocument·endDocument 는 문구를 그대로 남기고, 같은 모듈의
다른 인자 있는 호출 다섯 곳은 모두 포맷 문자열이 첫 인자다. 이 두 곳만 어긋난다.
인자 순서를 형제 호출에 맞췄다. EgovSAXValidatorService 로 실제 파싱을 돌려
남은 메시지를 확인하는 테스트를 더했다.
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
ContentHandlerImpl의startElement(:132)·endElement(:71) 이 slf4j 에 포맷 문자열과 값을 뒤바꿔 넘깁니다.slf4j 는 첫 인자를 포맷으로 봅니다. 요소명에는
{}가 없어 채울 자리가 없고, 뒤에 온 안내 문구는 들어갈 곳이 없어 버려집니다. 남는 것은 요소명뿐입니다.<person/>을EgovSAXValidatorService.parse(false)로 파싱했을 때 로거에 실제로 나간 메시지입니다.문구 취향 문제가 아니라 호출자가 넘긴 인자 하나가 폐기되는 것이고, 문서 단위 이벤트와 요소 단위 이벤트가 같은 클래스 안에서 갈립니다. 같은 클래스의
startDocument(:121)·endDocument(:60) 는"XML이 시작되었습니다."/"XML이 종료되었습니다."를 그대로 남깁니다.모듈 전체로 넓혀도 어긋나는 것은 이 두 줄뿐입니다. 인자를 두 개 이상 넘기는
LOGGER.debug는 이 모듈src/main에 7곳이고(git grep -c 'LOGGER\.debug(.*,' -- Foundation/org.egovframe.rte.fdl.xml/src/main), 그중 5곳 —AbstractXMLUtility:334·:339,EgovDOMValidatorService:131,EgovSAXValidatorService:117,EgovDOMFactoryServiceImpl:72 — 은 포맷 문자열이 첫 인자입니다.죽은 코드는 아닙니다.
EgovSAXValidatorService.parse(boolean)이 :97-98 에서 이 핸들러를 SAX 파서에 걸어 두므로 파싱되는 요소마다 두 메서드가 불립니다.AS-IS / TO-BE
형제 호출에 인자 순서를 맞췄습니다.
public void endElement(String uri, String localName, String name) { - LOGGER.debug(name, "{}이 종료하였습니다."); + LOGGER.debug("{}이 종료하였습니다.", name); } public void startElement(String uri, String localName, String name, Attributes atts) { - LOGGER.debug(name, "{}이 시작되었습니다."); + LOGGER.debug("{}이 시작되었습니다.", name); }영향 범위
인자 순서 두 줄입니다. 문구·로그 레벨·조건 분기는 그대로이고, 두 메서드는 로깅 외에 하는 일이 없습니다.
JUnit 테스트 JUnit tests
ContentHandlerLogMessageTest를 더했습니다. 핸들러를 직접 부르지 않고EgovSAXValidatorService로 실제 파싱을 통과시킨 뒤,ContentHandlerImpl로거에 잠시 붙인 appender 가 모은 메시지를 목록으로 단언합니다. 도달 경로까지 함께 보이려고 이 형태를 택했습니다.인자 순서를 도로 되돌리면 실패합니다.
수정 후 모듈 전체입니다. 기존 3건은 그대로입니다.
테스트 브라우저 Test Browser
테스트 스크린샷 또는 캡처 영상 Test screenshots or captured video
화면이 없는 실행환경 모듈이라 첨부하지 않았습니다.