금일 발생한 문제는 StackOverflowError 이다
StackOverflowError 는 재귀 함수를 많이 호출한 나머지 스텍 메모리가 초과해서 발생하는 애러라고 볼 수 있다
우선 나는 처음에 해당 문제에 대한 인지를 못하고 있고 내가 맵핑하지 않은 애러 메세지만 떴기 때문에 JWT 인증 문제인 줄 알았다
그러나 로그를 확인해보니까
at com.yoong.myissue.domain.team.dto.TeamResponse$Companion.from(TeamResponse.kt:16) ~[main/:na]
at com.yoong.myissue.domain.issue.entity.Issue.toIssueResponse(Issue.kt:79) ~[main/:na]
// X100
이런 애러가 많이 뜨고 StackOverflowError 가 발생한 것이다
다행이도 로그 상에서 코드의 위치를 잘 알려줘서 확인해보니
fun toIssueResponse(): IssueResponse {
return IssueResponse(
id = id!!,
title = title,
description = description,
priority = priority,
workingStatus = workingStatus,
member = MemberResponse.from(this.member),
team = TeamResponse.from(this.team), // 이부분에서 Team 객체를 불러온다
createdAt = createdAt,
)
}
companion object{
fun from(team: Team): TeamResponse {
return TeamResponse(
id = team.id!!,
name = team.name,
issue = team.issues.map { it.toIssueResponse() }, // 이부분에서 Issue 객체를 List로 불러온다
member = team.members.map { MemberResponse.from(it) }
)
}
}
위에 부분에서 팀과 이슈를 번갈아서 부르는 문제가 발생한 것이다 ( 왜 코드를 저렇게 짰지?? )
따라서 해당 부분을 설계를 변경해서 이슈 부분에서 각 이름만 부르는 것으로 수정을 진행했다
fun toIssueResponse(): IssueResponse {
return IssueResponse(
id = id!!,
title = title,
description = description,
priority = priority,
workingStatus = workingStatus,
nickname = member.nickname,
teamName = team.name,
createdAt = createdAt,
)
}
사실 알고리즘 문제 풀면 가끔 보이긴 하는데 이런 프로젝트에서도 볼 수 있는 애러였다니 조금 조심해서 설계를 해야 할 것 같다
'Kotlin > Spring' 카테고리의 다른 글
(Spring) No property {} found for type {} 해결 법 (0) | 2024.06.26 |
---|---|
(Spring) 관점 지향 코딩의 핵심!! AOP 의 설정 법을 알아보자 (0) | 2024.06.24 |
[Spring / QueryDSL] UnsatisfiedDependencyException, Error creating bean with name 해결 (1) | 2024.06.17 |
(Spring) 인증 개발을 하면서 겪은 다양한 버그들 (0) | 2024.06.05 |
(Spring) Type mismatch: inferred type is Duration but TemporalAmount! was expected 애러 해결 (0) | 2024.06.05 |