Skip to content

Commit c8d0146

Browse files
committed
Polish contribution
See gh-28075
1 parent 7f7fb58 commit c8d0146

File tree

3 files changed

+32
-17
lines changed

3 files changed

+32
-17
lines changed

spring-context-support/src/main/java/org/springframework/cache/jcache/interceptor/CacheResultInterceptor.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2018 the original author or authors.
2+
* Copyright 2002-2022 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.

spring-core/src/main/java/org/springframework/util/SerializationUtils.java

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2019 the original author or authors.
2+
* Copyright 2002-2022 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -26,9 +26,17 @@
2626
import org.springframework.lang.Nullable;
2727

2828
/**
29-
* Static utilities for serialization and deserialization.
29+
* Static utilities for serialization and deserialization using
30+
* <a href="https://docs.oracle.com/en/java/javase/17/docs/specs/serialization/"
31+
* target="_blank">Java Object Serialization</a>.
32+
*
33+
* <p>These utilities should be used with caution. See
34+
* <a href="https://www.oracle.com/java/technologies/javase/seccodeguide.html#8"
35+
* target="_blank">Secure Coding Guidelines for the Java Programming Language</a>
36+
* for details.
3037
*
3138
* @author Dave Syer
39+
* @author Loïc Ledoyen
3240
* @since 3.0.5
3341
*/
3442
public abstract class SerializationUtils {
@@ -58,13 +66,14 @@ public static byte[] serialize(@Nullable Object object) {
5866
* Deserialize the byte array into an object.
5967
* @param bytes a serialized object
6068
* @return the result of deserializing the bytes
61-
* @deprecated This utility uses Java's reflection, which allows arbitrary code to be
62-
* run and is known for being the source of many Remote Code Execution vulnerabilities.
63-
* <p>Prefer the use of an external tool (that serializes to JSON, XML or any other format)
64-
* which is regularly checked and updated for not allowing RCE.
69+
* @deprecated This utility uses Java Object Serialization, which allows
70+
* arbitrary code to be run and is known for being the source of many Remote
71+
* Code Execution (RCE) vulnerabilities.
72+
* <p>Prefer the use of an external tool (that serializes to JSON, XML, or
73+
* any other format) which is regularly checked and updated for not allowing RCE.
6574
*/
66-
@Nullable
6775
@Deprecated
76+
@Nullable
6877
public static Object deserialize(@Nullable byte[] bytes) {
6978
if (bytes == null) {
7079
return null;
@@ -81,14 +90,15 @@ public static Object deserialize(@Nullable byte[] bytes) {
8190
}
8291

8392
/**
84-
* Clone the given object using Java's serialization.
93+
* Clone the given object using Java Object Serialization.
8594
* @param object the object to clone
8695
* @param <T> the type of the object to clone
8796
* @return a clone (deep-copy) of the given object
88-
* @since 6.0.0
97+
* @since 6.0
8998
*/
9099
@SuppressWarnings("unchecked")
91100
public static <T extends Serializable> T clone(T object) {
92101
return (T) SerializationUtils.deserialize(SerializationUtils.serialize(object));
93102
}
103+
94104
}

spring-core/src/test/java/org/springframework/util/SerializationUtilsTests.java

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2019 the original author or authors.
2+
* Copyright 2002-2022 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -38,32 +38,36 @@ class SerializationUtilsTests {
3838

3939

4040
@Test
41-
void serializeCycleSunnyDay() throws Exception {
41+
@SuppressWarnings("deprecation")
42+
void serializeCycleSunnyDay() {
4243
assertThat(SerializationUtils.deserialize(SerializationUtils.serialize("foo"))).isEqualTo("foo");
4344
}
4445

4546
@Test
46-
void deserializeUndefined() throws Exception {
47+
@SuppressWarnings("deprecation")
48+
void deserializeUndefined() {
4749
assertThatIllegalStateException().isThrownBy(() -> SerializationUtils.deserialize(FOO.toByteArray()));
4850
}
4951

5052
@Test
51-
void serializeNonSerializable() throws Exception {
53+
void serializeNonSerializable() {
5254
assertThatIllegalArgumentException().isThrownBy(() -> SerializationUtils.serialize(new Object()));
5355
}
5456

5557
@Test
56-
void deserializeNonSerializable() throws Exception {
58+
@SuppressWarnings("deprecation")
59+
void deserializeNonSerializable() {
5760
assertThatIllegalArgumentException().isThrownBy(() -> SerializationUtils.deserialize("foo".getBytes()));
5861
}
5962

6063
@Test
61-
void serializeNull() throws Exception {
64+
void serializeNull() {
6265
assertThat(SerializationUtils.serialize(null)).isNull();
6366
}
6467

6568
@Test
66-
void deserializeNull() throws Exception {
69+
@SuppressWarnings("deprecation")
70+
void deserializeNull() {
6771
assertThat(SerializationUtils.deserialize(null)).isNull();
6872
}
6973

@@ -72,4 +76,5 @@ void cloneException() {
7276
IllegalArgumentException ex = new IllegalArgumentException("foo");
7377
assertThat(SerializationUtils.clone(ex)).hasMessage("foo").isNotSameAs(ex);
7478
}
79+
7580
}

0 commit comments

Comments
 (0)