Skip to content

26.06.30_20_이종재#97

Open
jongjae0305 wants to merge 1 commit into
SurvivalCodingCampus:student/20_이종재from
jongjae0305:main
Open

26.06.30_20_이종재#97
jongjae0305 wants to merge 1 commit into
SurvivalCodingCampus:student/20_이종재from
jongjae0305:main

Conversation

@jongjae0305

Copy link
Copy Markdown

260630_20_이종재

📝 과제 정보

  • 교육 주제: 인스턴스 기본조작

📋 체크리스트

  • 코드 컨벤션 준수 (Formatter 적용)
  • 모든 테스트 케이스 통과 (JUnit)

📷 실행 결과 (또는 테스트 결과)

image

❓질문 및 어려웠던 점

  • 처음에는 단순히 인터페이스에 메소드를 적어서 오버드라이브를 통해 정의하려나 생각하였는데 그게 아니였었어 뭔차이가 있는지 헷갈렸다.
  • if문과 try,catch문의 차이점.

🔄 자체 평가 & 회고

  • 인터페이스에 기존에 존재한 메소드를 바인딩하여 오버드라이브를 통한 내가 원하는 방식을 첨가한다는 것을 알게되었다.
  • if문은 사전방어, try-catch문은 사후수습, 둘다 비슷하지만 어떤 방식의 차이인지 다시 한번 확인.

@coderabbitai

coderabbitai Bot commented Jun 30, 2026

Copy link
Copy Markdown

Review Change Stack

이번 변경에서는 인스턴스 기본조작 학습 내용을 정리한 TIL 문서와 Book 관련 실습 코드/테스트가 추가되었습니다.

  • TIL/sample/2026-06-30.mdtoString(), equals/hashCode, Cloneable, iftry-catch의 차이 등을 정리한 학습 일지가 추가되었습니다.
  • Book 클래스가 추가되어 title, publishDate, comment를 다루며 Comparable<Book>, Cloneable을 구현합니다.
  • equalshashCode는 제목과 날짜 값을 기준으로 일관되게 동작하도록 작성되었고, compareTo는 출간일 기준 내림차순 정렬을 하도록 구현되었습니다.
  • clone()publishDate를 별도 객체로 복제해 깊은 복사를 수행하도록 처리되었습니다.
  • BookTest에는 동등성, 해시코드, 정렬, 깊은 복사, null 날짜 처리까지 검증하는 JUnit 테스트들이 추가되었습니다.
  • 추가로 제네릭 타입 선언 오타 수정이 포함되었습니다.

Walkthrough

day260630 패키지에 Coparable<T> 인터페이스와 Book 클래스(Comparable<Book>, Cloneable 구현)가 추가됨. BookpublishDate를 연/월/일 기반 정수로 변환하는 getDate() 헬퍼로 equals/hashCode/compareTo/clone을 구현. JUnit 5 테스트 7개가 추가되고, StrongBox<T> 공백과 TIL 학습 일지도 추가됨.

Changes

Book 클래스 구현 및 테스트

Layer / File(s) Summary
Book 클래스 및 Coparable 인터페이스
day01-basic/src/main/java/com/survivalcoding/day260630/Coparable.java, day01-basic/src/main/java/com/survivalcoding/day260630/Book.java
Coparable<T> 제네릭 인터페이스 선언. Booktitle/publishDate/comment 필드, 연-월-일 기반 날짜 정수 변환 헬퍼(getDate, null 시 0 반환), equals/hashCode(변환값 기준), compareTo(내림차순), clone(publishDate 깊은 복사, CloneNotSupportedException → RuntimeException 래핑)이 구현됨.
BookTest - 동등성/정렬/복사/null 처리 검증
day01-basic/src/test/java/com/survivalcoding/day260630/BookTest.java
날짜 동등성(시간 무시), null publishDate 비교 및 정렬 안전성, compareTo 내림차순 순서, clone 깊은 복사 독립성, null 상태 hashCode/compareTo/clone 각 동작을 JUnit 5로 검증하는 테스트 7개가 추가됨.
StrongBox 공백 수정
day01-basic/src/main/java/com/survivalcoding/day260629/StrongBox.java
StrongBox <T> 클래스 선언의 타입 파라미터 앞 불필요한 공백이 제거됨.
TIL 학습 일지
TIL/sample/2026-06-30.md
toString/equals/hashCode 해시 계약/Cloneable 개념 요약, if 사전 방어 vs try-catch 사후 수습 비교, Book 실습 코드, 어려웠던 점과 해결 방법(Coparable 오타, null hashCode 검증)이 기록됨.

