naver / arcus-java-client

ARCUS Java client
Apache License 2.0
50 stars 47 forks source link

INTERNAL: Modify by JDK 21 lint #805

Closed cheesecrust closed 1 month ago

cheesecrust commented 1 month ago

πŸ”— Related Issue

⌨️ What I did

jdk 21 lint κ²½κ³ λ₯Ό ν•΄κ²°ν•˜μ˜€μŠ΅λ‹ˆλ‹€. κ²½κ³ λ₯Ό λ‚˜λˆ„μ–΄ μ§„ν–‰ν•˜λ €λ‹€. λ‹€λ₯Έ ν•œμͺ½μ˜ κ²½κ³ κ°€ λ„ˆλ¬΄ 적어(2개) ν•©μ³μ„œ μ§„ν–‰ν•˜μ˜€μŠ΅λ‹ˆλ‹€.

possible 'this' escape before subclass is fully initialized

μœ„λŠ” 아직 final ν΄λž˜μŠ€κ°€ μ•„λ‹Œ ν΄λž˜μŠ€μ— λŒ€ν•˜μ—¬ μ΄ˆκΈ°ν™”κ°€ λλ‚˜μ§€ μ•Šμ•˜μ„λ•Œ, λ‹€λ₯Έ ν΄λž˜μŠ€μ—μ„œ ν•΄λ‹Ή 클래슀λ₯Ό μ°Έμ‘°ν•˜λŠ” κ²½μš°μ— λ°œμƒν•©λ‹ˆλ‹€. μ΄λ•Œ μ΄ˆκΈ°ν™”κ°€ λλ‚œλ‹€λŠ”κ²ƒμ€ μƒμ„±μž 호좜이 λλ‚¬μ„λ•Œλ₯Ό μ˜λ―Έν•©λ‹ˆλ‹€.

λ”°λΌμ„œ κ²½κ³ λ₯Ό ν•΄κ²°ν•˜κΈ° μœ„ν•΄μ„œλŠ”

  1. final class 둜 μ„ μ–Έ
  2. μƒμ„±μžκ°€ λλ‚œ ν›„ λ‹€λ₯Έ ν•¨μˆ˜μ—μ„œ this λ₯Ό μ™ΈλΆ€λ‘œ λ„˜κΈ°λŠ” λ©”μ„œλ“œλ₯Ό ν˜ΈμΆœν•©λ‹ˆλ‹€.
  3. κ²½κ³ λ₯Ό μΌμœΌν‚€λŠ” ν•¨μˆ˜μ—μ„œ ν•˜λŠ” 일을 μƒμ„±μžμ—μ„œ ν•©λ‹ˆλ‹€. (λΆ€λͺ¨ν΄λž˜μŠ€μ˜ ν•„λ“œ μ΄ˆκΈ°ν™”)

ν˜„μž¬ λ¬Έμ œκ°€ λ°œμƒν•˜λŠ” μ½”λ“œμ˜ νƒ€μž…μ€ 3가지 μž…λ‹ˆλ‹€.

  1. λ‹€λ₯Έ ν΄λž˜μŠ€μ— μƒμ†ν•˜μ§€ μ•ŠλŠ” ν΄λž˜μŠ€μ—μ„œ κ²½κ³ κ°€ λ°œμƒ
  2. 상속을 ν•˜λŠ” 쀑이며 μƒμœ„ 클래슀의 ν•„λ“œλ₯Ό μžμ‹ 클래슀의 μƒμ„±μžμ—μ„œ set ν•¨μˆ˜λ₯Ό ν˜ΈμΆœν•˜μ—¬ μ΄ˆκΈ°ν™” 경우 (μƒμœ„ 클래슀 ν•„λ“œ μ΄ˆκΈ°ν™”)
  3. 상속을 ν•˜λŠ” 쀑이며 λ‹¨μˆœ ν•„λ“œ μ΄ˆκΈ°ν™”κ°€ μ•„λ‹Œ this μ°Έμ‘°ν•˜λŠ” 경우

ν˜„μž¬ ν•΄κ²°ν•œ λ°©μ•ˆ

1 의 κ²½μš°λŠ” λ‹€λ₯Έ ν΄λž˜μŠ€μ— μƒμ†ν•˜μ§€ μ•ŠκΈ° λ•Œλ¬Έμ— final class μ„ μ–ΈμœΌλ‘œ ν•΄κ²°ν•˜μ˜€μŠ΅λ‹ˆλ‹€. 2 의 κ²½μš°λŠ” μžμ‹ μƒμ„±μžμ—μ„œ λΆ€λͺ¨ 클래슀의 ν•„λ“œλ₯Ό μ΄ˆκΈ°ν™” ν•˜κΈ° μœ„ν•΄ protected λ₯Ό ν™œμš©ν•˜μ˜€μŠ΅λ‹ˆλ‹€. 3 의 κ²½μš°μ—λŠ” SuppressWarning() 을 ν™œμš©ν•˜μ˜€μŠ΅λ‹ˆλ‹€. https://github.com/jam2in/arcus-works/issues/568#issuecomment-2345538152

non-transient instance field of a serializable class declared with a non-serializable type

μœ„λŠ” 직렬화 κ°€λŠ₯ μ—¬λΆ€κ°€ λͺ…ν™•ν•˜μ§€ μ•Šμ•„ λ°œμƒν•˜λŠ” κ²½κ³  μž…λ‹ˆλ‹€.

CheckedOperationTimeoutException μ—μ„œλŠ” ν•΄λ‹Ή ν•„λ“œλ₯Ό 직렬화 ν•˜μ§€ μ•Šμ•„λ„ 잘 λ™μž‘ν•˜μ—¬ transient λ₯Ό ν™œμš©ν–ˆμŠ΅λ‹ˆλ‹€. (직렬화 λ¬΄μ‹œ) VariousTypeTest μ—μ„œλŠ” 직렬화 κ°€λŠ₯ν•œ λͺ…ν™•ν•œ νƒ€μž…μΈ ArrayList λ₯Ό ν™œμš©ν•˜μ˜€μŠ΅λ‹ˆλ‹€.

test λŠ” λͺ¨λ‘ 잘 λ™μž‘ν•©λ‹ˆλ‹€.