Skip to content

Commit 52f2a93

Browse files
committed
fix: 데모 사진 조회 count 음수 방어 추가
1 parent e1b3eb4 commit 52f2a93

1 file changed

Lines changed: 6 additions & 1 deletion

File tree

src/main/java/com/semosan/api/domain/demo/service/DemoService.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ public class DemoService {
3434
public List<String> getDemoPhotos(Long sessionId, int count) {
3535
List<String> shuffled = new ArrayList<>(demoProperties.photoFilenames());
3636
Collections.shuffle(shuffled);
37-
List<String> randomUrls = shuffled.subList(0, Math.min(count, shuffled.size()))
37+
List<String> randomUrls = shuffled.subList(0, safeRandomPhotoCount(count, shuffled.size()))
3838
.stream()
3939
.map(this::presignedGetUrl)
4040
.toList();
@@ -50,6 +50,11 @@ public List<String> getDemoPhotos(Long sessionId, int count) {
5050
return combined;
5151
}
5252

53+
// 음수 count 요청이 들어와도 subList 범위를 벗어나지 않도록 보정합니다.
54+
private int safeRandomPhotoCount(int count, int availableCount) {
55+
return Math.max(0, Math.min(count, availableCount));
56+
}
57+
5358
private String presignedGetUrl(String objectKey) {
5459
try {
5560
String url = minioClient.getPresignedObjectUrl(

0 commit comments

Comments
 (0)