|
1 | 1 | /*
|
2 |
| - * Copyright (c) 2016, 2021, Oracle and/or its affiliates. All rights reserved. |
| 2 | + * Copyright (c) 2016, 2022, Oracle and/or its affiliates. All rights reserved. |
3 | 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
4 | 4 | *
|
5 | 5 | * This code is free software; you can redistribute it and/or modify it
|
|
80 | 80 | *
|
81 | 81 | * <p>For example, a filter that allows example classes, allows classes in the
|
82 | 82 | * {@code java.base} module, and rejects all other classes can be set:
|
83 |
| - * |
84 |
| - * <pre>{@code As a command line property: |
85 |
| - * % java -Djdk.serialFilter="example.*;java.base/*;!*" ...}</pre> |
86 |
| - * |
87 |
| - * <pre>{@code Or programmatically: |
| 83 | + * As a command line property: |
| 84 | + * {@snippet : |
| 85 | + * % java -Djdk.serialFilter="example.*;java.base/*;!*" ... |
| 86 | + * } |
| 87 | + * Or programmatically: |
| 88 | + * {@snippet lang="java": |
88 | 89 | * var filter = ObjectInputFilter.Config.createFilter("example.*;java.base/*;!*")
|
89 |
| - * ObjectInputFilter.Config.setSerialFilter(filter);}</pre> |
90 |
| - * |
| 90 | + * ObjectInputFilter.Config.setSerialFilter(filter); |
| 91 | + * } |
91 | 92 | * <p>In an application with multiple execution contexts, the application can provide a
|
92 | 93 | * {@linkplain Config#setSerialFilterFactory(BinaryOperator) filter factory} to
|
93 | 94 | * protect individual contexts by providing a custom filter for each. When the stream
|
|
191 | 192 | * The {@code doWithSerialFilter} method does the setup of the thread-specific filter
|
192 | 193 | * and invokes the application provided {@link Runnable Runnable}.
|
193 | 194 | *
|
194 |
| - * <pre>{@code |
| 195 | + * {@snippet lang="java": |
195 | 196 | * public static final class FilterInThread implements BinaryOperator<ObjectInputFilter> {
|
196 | 197 | *
|
197 | 198 | * private final ThreadLocal<ObjectInputFilter> filterThreadLocal = new ThreadLocal<>();
|
|
242 | 243 | * }
|
243 | 244 | * }
|
244 | 245 | * }
|
245 |
| - * }</pre> |
| 246 | + * } |
246 | 247 | * <h3>Using the Filter Factory</h3>
|
247 | 248 | * To use {@code FilterInThread} utility create an instance and configure it as the
|
248 | 249 | * JVM-wide filter factory. The {@code doWithSerialFilter} method is invoked with a
|
249 | 250 | * filter allowing the example application and core classes:
|
250 |
| - * <pre>{@code |
| 251 | + * {@snippet lang="java": |
251 | 252 | * // Create a FilterInThread filter factory and set
|
252 | 253 | * var filterInThread = new FilterInThread();
|
253 | 254 | * ObjectInputFilter.Config.setSerialFilterFactory(filterInThread);
|
|
258 | 259 | * byte[] bytes = ...;
|
259 | 260 | * var o = deserializeObject(bytes);
|
260 | 261 | * });
|
261 |
| - * }</pre> |
| 262 | + * } |
262 | 263 | * <p>
|
263 | 264 | * Unless otherwise noted, passing a {@code null} argument to a
|
264 | 265 | * method in this interface and its nested classes will cause a
|
@@ -310,11 +311,11 @@ public interface ObjectInputFilter {
|
310 | 311 | * <p>
|
311 | 312 | * Example, to create a filter that will allow any class loaded from the platform
|
312 | 313 | * or bootstrap classloaders.
|
313 |
| - * <pre><code> |
| 314 | + * {@snippet lang="java": |
314 | 315 | * ObjectInputFilter f
|
315 | 316 | * = allowFilter(cl -> cl.getClassLoader() == ClassLoader.getPlatformClassLoader() ||
|
316 | 317 | * cl.getClassLoader() == null, Status.UNDECIDED);
|
317 |
| - * </code></pre> |
| 318 | + * } |
318 | 319 | *
|
319 | 320 | * @param predicate a predicate to test a non-null Class
|
320 | 321 | * @param otherStatus a Status to use if the predicate is {@code false}
|
@@ -344,10 +345,10 @@ static ObjectInputFilter allowFilter(Predicate<Class<?>> predicate, Status other
|
344 | 345 | * </ul>
|
345 | 346 | * <p>
|
346 | 347 | * Example, to create a filter that will reject any class loaded from the application classloader.
|
347 |
| - * <pre><code> |
| 348 | + * {@snippet lang="java": |
348 | 349 | * ObjectInputFilter f = rejectFilter(cl ->
|
349 | 350 | * cl.getClassLoader() == ClassLoader.ClassLoader.getSystemClassLoader(), Status.UNDECIDED);
|
350 |
| - * </code></pre> |
| 351 | + * } |
351 | 352 | *
|
352 | 353 | * @param predicate a predicate to test a non-null Class
|
353 | 354 | * @param otherStatus a Status to use if the predicate is {@code false}
|
|
0 commit comments