Skip to content

HubInventoryAdapter.decreaseHubInventory()의 response.getData() NullPointerException 방어 처리 #15

Description

@coderabbitai

개요

PR #9 코드 리뷰 중 발견된 잠재적 NullPointerException 문제를 후속 처리합니다.

관련 링크

문제 설명

HubInventoryAdapter.javadecreaseHubInventory() 메서드에서 hubInventoryFeignClient.decreaseHubInventory() 호출 후 response.getData().items().stream()을 바로 호출하고 있습니다.

  • response.getData()null일 경우 NPE 발생 가능
  • response.getData().items()null일 경우 NPE 발생 가능

수정 방향

response.getData()response.getData().items()에 대한 null 체크를 추가하거나, Optional을 활용하여 방어 처리 후 의미 있는 예외를 던지도록 개선합니다.

CommonResponse<HubInventoryResponseDto.Decrease> response = hubInventoryFeignClient.decreaseHubInventory(hubInventoryDto);

if (response.getData() == null || response.getData().items() == null) {
    throw new IllegalStateException("Hub inventory decrease response is invalid");
}

return response.getData().items().stream()
    .collect(Collectors.toMap(
        HubInventoryResponseDto.Decrease.InventoryResult::productId,
        HubInventoryResponseDto.Decrease.InventoryResult::hubInventoryId
    ));

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions