Refactor : Adjust resolveFieldName Method Logic to Correctly Handle Primitive boolean Field Names #1096
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.
Summary
JavaGetterPropertyFieldNameResolver
의resolveFieldName
메소드가 필드 값을 추출하는 과정에서,원시 타입
boolean
필드값 추출 시 올바른 필드명이 추출되지 않아 메소드 순서를 변경했습니다.Description
Lombok
의@Getter
어노테이션을 사용할 때,boolean
타입을primitive type
으로 설정하고, 필드명의 prefix를“isXXX”
로 사용하는 경우 문제가 있습니다.위와 같은 엔티티에서 boolean isUsed; 라는 필드가 있다고 가정할 때,
Lombok 은 위처럼 필드명과 동일한
getter
를 생성합니다. (Sample::isUsed
)하지만
JavaGetterPropertyFieldNameResolver
의resolveFieldName
메소드에서,else if (hasPrefix(IS_PREFIX, methodName))
가true
일 경우stripPrefixPropertyName(targetClass, methodName, IS_PREFIX.length())
를 수행하기 때문에,isUsed
필드명이used
로 strip되어 resolve되기에 NPE 에러가 발생합니다.위처럼
isValidField(targetClass, methodName)
검증을 가장 먼저 수행하도록 변경하면, 필드명과 메소드명이 동일한 경우에도 대응이 가능해 변경했습니다.How Has This Been Tested?
Passed All Existing Tests