예상 코드 리뷰 노력

🎯 2 (Simple) | ⏱️ ~10 minutes

🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (1 warning, 1 inconclusive)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
Title check ❓ Inconclusive 제목이 과제 번호와 이름만 있어 변경 내용을 알 수 없어 다소 모호합니다. 주요 변경을 요약하는 짧은 문장으로 바꾸세요(예: 인스턴스 기본조작 학습 기록 추가).
✅ Passed checks (3 passed)
Check name Status Explanation
Description check ✅ Passed 필수 섹션인 과제 정보, 체크리스트, 실행 결과, 질문/회고가 모두 포함되어 템플릿을 충분히 따릅니다.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 5

🧹 Nitpick comments (5)
TIL/sample/2026-06-30.md (2)

15-24: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

try-catch를 사용한 NPE 처리 방식에 대한 학습 내용 보완이 필요합니다.

try-catchNullPointerException을 잡아 0을 반환하는 패턴은 동작하지만, Java에서는 권장되지 않는 예외 제어 흐름(Exception Control Flow)입니다. 사실상 if (date == null) 체크가 더 명시적이고 성능상 유리합니다. 학습 일지에 이 점을 추가하면 더 균형 잡힌 이해가 됩니다.

현재 getDate() 구현:

private int getDate(Date date) {
    try {
        // ... NPE 발생 가능
    } catch (NullPointerException e) {
        return NULL_DATE_VALUE;
    }
}

권장 방식:

private int getDate(Date date) {
    if (date == null) {
        return NULL_DATE_VALUE;
    }
    // ... Calendar 조작
}

참고: Effective Java 등에서도 예외를 제어 흐름용으로 사용하지 말 것을 권장합니다.

🤖 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 `@TIL/sample/2026-06-30.md` around lines 15 - 24, 학습 내용에서 `try-catch`로
`NullPointerException`을 잡아 `NULL_DATE_VALUE`를 반환하는 패턴을 일반적인 방어 방식처럼 보이지 않게
보완하세요. `getDate()`와 `publishDate` 관련 설명에, null 여부는 `try-catch`보다 `if (date ==
null)` 같은 사전 체크가 더 명시적이고 권장된다는 점을 추가하고, 예외 제어 흐름을 NPE 처리의 기본 해법처럼 서술한 부분을 수정하세요.
`getDate(Date date)`와 `NULL_DATE_VALUE`, `publishDate` 문맥을 기준으로 해당 설명을 업데이트하면
됩니다.

1-127: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value

학습 일지 전반: 코드와 문서의 동기화 상태 확인 필요

TIL 문서는 학습 과정을 기록하는 것으로 기능적 결함은 없으나, 위에서 지적한 두 가지 주요 불일치(Coparable 오타 수정 주장, clone() null 방어 코드 존재 주장)로 인해 향후 코드 유지보수 시 혼란을 야기할 수 있습니다. 문서 기록 시점의 코드 상태와 실제 코드 상태를 주기적으로 동기화하는 습관을 권장합니다.

🤖 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 `@TIL/sample/2026-06-30.md` around lines 1 - 127, The TIL entry in Book is out
of sync with the actual code: it claims a Comparable typo was fixed and that
clone() has null-guard deep-copy behavior, so update the prose to match the
current Book class implementation and remove or correct any outdated statements.
Verify the descriptions around getDate(), equals(), hashCode(), compareTo(), and
clone() so they reflect the real behavior of those methods rather than a
previously discussed or hypothetical state. Keep the narrative consistent with
the code’s current symbols and avoid mentioning fixes that are no longer
present.
day01-basic/src/main/java/com/survivalcoding/day260630/Coparable.java (1)

3-5: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

인터페이스명이 오탈자라서 계약이 분리돼 있습니다.

Coparable는 표준 Comparable과 한 글자 차이라 검색/구현/학습 자료 전부를 헷갈리게 합니다. 게다가 이 PR의 BookComparable<Book>를 구현하고 있어서, 현재 이 인터페이스는 같은 기능을 의도했다면 실제로 연결되지 않습니다. 이름을 바로잡거나, 과제 목적상 불필요하면 제거하는 편이 안전합니다.

