Skip to content

Commit

Permalink
Deprecate redundant ByteUtils.extractBytes(…) method.
Browse files Browse the repository at this point in the history
Refactors extractBytes(:ByteBuffer) to call getBytes(:ByteBuffer), thereby avoid the NullPointerException by throwing the more appropriate IllegalArgumentException with a descriptive message instead.

See spring-projects#2733
  • Loading branch information
jxblum committed Oct 12, 2023
1 parent 747a7d0 commit 9bae67e
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -376,16 +376,16 @@ public SerializationPair<Object> getValueSerializationPair() {
}

/**
* 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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public T read(ByteBuffer buffer) {
return (T) buffer;
}

return serializer.deserialize(ByteUtils.extractBytes(buffer));
return serializer.deserialize(ByteUtils.getBytes(buffer));
}

}
10 changes: 4 additions & 6 deletions src/main/java/org/springframework/data/redis/util/ByteUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
* @author Christoph Strobl
* @author Mark Paluch
* @author Guy Korland
* @author John Blum
* @since 1.7
*/
public final class ByteUtils {
Expand Down Expand Up @@ -251,13 +252,10 @@ public static ByteBuffer getByteBuffer(String theString, Charset charset) {
* @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);
}
}

0 comments on commit 9bae67e

Please sign in to comment.