260630_22_진미#101
Conversation
|
이번 변경에서는 OOP 기본 개념을 연습할 수 있는 예제와 다이어그램이 추가·수정되었습니다. 변경 내용
학습 포인트
Walkthrough
ChangesStrongBox KeyType 잠금 로직 구현
Book2 클래스 및 게임 다이어그램 추가
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes 🚥 Pre-merge checks | ✅ 2 | ❌ 3❌ Failed checks (2 warnings, 1 inconclusive)
✅ Passed checks (2 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 Warning |
There was a problem hiding this comment.
Actionable comments posted: 6
🧹 Nitpick comments (1)
post-oop/src/test/java/com/survivalcoding/StrongBoxTest.java (1)
9-23: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win
PADLOCK만 검증해서 나머지 분기 회귀를 놓치기 쉽습니다.핵심 변경이
KeyType별 임계값 분기인데, 현재 테스트는PADLOCK의1024회만 확인합니다.BUTTON,DIAL,FINGER도 같은 패턴으로 묶어 검증해야 이번 변경을 제대로 보호할 수 있습니다.예시 수정
- `@Test` - void test() { - - StrongBox<Integer> box = - new StrongBox<>(KeyType.PADLOCK); - - box.put(100); - - for (int i = 0; i < 1023; i++) { - assertNull(box.get()); - } - - assertEquals(100, box.get()); - - } + `@ParameterizedTest` + `@CsvSource`({ + "PADLOCK,1024", + "BUTTON,10000", + "DIAL,30000", + "FINGER,1000000" + }) + void get_returns_value_only_after_threshold(KeyType keyType, int threshold) { + StrongBox<Integer> box = new StrongBox<>(keyType); + box.put(100); + + for (int i = 0; i < threshold - 1; i++) { + assertNull(box.get()); + } + + assertEquals(100, box.get()); + }🤖 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 `@post-oop/src/test/java/com/survivalcoding/StrongBoxTest.java` around lines 9 - 23, The StrongBox test only covers the PADLOCK path, so it can miss regressions in the other KeyType threshold branches. Update StrongBoxTest to exercise StrongBox.get() for BUTTON, DIAL, and FINGER as well, using the same pattern as the existing PADLOCK test but with each type’s expected unlock count. Keep the assertions grouped by KeyType so the threshold logic in StrongBox and KeyType is verified across all branches.
🤖 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 `@game/june23th.puml`:
- Around line 9-31: The UML names and field identifiers are inconsistent and
contain typos, so clean up the domain terminology across the class declarations
in this diagram. Rename the misspelled class names and attributes in the
PlantUML snippet (for example, align symbols like Trank/Dragun/damege with the
intended game-unit and damage naming) so the diagram uses one stable vocabulary
throughout. Keep the changes localized to the affected class definitions so the
rendered model matches the corrected identifiers everywhere.
In `@game/src/main/java/com/survivalcoding/Book2.java`:
- Around line 49-59: The Book2.equals(Object) implementation is broken and does
not compile; fix it by comparing the actual Book2 fields instead of the invalid
local Data variable and nonexistent bb.Data member. Update equals in Book2 to
use proper null-safe field comparisons (for example via Objects.equals) for
title and the other real member fields, remove the unreachable statement after
return, and keep the logic consistent with hashCode().
- Around line 2-3: Replace the incorrect javax.xml.crypto.Data import in Book2
with a real date type such as java.time.LocalDate, then update the publishDate
field, constructor, getter, and setter in Book2 to use that same type
consistently. Also make sure any related UML mapping in game/june30th.puml is
updated to match the new date type so the model stays aligned with the code.
In `@post-oop/src/main/java/com/survivalcoding/StrongBox.java`:
- Around line 19-20: StrongBox.put(K data)에서 null 저장을 허용하면 get()의 잠김 상태 반환값과 구분이
깨집니다. StrongBox 클래스의 put 메서드에서 null 인자를 명시적으로 거부하도록 수정하고, 잠금/해제 상태를 나타내는 get()의
계약은 유지하세요. put, get, StrongBox 식별자를 기준으로 null 처리 정책을 일관되게 맞추면 됩니다.
- Around line 24-25: The StrongBox constructor currently accepts a null keyType,
which leaves StrongBox.get() unable to match any branch and causes silent,
permanent null returns. Update the StrongBox(KeyType) constructor to validate
keyType immediately and reject null at creation time, using the StrongBox and
get() logic as the reference points to keep the invalid state from being
constructed.
In `@TIL/sample/2026-06-30-정리.md`:
- Around line 5-7: 정리 문구가 equals, compareTo, Set 중복 규칙을 혼동하고 있으니, 해당 메모에서 각 개념을
분리해 수정하세요. compareTo는 정렬/비교 기준 설명으로만 남기고, “같은 내용은 지워진다”는 문장은 Set에서 equals와
hashCode가 함께 일관될 때의 중복 제거로 바꿔 쓰세요. Book2 같은 예제가 있다면 equals/compareTo/HashSet 동작을
각각 구분해서 설명하도록 문구를 정리하세요.
---
Nitpick comments:
In `@post-oop/src/test/java/com/survivalcoding/StrongBoxTest.java`:
- Around line 9-23: The StrongBox test only covers the PADLOCK path, so it can
miss regressions in the other KeyType threshold branches. Update StrongBoxTest
to exercise StrongBox.get() for BUTTON, DIAL, and FINGER as well, using the same
pattern as the existing PADLOCK test but with each type’s expected unlock count.
Keep the assertions grouped by KeyType so the threshold logic in StrongBox and
KeyType is verified across all branches.
🪄 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: 41f4fd5d-19a5-4564-b952-ba23f1a68bfd
📒 Files selected for processing (10)
TIL/sample/2026-06-30-정리.mdTIL/sample/📌2026-06-29-정리📌.mdgame/june22th.pumlgame/june23th.pumlgame/june30th.pumlgame/src/main/java/com/survivalcoding/Book2.javapost-oop/june30th.pumlpost-oop/src/main/java/com/survivalcoding/StrongBox.javapost-oop/src/test/java/com/survivalcoding/StrongBoxTest.javasettings.gradle
💤 Files with no reviewable changes (1)
- settings.gradle
| class Marine{ | ||
| -int damege | ||
| } | ||
| class Trank{ | ||
| -int damage | ||
| } | ||
| class Vulture{ | ||
| -int damage | ||
| } | ||
| class Scv{ | ||
| -int damage | ||
| } | ||
| class Zergling{ | ||
| -int damage | ||
| } | ||
| class Hydra{ | ||
| - int damege | ||
| } | ||
| class Dragun{ | ||
| -int damege | ||
| } | ||
| class Zealot{ | ||
| - int damege |
There was a problem hiding this comment.
📐 Maintainability & Code Quality | 🟡 Minor | ⚡ Quick win
클래스/필드 이름 오타가 다이어그램 의미를 흐립니다.
Trank, Dragun, damege 같은 표기가 여러 군데 섞여 있어 렌더링 결과만 봐도 도메인 용어가 불안정해 보입니다. 학습용 산출물이라도 용어를 한 번 정리해 두는 편이 이후 코드/테스트 이름과 맞추기 쉽습니다.
🤖 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 `@game/june23th.puml` around lines 9 - 31, The UML names and field identifiers
are inconsistent and contain typos, so clean up the domain terminology across
the class declarations in this diagram. Rename the misspelled class names and
attributes in the PlantUML snippet (for example, align symbols like
Trank/Dragun/damege with the intended game-unit and damage naming) so the
diagram uses one stable vocabulary throughout. Keep the changes localized to the
affected class definitions so the rendered model matches the corrected
identifiers everywhere.
| import javax.xml.crypto.Data; | ||
| import java.util.Objects; |
There was a problem hiding this comment.
🗄️ Data Integrity & Integration | 🟠 Major | ⚡ Quick win
🧩 Analysis chain
🏁 Script executed:
#!/bin/bash
set -euo pipefail
printf '\n== Book2.java ==\n'
sed -n '1,220p' game/src/main/java/com/survivalcoding/Book2.java
printf '\n== UML files mentioning Book2 or publishDate ==\n'
rg -n --hidden --glob '!*node_modules*' --glob '!*.class' --glob '!*.jar' 'Book2|publishDate' game/src/main/java game/src/main/resources . || trueRepository: SurvivalCodingCampus/polytech_java2
Length of output: 4149
🏁 Script executed:
#!/bin/bash
set -euo pipefail
printf '\n== JDK Data type lookup in source and docs hints ==\n'
rg -n 'javax\.xml\.crypto\.Data|publishDate|equals\(' game/src/main/java game/src/main/resources . || trueRepository: SurvivalCodingCampus/polytech_java2
Length of output: 2772
🏁 Script executed:
#!/bin/bash
set -euo pipefail
echo '== Book2.java =='
nl -ba game/src/main/java/com/survivalcoding/Book2.java | sed -n '1,220p'
echo
echo '== References to Book2 / publishDate / equals =='
rg -n --hidden --glob '!*node_modules*' 'Book2|publishDate|equals\(' game/src/main/java game/src/main/resources . || trueRepository: SurvivalCodingCampus/polytech_java2
Length of output: 230
publishDate를 날짜 타입으로 바꾸세요.
javax.xml.crypto.Data는 XML 암호화용 인터페이스라 출판일 의미와 맞지 않습니다. 생성자·게터·세터와 game/june30th.puml까지 같은 타입으로 묶여 있으니 java.time.LocalDate 같은 날짜 타입으로 정리하세요.
🤖 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 `@game/src/main/java/com/survivalcoding/Book2.java` around lines 2 - 3, Replace
the incorrect javax.xml.crypto.Data import in Book2 with a real date type such
as java.time.LocalDate, then update the publishDate field, constructor, getter,
and setter in Book2 to use that same type consistently. Also make sure any
related UML mapping in game/june30th.puml is updated to match the new date type
so the model stays aligned with the code.
| @Override | ||
| public boolean equals(Object obj) { | ||
|
|
||
| if (!(obj instanceof Book2)) return false; | ||
| Book2 bb = (Book2) obj; | ||
| String Data; | ||
| return title == bb.title && Data(equals(bb.Data)); | ||
| title.equals(Data); | ||
|
|
||
| //boolean Object; | ||
| } |
There was a problem hiding this comment.
🎯 Functional Correctness | 🔴 Critical | ⚡ Quick win
equals() 구현은 현재 상태로 컴파일되지 않습니다.
Line 54-56에서 지역 변수 Data 가 타입명을 가리고, bb.Data 는 존재하지 않는 멤버이며, return 뒤의 title.equals(Data); 는 도달 불가 코드입니다. Objects.equals(...) 로 실제 필드들을 비교하도록 정리해야 hashCode() 와의 계약도 맞습니다.
🔧 수정 예시
`@Override`
public boolean equals(Object obj) {
-
- if (!(obj instanceof Book2)) return false;
- Book2 bb = (Book2) obj;
- String Data;
- return title == bb.title && Data(equals(bb.Data));
- title.equals(Data);
-
- //boolean Object;
+ if (this == obj) return true;
+ if (!(obj instanceof Book2)) return false;
+ Book2 other = (Book2) obj;
+ return Objects.equals(title, other.title)
+ && Objects.equals(publishDate, other.publishDate)
+ && Objects.equals(comment, other.comment);
}🧰 Tools
🪛 PMD (7.25.0)
[Medium] 55-55: UseEqualsToCompareStrings (Error Prone): Use equals() to compare strings instead of '==' or '!='
(UseEqualsToCompareStrings (Error Prone))
[Medium] 56-56: UselessPureMethodCall (Error Prone): Do not call pure method equals if the result is not used.
(UselessPureMethodCall (Error Prone))
🤖 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 `@game/src/main/java/com/survivalcoding/Book2.java` around lines 49 - 59, The
Book2.equals(Object) implementation is broken and does not compile; fix it by
comparing the actual Book2 fields instead of the invalid local Data variable and
nonexistent bb.Data member. Update equals in Book2 to use proper null-safe field
comparisons (for example via Objects.equals) for title and the other real member
fields, remove the unreachable statement after return, and keep the logic
consistent with hashCode().
Source: Linters/SAST tools
| public void put(K date) { | ||
| this.data = date; |
There was a problem hiding this comment.
🎯 Functional Correctness | 🟠 Major | ⚡ Quick win
null 저장을 허용하면 잠금 상태와 해제 상태를 구분할 수 없습니다.
get()이 잠겨 있을 때 null을 반환하는데, 여기서 put(null)도 허용하면 해제된 뒤에도 동일하게 null이 반환되어 API 의미가 깨집니다. put()에서 null을 거부하거나 반환 계약을 바꿔야 합니다.
예시 수정
+import java.util.Objects;
+
public void put(K date) {
- this.data = date;
+ this.data = Objects.requireNonNull(date, "data");
}📝 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.
| public void put(K date) { | |
| this.data = date; | |
| import java.util.Objects; | |
| public void put(K date) { | |
| this.data = Objects.requireNonNull(date, "data"); |
🤖 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 `@post-oop/src/main/java/com/survivalcoding/StrongBox.java` around lines 19 -
20, StrongBox.put(K data)에서 null 저장을 허용하면 get()의 잠김 상태 반환값과 구분이 깨집니다. StrongBox
클래스의 put 메서드에서 null 인자를 명시적으로 거부하도록 수정하고, 잠금/해제 상태를 나타내는 get()의 계약은 유지하세요. put,
get, StrongBox 식별자를 기준으로 null 처리 정책을 일관되게 맞추면 됩니다.
| public StrongBox(KeyType keyType) { | ||
| this.keyType = keyType; |
There was a problem hiding this comment.
🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win
keyType는 생성자에서 바로 검증하는 편이 안전합니다.
지금은 new StrongBox<>(null)이 가능해서 get()이 어떤 분기도 타지 못하고 영구적으로 null만 반환합니다. 이 경우는 조용히 실패시키기보다 생성 시점에 막는 편이 낫습니다.
예시 수정
+import java.util.Objects;
+
public StrongBox(KeyType keyType) {
- this.keyType = keyType;
+ this.keyType = Objects.requireNonNull(keyType, "keyType");
}📝 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.
| public StrongBox(KeyType keyType) { | |
| this.keyType = keyType; | |
| import java.util.Objects; | |
| public StrongBox(KeyType keyType) { | |
| this.keyType = Objects.requireNonNull(keyType, "keyType"); |
🤖 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 `@post-oop/src/main/java/com/survivalcoding/StrongBox.java` around lines 24 -
25, The StrongBox constructor currently accepts a null keyType, which leaves
StrongBox.get() unable to match any branch and causes silent, permanent null
returns. Update the StrongBox(KeyType) constructor to validate keyType
immediately and reject null at creation time, using the StrongBox and get()
logic as the reference points to keep the invalid state from being constructed.
| h1 == h2 는 서로 다른 주소이므로 '=='가 들어갔어도 비교는 equals로 한다 | ||
| ㄴ> 비교하는 코드 틀 :: [h1.compareTo(h2)] | ||
| [equals() 특징] :: equals가 있으면 같은 내용은 지워진다 |
There was a problem hiding this comment.
📐 Maintainability & Code Quality | 🟡 Minor | ⚡ Quick win
equals, compareTo, Set 중복 규칙 설명이 서로 섞여 있습니다.
compareTo() 는 정렬 기준 비교이고, "같은 내용은 지워진다" 는 Set 에서 equals() 와 hashCode() 가 함께 일관될 때의 동작입니다. 지금 문구대로면 Book2 같은 예제의 동등성 계약을 잘못 학습하기 쉽습니다.
✏️ 문구 예시
-h1 == h2 는 서로 다른 주소이므로 '=='가 들어갔어도 비교는 equals로 한다
-ㄴ> 비교하는 코드 틀 :: [h1.compareTo(h2)]
-[equals() 특징] :: equals가 있으면 같은 내용은 지워진다
+h1 == h2 는 참조 비교이고, 내용 비교는 equals()를 사용한다
+ㄴ> compareTo()는 정렬/대소 비교가 필요할 때 사용한다
+[equals()/hashCode() 특징] :: Set/Map에서 같은 값으로 취급되려면 둘 다 일관되어야 한다📝 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.
| h1 == h2 는 서로 다른 주소이므로 '=='가 들어갔어도 비교는 equals로 한다 | |
| ㄴ> 비교하는 코드 틀 :: [h1.compareTo(h2)] | |
| [equals() 특징] :: equals가 있으면 같은 내용은 지워진다 | |
| h1 == h2 는 참조 비교이고, 내용 비교는 equals()를 사용한다 | |
| ㄴ> compareTo()는 정렬/대소 비교가 필요할 때 사용한다 | |
| [equals()/hashCode() 특징] :: Set/Map에서 같은 값으로 취급되려면 둘 다 일관되어야 한다 |
🤖 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 5 - 7, 정리 문구가 equals, compareTo,
Set 중복 규칙을 혼동하고 있으니, 해당 메모에서 각 개념을 분리해 수정하세요. compareTo는 정렬/비교 기준 설명으로만 남기고, “같은
내용은 지워진다”는 문장은 Set에서 equals와 hashCode가 함께 일관될 때의 중복 제거로 바꿔 쓰세요. Book2 같은 예제가 있다면
equals/compareTo/HashSet 동작을 각각 구분해서 설명하도록 문구를 정리하세요.
YYMMDD_01_홍길동
📝 과제 정보
📋 체크리스트
📷 실행 결과 (또는 테스트 결과)
❓질문 및 어려웠던 점
🔄 자체 평가 & 회고