🤖 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 `@day01-basic/src/main/java/com/survivalcoding/day260630/Coparable.java` around
lines 3 - 5, `Coparable<T>` is misspelled and does not match the standard
comparison contract, so it is effectively disconnected from the `Book`
implementation. Rename the interface to `Comparable<T>` if it is meant to define
ordering, or remove it if `Book` and the rest of the code should rely on the
existing standard interface instead. Make sure any references in the
comparison-related types are updated to use the corrected symbol so the contract
is consistent.
day01-basic/src/test/java/com/survivalcoding/day260630/BookTest.java (1)

103-110: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

깊은 복사 테스트가 내부 상태 노출을 전제로 하고 있습니다.

cloned.getPublishDate().setTime(0) 방식은 getter가 방어적 복사로 바뀌면 바로 깨집니다. 이 테스트는 깊은 복사 자체보다 “가변 Date를 외부에 그대로 노출한다”는 구현 세부사항을 고정해 버리니, 복사본에 새 날짜를 setPublishDate()로 넣는 방식처럼 캡슐화와 무관한 검증으로 바꾸는 편이 낫습니다.

🤖 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 `@day01-basic/src/test/java/com/survivalcoding/day260630/BookTest.java` around
lines 103 - 110, The deep-copy test in BookTest is relying on internal Date
exposure through getPublishDate(), which will break if defensive copying is
added. Update the test to verify deep copy behavior without mutating the
returned Date directly: use the cloned Book’s public API, such as
setPublishDate(), to assign a different date and then assert the original Book
remains unchanged. Keep the focus on Book and clone() behavior rather than
getter implementation details.
day01-basic/src/main/java/com/survivalcoding/day260630/Book.java (1)

40-49: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

NullPointerException로 분기하지 말고 null을 먼저 검사하세요.

여기서 NPE를 삼키면, 나중에 이 메서드 안에 다른 null 버그가 들어와도 전부 0으로 숨겨집니다. date == null을 먼저 반환하는 쪽이 의도도 더 명확합니다.

🤖 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 `@day01-basic/src/main/java/com/survivalcoding/day260630/Book.java` around
lines 40 - 49, The getDate(Date date) method is using a NullPointerException
catch to handle null input, which hides unrelated bugs; update Book.getDate to
check whether date is null before creating and using the Calendar, and return
NULL_DATE_VALUE immediately for that case. Keep the rest of the date-to-integer
conversion logic unchanged, and remove the exception-driven control flow so only
the intended null case is handled explicitly.
🤖 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 `@day01-basic/src/main/java/com/survivalcoding/day260630/Book.java`:
- Around line 68-74: `Book.compareTo(Book)`가 `equals()`와 불일치하므로, 날짜가 같은 경우에도
`compareTo() == 0`이 되지 않도록 보조 정렬 키를 추가하세요. `compareTo()`에서
`getDate(this.publishDate)`와 `getDate(book.publishDate)`를 먼저 비교한 뒤, 같다면 `title`
같은 식별 가능한 필드를 한 번 더 비교해 `equals()`와 일관되게 만드세요. `Book`의 `compareTo`, `equals`,
`title`, `publishDate`를 기준으로 수정하면 됩니다.
- Around line 24-30: The Book publish date accessors are exposing mutable Date
state directly, which lets callers change the internal value after
equals/hashCode/compareTo have been based on it. Update getPublishDate() and
setPublishDate() in Book to use defensive copying on both read and write, and
make sure any internal publishDate usage continues to rely on the copied value
rather than the caller’s Date instance.
- Around line 76-80: `Book.clone()` currently dereferences `publishDate`
unconditionally, so cloning a `Book` with no date throws a null-related failure.
Update the `clone()` method to handle the `publishDate` field safely in the
`Book` class: only create the defensive `Date` copy when `publishDate` is
non-null, otherwise leave the cloned field null. Keep the existing
`super.clone()` flow and ensure the cloned object still copies all other state
correctly.

In `@TIL/sample/2026-06-30.md`:
- Around line 118-122: TIL 내용이 실제 코드 상태와 불일치하므로, “Coparable 오타 수정”이라는 서술을 현재 구현에
맞게 정정하거나 실제로 `Coparable`을 `Comparable`로 리네임한 뒤 관련 설명까지 함께 갱신하세요. 특히 `Coparable`
인터페이스명과 이를 다루는 해당 문단의 서술을 일치시키고, 실제 파일/클래스 상태를 반영하도록 `Coparable` 또는 `Comparable`
중 하나로 통일하세요.
- Around line 95-107: The `Book.clone()` example in the TIL is out of sync with
the actual `Book` implementation because it shows a null guard for `publishDate`
that the real code does not have. Either update the TIL snippet to match the
current `clone()` behavior, or apply the same `if (this.publishDate != null)`
defensive copy logic in `Book.clone()` so the documented example and the real
method stay consistent.

