Skip to content

Commit 4f4aa83

Browse files
committed
Document safer deserialization option in Javadoc for SerializationUtils
1 parent bd40b45 commit 4f4aa83

File tree

3 files changed

+49
-7
lines changed

3 files changed

+49
-7
lines changed

pom.xml

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,7 @@
174174
<!-- Local macOS Java 21 says 0.92 -->
175175
<commons.jacoco.complexityRatio>0.91</commons.jacoco.complexityRatio>
176176
<commons.text.version>1.15.0</commons.text.version>
177+
<commons.io.version>2.21.0</commons.io.version>
177178
</properties>
178179
<build>
179180
<defaultGoal>clean verify apache-rat:check checkstyle:check japicmp:cmp spotbugs:check pmd:check javadoc:javadoc</defaultGoal>
@@ -231,7 +232,17 @@
231232
<artifactId>commons-text</artifactId>
232233
<version>${commons.text.version}</version>
233234
</additionalDependency>
235+
<additionalDependency>
236+
<groupId>commons-io</groupId>
237+
<artifactId>commons-io</artifactId>
238+
<version>${commons.io.version}</version>
239+
</additionalDependency>
234240
</additionalDependencies>
241+
<links>
242+
<link>https://commons.apache.org/proper/commons-io/apidocs</link>
243+
<link>https://commons.apache.org/proper/commons-text/apidocs</link>
244+
<link>${commons.javadoc.javaee.link}</link>
245+
</links>
235246
</configuration>
236247
<executions>
237248
<execution>
@@ -324,7 +335,20 @@
324335
<source>${maven.compiler.source}</source>
325336
<quiet>true</quiet>
326337
<notimestamp>true</notimestamp>
338+
<additionalDependencies>
339+
<additionalDependency>
340+
<groupId>org.apache.commons</groupId>
341+
<artifactId>commons-text</artifactId>
342+
<version>${commons.text.version}</version>
343+
</additionalDependency>
344+
<additionalDependency>
345+
<groupId>commons-io</groupId>
346+
<artifactId>commons-io</artifactId>
347+
<version>${commons.io.version}</version>
348+
</additionalDependency>
349+
</additionalDependencies>
327350
<links>
351+
<link>https://commons.apache.org/proper/commons-io/apidocs</link>
328352
<link>https://commons.apache.org/proper/commons-text/apidocs</link>
329353
<link>${commons.javadoc.javaee.link}</link>
330354
</links>

src/changes/changes.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ The <action> type attribute can be add,update,fix,remove.
7676
<action issue="LANG-1802" type="fix" dev="ggregory" due-to="Gary Gregory, IcoreE">Fix collision in CharRange.hashCode().</action>
7777
<action type="fix" dev="ggregory" due-to="Gary Gregory">Fix race condition in Fraction.hashCode().</action>
7878
<action type="fix" dev="ggregory" due-to="Gary Gregory">Fix race condition in Range.hashCode().</action>
79+
<action type="fix" dev="ggregory" due-to="Gary Gregory, Akshat_Agg">Document safer deserialization option in Javadoc for SerializationUtils.</action>
7980
<!-- ADD -->
8081
<!-- UPDATE -->
8182
<action type="update" dev="ggregory" due-to="Gary Gregory, Dependabot">Bump org.apache.commons:commons-parent from 92 to 93 #1498.</action>

src/main/java/org/apache/commons/lang3/SerializationUtils.java

Lines changed: 24 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -28,19 +28,26 @@
2828
import java.util.Objects;
2929

3030
/**
31-
* Assists with the serialization process and performs additional functionality based
32-
* on serialization.
31+
* Performs additional functionality for serialization.
3332
*
3433
* <ul>
3534
* <li>Deep clone using serialization</li>
3635
* <li>Serialize managing finally and IOException</li>
3736
* <li>Deserialize managing finally and IOException</li>
3837
* </ul>
3938
*
40-
* <p>This class throws exceptions for invalid {@code null} inputs.
41-
* Each method documents its behavior in more detail.</p>
39+
* <p>
40+
* This class throws exceptions for invalid {@code null} inputs. Each method documents its behavior in more detail.
41+
* </p>
42+
* <p>
43+
* If you want to secure deserialization with a whitelist or blacklist, please use Apache Commons IO's
44+
* {@link org.apache.commons.io.serialization.ValidatingObjectInputStream ValidatingObjectInputStream}.
45+
* </p>
46+
* <p>
47+
* #ThreadSafe#
48+
* </p>
4249
*
43-
* <p>#ThreadSafe#</p>
50+
* @see org.apache.commons.io.serialization.ValidatingObjectInputStream
4451
* @since 1.0
4552
*/
4653
public class SerializationUtils {
@@ -140,13 +147,18 @@ public static <T extends Serializable> T clone(final T object) {
140147
* Without Generics in this declaration, the call site must type cast and can cause the same ClassCastException.
141148
* Note that in both cases, the ClassCastException is in the call site, not in this method.
142149
* </p>
150+
* <p>
151+
* If you want to secure deserialization with a whitelist or blacklist, please use Apache Commons IO's
152+
* {@link org.apache.commons.io.serialization.ValidatingObjectInputStream ValidatingObjectInputStream}.
153+
* </p>
143154
*
144155
* @param <T> the object type to be deserialized.
145156
* @param objectData
146157
* the serialized object, must not be null.
147158
* @return the deserialized object.
148159
* @throws NullPointerException if {@code objectData} is {@code null}.
149160
* @throws SerializationException (runtime) if the serialization fails.
161+
* @see org.apache.commons.io.serialization.ValidatingObjectInputStream
150162
*/
151163
public static <T> T deserialize(final byte[] objectData) {
152164
Objects.requireNonNull(objectData, "objectData");
@@ -172,12 +184,17 @@ public static <T> T deserialize(final byte[] objectData) {
172184
* Note that in both cases, the ClassCastException is in the call site, not in this method.
173185
* </p>
174186
*
187+
* <p>
188+
* If you want to secure deserialization with a whitelist or blacklist, please use Apache Commons IO's
189+
* {@link org.apache.commons.io.serialization.ValidatingObjectInputStream ValidatingObjectInputStream}.
190+
* </p>
191+
*
175192
* @param <T> the object type to be deserialized.
176-
* @param inputStream
177-
* the serialized object input stream, must not be null.
193+
* @param inputStream the serialized object input stream, must not be null.
178194
* @return the deserialized object.
179195
* @throws NullPointerException if {@code inputStream} is {@code null}.
180196
* @throws SerializationException (runtime) if the serialization fails.
197+
* @see org.apache.commons.io.serialization.ValidatingObjectInputStream
181198
*/
182199
@SuppressWarnings("resource") // inputStream is managed by the caller
183200
public static <T> T deserialize(final InputStream inputStream) {

0 commit comments

Comments
 (0)