shashank created CAMEL-25165:
--------------------------------

             Summary: camel-spring-redis - 
SpringRedisIdempotentRepository.remove() returns true also when the key was not 
in the repository
                 Key: CAMEL-25165
                 URL: https://issues.apache.org/jira/browse/CAMEL-25165
             Project: Camel
          Issue Type: Bug
          Components: camel-spring-redis
            Reporter: shashank


{{SpringRedisIdempotentRepository.remove}} returns the result of {{SREM}} 
compared with {{null}}:

{code:java}
return setOperations.remove(repositoryName, key) != null;
{code}

{{SREM}} returns the number of members it removed, which is 0 when the key was 
not in the set. So {{remove}} returns {{true}} for any key. 
{{IdempotentRepository.remove}} documents the return value as "true if the key 
was removed".

This is the same pattern as the {{SADD}} result in {{add}} (CAMEL-25155). Claus 
Ibsen suggested fixing {{remove}} as well in the review of apache/camel#27110.

The Idempotent Consumer EIP and the file consumers call {{remove}} on failure 
and do not use the returned value, so the EIP is not affected. The value is 
seen by code that calls the repository directly, and by the JMX operation 
{{remove}}.

h3. Proposed fix

Return {{true}} only when {{SREM}} removed the key ({{removed != null && 
removed > 0}}), as the CAMEL-25155 fix does for {{add}}. Inside a pipeline or a 
transaction Spring Data Redis returns {{null}}, and {{remove}} returns 
{{false}} there as before.

Tests: {{SpringRedisIdempotentRepositoryTest}} (mocked {{SetOperations}}): 
{{SREM}} returns 1 gives {{true}}, 0 gives {{false}}, {{null}} gives {{false}}. 
The 0 case fails without the fix ({{expected: <false> but was: <true>}}).

The upgrade guide gets a short note, as the return value changes for a missing 
key.

_Filed with Claude Code on behalf of allthingssecurity._




--
This message was sent by Atlassian Jira
(v8.20.10#820010)

Reply via email to