---

Nitpick comments:
In `@day01-basic/src/main/java/com/survivalcoding/day260630/Book.java`:
- Around line 40-49: The getDate(Date date) method is using a
NullPointerException catch to handle null input, which hides unrelated bugs;
update Book.getDate to check whether date is null before creating and using the
Calendar, and return NULL_DATE_VALUE immediately for that case. Keep the rest of
the date-to-integer conversion logic unchanged, and remove the exception-driven
control flow so only the intended null case is handled explicitly.

In `@day01-basic/src/main/java/com/survivalcoding/day260630/Coparable.java`:
- Around line 3-5: `Coparable<T>` is misspelled and does not match the standard
comparison contract, so it is effectively disconnected from the `Book`
implementation. Rename the interface to `Comparable<T>` if it is meant to define
ordering, or remove it if `Book` and the rest of the code should rely on the
existing standard interface instead. Make sure any references in the
comparison-related types are updated to use the corrected symbol so the contract
is consistent.

In `@day01-basic/src/test/java/com/survivalcoding/day260630/BookTest.java`:
- Around line 103-110: The deep-copy test in BookTest is relying on internal
Date exposure through getPublishDate(), which will break if defensive copying is
added. Update the test to verify deep copy behavior without mutating the
returned Date directly: use the cloned Book’s public API, such as
setPublishDate(), to assign a different date and then assert the original Book
remains unchanged. Keep the focus on Book and clone() behavior rather than
getter implementation details.

In `@TIL/sample/2026-06-30.md`:
- Around line 15-24: 학습 내용에서 `try-catch`로 `NullPointerException`을 잡아
`NULL_DATE_VALUE`를 반환하는 패턴을 일반적인 방어 방식처럼 보이지 않게 보완하세요. `getDate()`와
`publishDate` 관련 설명에, null 여부는 `try-catch`보다 `if (date == null)` 같은 사전 체크가 더
명시적이고 권장된다는 점을 추가하고, 예외 제어 흐름을 NPE 처리의 기본 해법처럼 서술한 부분을 수정하세요. `getDate(Date
date)`와 `NULL_DATE_VALUE`, `publishDate` 문맥을 기준으로 해당 설명을 업데이트하면 됩니다.
- Around line 1-127: The TIL entry in Book is out of sync with the actual code:
it claims a Comparable typo was fixed and that clone() has null-guard deep-copy
behavior, so update the prose to match the current Book class implementation and
remove or correct any outdated statements. Verify the descriptions around
getDate(), equals(), hashCode(), compareTo(), and clone() so they reflect the
real behavior of those methods rather than a previously discussed or
hypothetical state. Keep the narrative consistent with the code’s current
symbols and avoid mentioning fixes that are no longer present.
🪄 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: 8a2ba262-af8b-4bd9-8832-004d925467ae

📥 Commits

Reviewing files that changed from the base of the PR and between 5daa20d and 4f4b7c5.

📒 Files selected for processing (5)
  • TIL/sample/2026-06-30.md
  • day01-basic/src/main/java/com/survivalcoding/day260629/StrongBox.java
  • day01-basic/src/main/java/com/survivalcoding/day260630/Book.java
  • day01-basic/src/main/java/com/survivalcoding/day260630/Coparable.java
  • day01-basic/src/test/java/com/survivalcoding/day260630/BookTest.java

Comment on lines +24 to +30
public Date getPublishDate() {
return publishDate;
}

