Deprecate redundant ByteUtils.extractBytes(…) method.

Refactors extractBytes(:ByteBuffer) to call getBytes(:ByteBuffer), thereby avoid the NullPointerException by throwing the more appropriate IllegalArgumentException with a descriptive message instead.

See #2733
This commit is contained in:
John Blum
2023-09-22 17:23:56 -07:00
parent 747a7d03ee
commit 9bae67eae2
3 changed files with 11 additions and 13 deletions

View File

@@ -376,16 +376,16 @@ public class RedisCacheConfiguration {
}
/**
* Returns a computed {@link Duration TTL expiration timeout} based on cache entry key/value
* if a {@link TtlFunction} was confiugred using {@link #entryTtl(TtlFunction)}.
* Returns a computed {@link Duration TTL expiration timeout} based on cache entry key/value if a {@link TtlFunction}
* was confiugred using {@link #entryTtl(TtlFunction)}.
* <p>
* Otherwise, returns the user-provided, fixed {@link Duration} if {@link #entryTtl(Duration)}
* was called during cache configuration.
* Otherwise, returns the user-provided, fixed {@link Duration} if {@link #entryTtl(Duration)} was called during cache
* configuration.
*
* @return the configured {@link Duration TTL expiration}.
* @deprecated since 3.2.0. Use {@link #getTtlFunction()} instead.
* @deprecated since 3.2. Use {@link #getTtlFunction()} instead.
*/
@Deprecated(since = "3.2.0")
@Deprecated(since = "3.2")
public Duration getTtl() {
return getTtlFunction().getTimeToLive(Object.class, null);
}

View File

@@ -43,7 +43,7 @@ class DefaultRedisElementReader<T> implements RedisElementReader<T> {
return (T) buffer;
}
return serializer.deserialize(ByteUtils.extractBytes(buffer));
return serializer.deserialize(ByteUtils.getBytes(buffer));
}
}

View File

@@ -31,6 +31,7 @@ import org.springframework.util.ObjectUtils;
* @author Christoph Strobl
* @author Mark Paluch
* @author Guy Korland
* @author John Blum
* @since 1.7
*/
public final class ByteUtils {
@@ -251,13 +252,10 @@ public final class ByteUtils {
* @param buffer must not be {@literal null}.
* @return the extracted bytes.
* @since 2.1
* @deprecated Since 3.2. Use {@link #getBytes(ByteBuffer)} instead.
*/
@Deprecated(since = "3.2")
public static byte[] extractBytes(ByteBuffer buffer) {
ByteBuffer duplicate = buffer.duplicate();
byte[] bytes = new byte[duplicate.remaining()];
duplicate.get(bytes);
return bytes;
return getBytes(buffer);
}
}