diff options
author | Roger Riggs <rriggs@openjdk.org> | 2023-02-08 22:09:22 +0000 |
---|---|---|
committer | Roger Riggs <rriggs@openjdk.org> | 2023-02-08 22:09:22 +0000 |
commit | 6f460e4885b274f01c9097f41a65c637654858ce (patch) | |
tree | bb237eeba724a1b761a20f7bb2172e28229e8d67 | |
parent | 1330d4eaa54790b468f69e61574b3c5d522be120 (diff) | |
download | libcore-6f460e4885b274f01c9097f41a65c637654858ce.tar.gz |
8301863: ObjectInputFilter example incorrectly calls rejectUndecidedClassjdk21u/jdk-20+35jdk/jdk-20+35
Reviewed-by: lancea
-rw-r--r-- | src/java.base/share/classes/java/io/ObjectInputFilter.java | 27 |
1 files changed, 11 insertions, 16 deletions
diff --git a/src/java.base/share/classes/java/io/ObjectInputFilter.java b/src/java.base/share/classes/java/io/ObjectInputFilter.java index ab16c8cf1a3..e40a2407206 100644 --- a/src/java.base/share/classes/java/io/ObjectInputFilter.java +++ b/src/java.base/share/classes/java/io/ObjectInputFilter.java @@ -187,8 +187,11 @@ import static java.lang.System.Logger.Level.ERROR; * * This class shows how an application provided filter factory can combine filters * to check every deserialization operation that takes place in a thread. - * It defines a thread-local variable to hold the thread-specific filter, and constructs a filter factory - * that composes that filter with the static JVM-wide filter and the stream-specific filter. + * It defines a thread-local variable to hold the thread-specific filter, and construct a filter factory + * that composes that filter with the static JVM-wide filter and the stream-specific filter, + * rejecting any classes not handled by those two filters. + * If a stream specific filter is set and does not accept or reject a class, + * the combined JVM-wide filter and thread filter is applied. * The {@code doWithSerialFilter} method does the setup of the thread-specific filter * and invokes the application provided {@link Runnable Runnable}. * @@ -207,26 +210,18 @@ import static java.lang.System.Logger.Level.ERROR; * // Called from the OIS constructor or perhaps OIS.setObjectInputFilter with no current filter * var filter = filterThreadLocal.get(); * if (filter != null) { - * // Wrap the filter to reject UNDECIDED results - * filter = ObjectInputFilter.rejectUndecidedClass(filter); + * // Merge to invoke the thread local filter and then the JVM-wide filter (if any) + * filter = ObjectInputFilter.merge(filter, next); + * return ObjectInputFilter.rejectUndecidedClass(filter); * } - * if (next != null) { - * // Merge the next filter with the thread filter, if any - * // Initially this is the static JVM-wide filter passed from the OIS constructor - * // Wrap the filter to reject UNDECIDED results - * filter = ObjectInputFilter.merge(next, filter); - * filter = ObjectInputFilter.rejectUndecidedClass(filter); - * } - * return filter; + * return (next == null) ? null : ObjectInputFilter.rejectUndecidedClass(next); * } else { * // Called from OIS.setObjectInputFilter with a current filter and a stream-specific filter. * // The curr filter already incorporates the thread filter and static JVM-wide filter * // and rejection of undecided classes - * // If there is a stream-specific filter wrap it and a filter to recheck for undecided + * // If there is a stream-specific filter merge to invoke it and then the current filter. * if (next != null) { - * next = ObjectInputFilter.merge(next, curr); - * next = ObjectInputFilter.rejectUndecidedClass(next); - * return next; + * return ObjectInputFilter.merge(next, curr); * } * return curr; * } |