public void setPublishDate(Date publishDate) {
this.publishDate = publishDate;
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🗄️ Data Integrity & Integration | 🟠 Major | ⚡ Quick win

가변 Date를 그대로 주고받으면 동등성/정렬 계약이 깨집니다.

지금은 외부 코드가 getPublishDate()로 받은 Date를 수정하거나, setPublishDate()에 넘긴 Date를 나중에 다시 수정해서 equals()/hashCode()/compareTo() 기준을 뒤에서 바꿀 수 있습니다. BookHashSet이나 정렬 컬렉션에 넣은 뒤 상태가 바뀌는 형태라서 위험합니다. getter/setter 둘 다 방어적 복사로 막는 편이 좋습니다.

수정 예시
     public Date getPublishDate() {
-        return publishDate;
+        return publishDate == null ? null : new Date(publishDate.getTime());
     }

     public void setPublishDate(Date publishDate) {
-        this.publishDate = publishDate;
+        this.publishDate = publishDate == null ? null : new Date(publishDate.getTime());
     }
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
public Date getPublishDate() {
return publishDate;
}
public void setPublishDate(Date publishDate) {
this.publishDate = publishDate;
}
public Date getPublishDate() {
return publishDate == null ? null : new Date(publishDate.getTime());
}
public void setPublishDate(Date publishDate) {
this.publishDate = publishDate == null ? null : new Date(publishDate.getTime());
}
🤖 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 `@day01-basic/src/main/java/com/survivalcoding/day260630/Book.java` around
lines 24 - 30, The Book publish date accessors are exposing mutable Date state
directly, which lets callers change the internal value after
equals/hashCode/compareTo have been based on it. Update getPublishDate() and
setPublishDate() in Book to use defensive copying on both read and write, and
make sure any internal publishDate usage continues to rely on the copied value
rather than the caller’s Date instance.

Comment on lines +68 to +74
@Override
public int compareTo(Book book) {
int thisDate = getDate(this.publishDate);
int otherDate = getDate(book.publishDate);

return Integer.compare(otherDate, thisDate);
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🗄️ Data Integrity & Integration | 🟠 Major | ⚡ Quick win

compareTo()equals()와 일관되지 않습니다.

현재는 날짜만 비교해서, 제목이 다른 두 책도 같은 날짜면 compareTo() == 0이 됩니다. 반면 equals()는 제목까지 비교하므로 TreeSet/TreeMap에서는 서로 다른 책이 같은 원소처럼 취급될 수 있습니다. 날짜가 같을 때는 제목 같은 보조 키로 한 번 더 비교해야 합니다.

🤖 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 `@day01-basic/src/main/java/com/survivalcoding/day260630/Book.java` around
lines 68 - 74, `Book.compareTo(Book)`가 `equals()`와 불일치하므로, 날짜가 같은 경우에도
`compareTo() == 0`이 되지 않도록 보조 정렬 키를 추가하세요. `compareTo()`에서
`getDate(this.publishDate)`와 `getDate(book.publishDate)`를 먼저 비교한 뒤, 같다면 `title`
같은 식별 가능한 필드를 한 번 더 비교해 `equals()`와 일관되게 만드세요. `Book`의 `compareTo`, `equals`,
`title`, `publishDate`를 기준으로 수정하면 됩니다.

Comment on lines +76 to +80
@Override
public Book clone() {
try {
Book result = (Book) super.clone();
result.publishDate = new Date(this.publishDate.getTime());

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🩺 Stability & Availability | 🔴 Critical | ⚡ Quick win

publishDate가 null이면 clone()이 바로 터집니다.

Line 80에서 this.publishDate.getTime()을 바로 호출해서, 날짜 없는 책은 복제할 수 없습니다. 현재 추가된 null-clone 테스트도 이 경로에서 실패합니다.

수정 예시
     `@Override`
     public Book clone() {
         try {
             Book result = (Book) super.clone();
-            result.publishDate = new Date(this.publishDate.getTime());
+            result.publishDate = this.publishDate == null
+                    ? null
+                    : new Date(this.publishDate.getTime());
             return result;
         } catch (CloneNotSupportedException e) {
             throw new RuntimeException(e);
         }
     }
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
@Override
public Book clone() {
try {
Book result = (Book) super.clone();
result.publishDate = new Date(this.publishDate.getTime());
`@Override`
public Book clone() {
try {
Book result = (Book) super.clone();
result.publishDate = this.publishDate == null
? null
: new Date(this.publishDate.getTime());
return result;
} catch (CloneNotSupportedException e) {
throw new RuntimeException(e);
}
}
🤖 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 `@day01-basic/src/main/java/com/survivalcoding/day260630/Book.java` around
lines 76 - 80, `Book.clone()` currently dereferences `publishDate`
unconditionally, so cloning a `Book` with no date throws a null-related failure.
Update the `clone()` method to handle the `publishDate` field safely in the
`Book` class: only create the defensive `Date` copy when `publishDate` is
non-null, otherwise leave the cloned field null. Keep the existing
`super.clone()` flow and ensure the cloned object still copies all other state
correctly.

Comment thread TIL/sample/2026-06-30.md
Comment on lines +95 to +107
@Override
public Book clone() {
try {
Book result = (Book) super.clone();
// 방어 코드: publishDate가 null이 아닐 때만 깊은 복사를 수행하여 NPE 예방
if (this.publishDate != null) {
result.publishDate = new Date(this.publishDate.getTime());
}
return result;
} catch (CloneNotSupportedException e) {
throw new RuntimeException(e);
}
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

📐 Maintainability & Code Quality | 🟡 Minor | ⚡ Quick win

TIL의 clone() 코드 스니펫이 실제 구현과 불일치합니다.

TIL에 작성된 clone() 메서드는 if (this.publishDate != null) 방어 로직을 포함하지만, 실제 Book.java 구현에서는 해당 null 체크가 없어 publishDate가 null일 때 NullPointerException이 발생합니다. 학습 일지가 실제 코드보다 더 안전한 구현을 문서화하고 있어, 코드와 문서 간 동기화가 필요합니다.

     `@Override`
     public Book clone() {
         try {
             Book result = (Book) super.clone();
-            // 방어 코드: publishDate가 null이 아닐 때만 깊은 복사를 수행하여 NPE 예방
-            if (this.publishDate != null) {
-                result.publishDate = new Date(this.publishDate.getTime());
-            }
+            result.publishDate = new Date(this.publishDate.getTime());
             return result;
         } catch (CloneNotSupportedException e) {
             throw new RuntimeException(e);
         }
     }

실제 코드를 TIL에 반영하거나, 실제 코드에 TIL의 방어 로직을 적용하세요.

📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
@Override
public Book clone() {
try {
Book result = (Book) super.clone();
// 방어 코드: publishDate가 null이 아닐 때만 깊은 복사를 수행하여 NPE 예방
if (this.publishDate != null) {
result.publishDate = new Date(this.publishDate.getTime());
}
return result;
} catch (CloneNotSupportedException e) {
throw new RuntimeException(e);
}
}
`@Override`
public Book clone() {
try {
Book result = (Book) super.clone();
result.publishDate = new Date(this.publishDate.getTime());
return result;
} catch (CloneNotSupportedException e) {
throw new RuntimeException(e);
}
}
🤖 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 `@TIL/sample/2026-06-30.md` around lines 95 - 107, The `Book.clone()` example
in the TIL is out of sync with the actual `Book` implementation because it shows
a null guard for `publishDate` that the real code does not have. Either update
the TIL snippet to match the current `clone()` behavior, or apply the same `if
(this.publishDate != null)` defensive copy logic in `Book.clone()` so the
documented example and the real method stay consistent.

Comment thread TIL/sample/2026-06-30.md
Comment on lines +118 to +122
## 해결 방법

- 클래스 선언부를 정밀 분석한 결과, 자바 표준 인터페이스 명칭인 `Comparable`을 **`Coparable`로 잘못 타이핑한 오타**를 찾아내어 수정함으로써 제네릭 컴파일 에러를 깔끔하게 해결했습니다.
- JUnit 테스트 코드에서 단순히 무오류를 검증하는 것뿐만 아니라, `null` 객체가 생성한 최종 해시값을 `0`을 대입한 예상값(`Objects.hash(title, 0)`)과 정밀하게 `assertEquals`로 상호 비교함으로써 예외 처리 블록의 완벽한 동작을 입증했습니다.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

📐 Maintainability & Code Quality | 🟡 Minor | ⚡ Quick win

Coparable 오타 수정 주장이 실제 코드와 불일치합니다.

TIL에서 "Coparable로 잘못 타이핑한 오타를 찾아내어 수정함"이라고 기술했으나, 실제 코드베이스에는 여전히 Coparable.java 파일이 존재합니다. 이는 학습 일지의 사실 관계와 실제 코드 상태가 맞지 않음을 의미합니다.

  • 실제 파일: day01-basic/src/main/java/com/survivalcoding/day260630/Coparable.java
  • 인터페이스명: public interface Coparable<T>

TIL 내용을 실제 코드 상태에 맞게 수정하거나, 실제로 Comparable로 rename 리팩토링을 완료하세요.

🤖 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 `@TIL/sample/2026-06-30.md` around lines 118 - 122, TIL 내용이 실제 코드 상태와 불일치하므로,
“Coparable 오타 수정”이라는 서술을 현재 구현에 맞게 정정하거나 실제로 `Coparable`을 `Comparable`로 리네임한 뒤
관련 설명까지 함께 갱신하세요. 특히 `Coparable` 인터페이스명과 이를 다루는 해당 문단의 서술을 일치시키고, 실제 파일/클래스 상태를
반영하도록 `Coparable` 또는 `Comparable` 중 하나로 통일하세요.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant