Skip to content

CLEANUP: Replace assert statements with proper exception handling#1077

Merged
jhpark816 merged 1 commit intonaver:developfrom
f1v3-dev:cleanup/assert
Apr 23, 2026
Merged

CLEANUP: Replace assert statements with proper exception handling#1077
jhpark816 merged 1 commit intonaver:developfrom
f1v3-dev:cleanup/assert

Conversation

@f1v3-dev
Copy link
Copy Markdown
Collaborator

@f1v3-dev f1v3-dev commented Apr 6, 2026

🔗 Related Issue

⌨️ What I did

  • assert 문을 중요도에 따라 분류하고, 중요도 높음 항목을 우선 처리합니다.

처리 기준

  • I/O Thread 내 서버 응답 검증 → IllegalStateException 으로 대체
  • null, 범위 검증 assert 제거 → RuntimeException(NPE, IndexOutOfBoundsException 등) 발생하므로 불필요
  • 상위 조건으로 이미 보장된 assert 제거

@f1v3-dev f1v3-dev requested a review from oliviarla April 6, 2026 08:15
@f1v3-dev f1v3-dev self-assigned this Apr 6, 2026
@jhpark816 jhpark816 requested a review from uhm0311 April 6, 2026 08:17
uhm0311
uhm0311 previously approved these changes Apr 6, 2026
Copy link
Copy Markdown
Collaborator

@jhpark816 jhpark816 left a comment

Choose a reason for hiding this comment

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

리뷰 완료

Comment thread src/main/java/net/spy/memcached/protocol/ascii/BaseGetOpImpl.java Outdated
Comment thread src/main/java/net/spy/memcached/protocol/ascii/BaseGetOpImpl.java
Comment thread src/main/java/net/spy/memcached/protocol/ascii/BaseGetOpImpl.java
Copy link
Copy Markdown
Collaborator

@oliviarla oliviarla left a comment

Choose a reason for hiding this comment

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

리뷰 완료입니다.

Comment thread src/main/java/net/spy/memcached/AddrUtil.java Outdated
oliviarla
oliviarla previously approved these changes Apr 9, 2026
Copy link
Copy Markdown
Collaborator

@jhpark816 jhpark816 left a comment

Choose a reason for hiding this comment

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

일부 리뷰

Comment thread src/main/java/net/spy/memcached/protocol/ascii/BaseGetOpImpl.java
@f1v3-dev
Copy link
Copy Markdown
Collaborator Author

transcoders 패키지

서버에서 온 외부 데이터 검증이며 I/O Thread에서 실행되지 않으므로 throw new IllegalStateException으로 교체했습니다.

파일 변경 내용
TranscoderUtils decodeInt/Long/Byte/Boolean의 assert → IllegalStateException
WhalinTranscoder decodeBoolean의 assert → IllegalStateException
WhalinV1Transcoder decodeByte/Integer/Float/Double/Boolean의 assert → IllegalStateException

protocol/ascii 패키지

I/O Thread에서 실행되므로 케이스별로 판단했습니다.

assert 내용 판단 처리
tmp != lookingFor (\r\n 검증) 스트림 오염 → reconnect IllegalStateException으로 교체
"VALUE".equals(stuff[0]) startsWith("VALUE ") 진입 조건으로 이미 보장 제거
stuff.length == N 위반 시 자연스럽게 ArrayIndexOutOfBoundsException 발생 제거
key/data != null, readOffset <= data.length 내부 불변식 제거
default: assert false (\r\n switch) lookingFor'\r', '\n'만 가능 — 도달 불가 제거
initialize() switch default 없음 하위 클래스가 get/gets/gat/gats/mget/mgets만 전달 — 도달 불가 제거

@oliviarla

위와 같이 변경하였습니다. 리뷰 부탁드립니다.

Copy link
Copy Markdown
Collaborator

@oliviarla oliviarla left a comment

Choose a reason for hiding this comment

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

리뷰 완료입니다.

Comment thread src/main/java/net/spy/memcached/protocol/ascii/BaseGetOpImpl.java
oliviarla
oliviarla previously approved these changes Apr 21, 2026
@oliviarla oliviarla requested a review from jhpark816 April 21, 2026 06:52
Copy link
Copy Markdown
Collaborator

@jhpark816 jhpark816 left a comment

Choose a reason for hiding this comment

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

일부 리뷰

commandBuilder.append(RN_STRING);
commandBuilder.append(keysString);
commandBuilder.append(RN_STRING);
break;
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

default 문에서 exception throw가 맞지 않나 생각합니다.

아래에 있는 코드를 수행한다면, 오히려 맞지 않기 때문입니다.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

inittialize() 를 호출하는 하위 클래스에서 현재 switch-case 이외의 cmd 값을 넘기지 않습니다.

따라서 도달할 수 없는 코드라고 판단하여 default를 제거한 상태입니다.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

default 문으로 기존대로 assert 추가해 두는 것이 좋겠습니다.

assert는 현재 코드 기준으로 false여야 합니다.
향후 코드 수정하더라도 false를 만족시켜야 함을 알 수 있으며,
위의 예시에서 그 외의 cmd가 없음을 명시하는 효과가 있습니다.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

default:
  assert false : "Unknown command: " + cmd;

위와 같이 반영하도록 하겠습니다.

Comment thread src/main/java/net/spy/memcached/protocol/ascii/BaseGetOpImpl.java
Comment thread src/main/java/net/spy/memcached/protocol/ascii/BaseGetOpImpl.java
Copy link
Copy Markdown
Collaborator

@jhpark816 jhpark816 left a comment

Choose a reason for hiding this comment

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

일부 리뷰

Comment thread src/main/java/net/spy/memcached/protocol/ascii/BaseGetOpImpl.java
commandBuilder.append(RN_STRING);
commandBuilder.append(keysString);
commandBuilder.append(RN_STRING);
break;
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

default 문으로 기존대로 assert 추가해 두는 것이 좋겠습니다.

assert는 현재 코드 기준으로 false여야 합니다.
향후 코드 수정하더라도 false를 만족시켜야 함을 알 수 있으며,
위의 예시에서 그 외의 cmd가 없음을 명시하는 효과가 있습니다.

@jhpark816 jhpark816 requested a review from oliviarla April 23, 2026 04:50
@jhpark816
Copy link
Copy Markdown
Collaborator

@oliviarla
수정된 사항이 있으니, 최종 리뷰 바랍니다.

@jhpark816 jhpark816 merged commit f444e43 into naver:develop Apr 23, 2026
2 checks passed
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.

4 participants