260630_16_이혁#99
Conversation
|
이번 PR에서는 인스턴스 기본 조작을 주제로 주요 변경
확인 사항
Walkthrough
ChangesBook 클래스 구현 및 테스트
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes 🚥 Pre-merge checks | ✅ 3 | ❌ 2❌ Failed checks (1 warning, 1 inconclusive)
✅ Passed checks (3 passed)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 2
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@2026-06-30/src/main/java/com/survivalcoding/Book.java`:
- Around line 49-52: `Book.compareTo()` currently orders only by `publishDate`,
which can make different books compare as equal and also throws on null dates.
Update `compareTo(Book other)` in `Book` to use a null-safe, multi-field
comparison that includes `title` as a tiebreaker and aligns better with
`equals()`. Keep the comparison logic centralized in `Book` so
`TreeSet`/`TreeMap` won’t collapse distinct books with the same publish date.
- Around line 7-8: `Book`의 `title`과 `publishDate`가
`equals()`/`hashCode()`/`compareTo()` 기준인데 외부에서 변경될 수 있으니 불변으로 고정하세요. `Book`
클래스의 필드를 `final`로 만들고, `publishDate`는 생성 시 방어적 복사를 적용하며 getter에서도 내부 `Date` 원본을
직접 반환하지 않도록 수정하세요. 필요하면 `Book` 생성자와 `getPublishDate()`를 함께 조정해 컬렉션에 들어간 뒤 상태가
바뀌지 않게 하세요.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: ff623dd7-73e5-4081-9cee-8637021f43e9
📒 Files selected for processing (3)
2026-06-30/src/main/java/com/survivalcoding/Book.java2026-06-30/src/test/java/com/survivalcoding/BookTest.javaTIL/sample/2026-06-30-인스턴스 기본 조작.md
| private String title; | ||
| private Date publishDate; |
There was a problem hiding this comment.
🗄️ Data Integrity & Integration | 🟠 Major | ⚡ Quick win
🧩 Analysis chain
🏁 Script executed:
#!/bin/bash
set -euo pipefail
git ls-files '2026-06-30/src/main/java/com/survivalcoding/Book.java' \
'2026-06-30/src/test' \
'2026-06-30/src/main/java/com/survivalcoding' | sed -n '1,200p'
echo '--- Book.java outline ---'
ast-grep outline 2026-06-30/src/main/java/com/survivalcoding/Book.java --view expanded || true
echo '--- Book.java excerpt ---'
wc -l 2026-06-30/src/main/java/com/survivalcoding/Book.java
sed -n '1,220p' 2026-06-30/src/main/java/com/survivalcoding/Book.java
echo '--- usages of Book in tests/source ---'
rg -n --hidden --glob '!**/target/**' --glob '!**/build/**' '\bBook\b' 2026-06-30/src/main/java 2026-06-30/src/test || true
echo '--- Set/Map usage around Book ---'
rg -n --hidden --glob '!**/target/**' --glob '!**/build/**' 'new (HashSet|HashMap|TreeSet|TreeMap)<|Set<|Map<' 2026-06-30/src/main/java 2026-06-30/src/test || trueRepository: SurvivalCodingCampus/polytech_java2
Length of output: 5266
🏁 Script executed:
#!/bin/bash
set -euo pipefail
echo '--- BookTest outline ---'
ast-grep outline 2026-06-30/src/test/java/com/survivalcoding/BookTest.java --view expanded || true
echo '--- BookTest excerpt ---'
wc -l 2026-06-30/src/test/java/com/survivalcoding/BookTest.java
sed -n '1,260p' 2026-06-30/src/test/java/com/survivalcoding/BookTest.javaRepository: SurvivalCodingCampus/polytech_java2
Length of output: 6130
title/publishDate는 불변으로 고정하세요. equals()/hashCode()/compareTo() 기준인데 둘 다 외부에서 바뀔 수 있고, 특히 publishDate는 getter가 Date 원본을 그대로 노출합니다. HashSet/HashMap/정렬된 컬렉션에 들어간 뒤 값이 바뀌면 조회와 정렬 기준이 깨집니다.
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In `@2026-06-30/src/main/java/com/survivalcoding/Book.java` around lines 7 - 8,
`Book`의 `title`과 `publishDate`가 `equals()`/`hashCode()`/`compareTo()` 기준인데 외부에서
변경될 수 있으니 불변으로 고정하세요. `Book` 클래스의 필드를 `final`로 만들고, `publishDate`는 생성 시 방어적 복사를
적용하며 getter에서도 내부 `Date` 원본을 직접 반환하지 않도록 수정하세요. 필요하면 `Book` 생성자와
`getPublishDate()`를 함께 조정해 컬렉션에 들어간 뒤 상태가 바뀌지 않게 하세요.
| @Override | ||
| public int compareTo(Book other) { | ||
| return other.publishDate.compareTo(this.publishDate); | ||
| } |
There was a problem hiding this comment.
🎯 Functional Correctness | 🟠 Major | ⚡ Quick win
🧩 Analysis chain
🏁 Script executed:
#!/bin/bash
set -euo pipefail
# Locate the file and map its structure first
git ls-files '2026-06-30/src/main/java/com/survivalcoding/Book.java'
ast-grep outline 2026-06-30/src/main/java/com/survivalcoding/Book.java --view expanded || true
# Show the file with line numbers
wc -l 2026-06-30/src/main/java/com/survivalcoding/Book.java
cat -n 2026-06-30/src/main/java/com/survivalcoding/Book.java
# Search for usages/related methods in the same package
rg -n "compareTo\\(|equals\\(|publishDate|title" 2026-06-30/src/main/java/com/survivalcoding -g '*.java'Repository: SurvivalCodingCampus/polytech_java2
Length of output: 4242
compareTo()는 equals()와 다른 기준을 쓰고 publishDate null도 처리하지 않습니다.
publishDate만 비교해서 같은 날짜의 서로 다른 책이 0이 될 수 있어 TreeSet/TreeMap에서 항목이 합쳐집니다. other.publishDate.compareTo(this.publishDate)는 양쪽 값이 null이면 바로 NPE도 발생합니다. title까지 포함한 null-safe 비교로 맞추세요.
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In `@2026-06-30/src/main/java/com/survivalcoding/Book.java` around lines 49 - 52,
`Book.compareTo()` currently orders only by `publishDate`, which can make
different books compare as equal and also throws on null dates. Update
`compareTo(Book other)` in `Book` to use a null-safe, multi-field comparison
that includes `title` as a tiebreaker and aligns better with `equals()`. Keep
the comparison logic centralized in `Book` so `TreeSet`/`TreeMap` won’t collapse
distinct books with the same publish date.
260630_16_이혁
📝 과제 정보
인스턴스 기본 조작 연습문제 및 TIL
인스턴스 기본 조작
📋 체크리스트
📷 실행 결과 (또는 테스트 결과)
❓질문 및 어려웠던 점
연습문제 코드를 만들려면 수업시간에 배운 내용을 바탕으로 새로운 것을 추가해야 하는데 추가를 해도 더 추가해야 하는 것들이 많아서 힘들었습니다.
또한 테스트 코드도 기존의 아는 수준에서는 완벽하게 코드를 만들 수 없어서 힘들었습니다.
🔄 자체 평가 & 회고
수업시간에 배운 내용을 바탕으로 추가해도 또 추가해야 할 내용들이 계속 나와서 어려운 것 같습니다.