Skip to content

Fix argument validation in RedisData.setTimeToLive(Long, TimeUnit) - #3406

Closed
JuHyun419 wants to merge 1 commit into
spring-projects:mainfrom
JuHyun419:fix/redis-data-ttl-assert
Closed

Fix argument validation in RedisData.setTimeToLive(Long, TimeUnit)#3406
JuHyun419 wants to merge 1 commit into
spring-projects:mainfrom
JuHyun419:fix/redis-data-ttl-assert

Conversation

@JuHyun419

Copy link
Copy Markdown
Contributor

Summary

  • RedisData.setTimeToLive(Long, TimeUnit) had a copy/paste bug: the second Assert.notNull(...) call re-checked timeToLive instead of validating timeUnit.
  • As a result, passing a null TimeUnit skipped the intended fail-fast IllegalArgumentException and instead threw an unguarded NullPointerException from TimeUnit.SECONDS.convert(...).
  • Fixed the check to validate timeUnit as the message already stated.
  • Added RedisDataUnitTests covering: null TimeUnit (new behavior), null timeToLive (existing behavior), and the regular seconds-conversion path (regression guard).

Test plan

  • New unit tests in RedisDataUnitTests pass (./mvnw test -Dtest=RedisDataUnitTests)
  • ./mvnw compile / test-compile succeed

The second Assert.notNull call was checking timeToLive again instead of timeUnit, so passing a null TimeUnit fell through to an unguarded NullPointerException from TimeUnit.SECONDS.convert(...) instead of the intended IllegalArgumentException. Added RedisDataUnitTests covering the null TimeUnit case, the existing null TTL case, and the regular seconds conversion path.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01NCNaLYkirUWaphVdUZPvEa
Signed-off-by: juhyun <zzang9ha@naver.com>
@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label Jul 29, 2026
@mhalbritter mhalbritter self-assigned this Jul 30, 2026
@mhalbritter mhalbritter added type: bug A general bug and removed status: waiting-for-triage An issue we've not yet triaged labels Jul 30, 2026
mhalbritter added a commit that referenced this pull request Jul 30, 2026
mhalbritter pushed a commit that referenced this pull request Jul 30, 2026
Closes #3406

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Signed-off-by: juhyun <zzang9ha@naver.com>
mhalbritter added a commit that referenced this pull request Jul 30, 2026
mhalbritter pushed a commit that referenced this pull request Jul 30, 2026
Closes #3406

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Signed-off-by: juhyun <zzang9ha@naver.com>
mhalbritter added a commit that referenced this pull request Jul 30, 2026
@mhalbritter

Copy link
Copy Markdown
Contributor

Merged, polished and backported. Thanks @JuHyun419 !

@mhalbritter mhalbritter added this to the 4.0.7 (2025.1.7) milestone Jul 30, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

type: bug A general bug

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants