Skip to content

Commit 89876e2

Browse files
jxblummp911de
authored andcommitted
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.
1 parent a6f7416 commit 89876e2

File tree

3 files changed

+11
-13
lines changed

3 files changed

+11
-13
lines changed

src/main/java/org/springframework/data/redis/cache/RedisCacheConfiguration.java

+6-6
Original file line numberDiff line numberDiff line change
@@ -376,16 +376,16 @@ public SerializationPair<Object> getValueSerializationPair() {
376376
}
377377

378378
/**
379-
* Returns a computed {@link Duration TTL expiration timeout} based on cache entry key/value
380-
* if a {@link TtlFunction} was confiugred using {@link #entryTtl(TtlFunction)}.
379+
* Returns a computed {@link Duration TTL expiration timeout} based on cache entry key/value if a {@link TtlFunction}
380+
* was confiugred using {@link #entryTtl(TtlFunction)}.
381381
* <p>
382-
* Otherwise, returns the user-provided, fixed {@link Duration} if {@link #entryTtl(Duration)}
383-
* was called during cache configuration.
382+
* Otherwise, returns the user-provided, fixed {@link Duration} if {@link #entryTtl(Duration)} was called during cache
383+
* configuration.
384384
*
385385
* @return the configured {@link Duration TTL expiration}.
386-
* @deprecated since 3.2.0. Use {@link #getTtlFunction()} instead.
386+
* @deprecated since 3.2. Use {@link #getTtlFunction()} instead.
387387
*/
388-
@Deprecated(since = "3.2.0")
388+
@Deprecated(since = "3.2")
389389
public Duration getTtl() {
390390
return getTtlFunction().getTimeToLive(Object.class, null);
391391
}

src/main/java/org/springframework/data/redis/serializer/DefaultRedisElementReader.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ public T read(ByteBuffer buffer) {
4343
return (T) buffer;
4444
}
4545

46-
return serializer.deserialize(ByteUtils.extractBytes(buffer));
46+
return serializer.deserialize(ByteUtils.getBytes(buffer));
4747
}
4848

4949
}

src/main/java/org/springframework/data/redis/util/ByteUtils.java

+4-6
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
* @author Christoph Strobl
3232
* @author Mark Paluch
3333
* @author Guy Korland
34+
* @author John Blum
3435
* @since 1.7
3536
*/
3637
public final class ByteUtils {
@@ -251,13 +252,10 @@ public static ByteBuffer getByteBuffer(String theString, Charset charset) {
251252
* @param buffer must not be {@literal null}.
252253
* @return the extracted bytes.
253254
* @since 2.1
255+
* @deprecated Since 3.2. Use {@link #getBytes(ByteBuffer)} instead.
254256
*/
257+
@Deprecated(since = "3.2")
255258
public static byte[] extractBytes(ByteBuffer buffer) {
256-
257-
ByteBuffer duplicate = buffer.duplicate();
258-
byte[] bytes = new byte[duplicate.remaining()];
259-
duplicate.get(bytes);
260-
261-
return bytes;
259+
return getBytes(buffer);
262260
}
263261
}

0 commit comments

Comments
 (0)