컬렉션 필드 초기화가 정상적으로 적용되지 않고 NullPointerException이 발생 #174
janeljs
started this conversation in
Troubleshooting docs
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
문제
.schedules(new ArrayList<>())부분이 없으면 NullPointerException이 발생합니다.private final List<Schedule> schedules = new ArrayList<>();에서 필드 초기화가 되었는데 왜 NPE가 발생하는 걸까요?해결
생성된 빌더 클래스를 확인하니 리스트를 통채로 교체하고 있었습니다.
구글링을 해보니 같은 문제를 겪고 있는 사람들이 있었는데요.
projectlombok/lombok#1347
@Builder.Default사용에 관련해서는 아직 문제가 해결되지 않은 것처럼 보였습니다.projectlombok/lombok#2340
projectlombok/lombok#1347 (comment) 의 커멘트를 참고하여
@Singular어노테이션을 붙이니 잘 작동합니다. 해당 어노테이션을 추가한 뒤 생성된 빌더를 확인해보면 아래와 같습니다.Schedule 하나를 add할 수 있는 schedule 메서드가 추가되었습니다.
Beta Was this translation helpful? Give feedback.
All reactions