3434import java .lang .reflect .Modifier ;
3535import java .lang .reflect .Proxy ;
3636import java .nio .charset .StandardCharsets ;
37- import java .security .AccessControlContext ;
38- import java .security .AccessController ;
39- import java .security .PrivilegedAction ;
40- import java .security .PrivilegedActionException ;
41- import java .security .PrivilegedExceptionAction ;
4237import java .util .Arrays ;
43- import java .util .Map ;
4438import java .util .Objects ;
4539
4640import jdk .internal .access .JavaLangAccess ;
4943import jdk .internal .misc .Unsafe ;
5044import jdk .internal .util .ByteArray ;
5145import sun .reflect .misc .ReflectUtil ;
52- import sun .security .action .GetBooleanAction ;
53- import sun .security .action .GetIntegerAction ;
5446
5547/**
5648 * An ObjectInputStream deserializes primitive data and objects previously
@@ -278,26 +270,26 @@ protected Boolean computeValue(Class<?> type) {
278270 * have been read.
279271 * See {@link #setObjectInputFilter(ObjectInputFilter)}
280272 */
281- static final boolean SET_FILTER_AFTER_READ = GetBooleanAction
282- . privilegedGetProperty ("jdk.serialSetFilterAfterRead" );
273+ static final boolean SET_FILTER_AFTER_READ =
274+ Boolean . getBoolean ("jdk.serialSetFilterAfterRead" );
283275
284276 /**
285277 * Property to control {@link GetField#get(String, Object)} conversion of
286278 * {@link ClassNotFoundException} to {@code null}. If set to {@code true}
287279 * {@link GetField#get(String, Object)} returns null otherwise
288280 * throwing {@link ClassNotFoundException}.
289281 */
290- private static final boolean GETFIELD_CNFE_RETURNS_NULL = GetBooleanAction
291- . privilegedGetProperty ("jdk.serialGetFieldCnfeReturnsNull" );
282+ private static final boolean GETFIELD_CNFE_RETURNS_NULL =
283+ Boolean . getBoolean ("jdk.serialGetFieldCnfeReturnsNull" );
292284
293285 /**
294286 * Property to override the implementation limit on the number
295287 * of interfaces allowed for Proxies. The property value is clamped to 0..65535.
296288 * The maximum number of interfaces allowed for a proxy is limited to 65535 by
297289 * {@link java.lang.reflect.Proxy#newProxyInstance(ClassLoader, Class[], InvocationHandler)}.
298290 */
299- static final int PROXY_INTERFACE_LIMIT = Math . clamp ( GetIntegerAction
300- . privilegedGetProperty ("jdk.serialProxyInterfaceLimit" , 65535 ), 0 , 65535 );
291+ static final int PROXY_INTERFACE_LIMIT =
292+ Math . clamp ( Integer . getInteger ("jdk.serialProxyInterfaceLimit" , 65535 ), 0 , 65535 );
301293 }
302294
303295 /*
@@ -386,7 +378,6 @@ private static class Logging {
386378 */
387379 @ SuppressWarnings ("this-escape" )
388380 public ObjectInputStream (InputStream in ) throws IOException {
389- verifySubclass ();
390381 bin = new BlockDataInputStream (in );
391382 handles = new HandleTable (10 );
392383 vlist = new ValidationList ();
@@ -416,11 +407,6 @@ public ObjectInputStream(InputStream in) throws IOException {
416407 * fails due to invalid serial filter or serial filter factory properties.
417408 */
418409 protected ObjectInputStream () throws IOException {
419- @ SuppressWarnings ("removal" )
420- SecurityManager sm = System .getSecurityManager ();
421- if (sm != null ) {
422- sm .checkPermission (SUBCLASS_IMPLEMENTATION_PERMISSION );
423- }
424410 bin = null ;
425411 handles = null ;
426412 vlist = null ;
@@ -907,13 +893,6 @@ protected boolean enableResolveObject(boolean enable) {
907893 if (enable == enableResolve ) {
908894 return enable ;
909895 }
910- if (enable ) {
911- @ SuppressWarnings ("removal" )
912- SecurityManager sm = System .getSecurityManager ();
913- if (sm != null ) {
914- sm .checkPermission (SUBSTITUTION_PERMISSION );
915- }
916- }
917896 enableResolve = enable ;
918897 return !enableResolve ;
919898 }
@@ -1309,11 +1288,6 @@ public final ObjectInputFilter getObjectInputFilter() {
13091288 * @since 9
13101289 */
13111290 public final void setObjectInputFilter (ObjectInputFilter filter ) {
1312- @ SuppressWarnings ("removal" )
1313- SecurityManager sm = System .getSecurityManager ();
1314- if (sm != null ) {
1315- sm .checkPermission (ObjectStreamConstants .SERIAL_FILTER_PERMISSION );
1316- }
13171291 if (totalObjectRefs > 0 && !Caches .SET_FILTER_AFTER_READ ) {
13181292 throw new IllegalStateException (
13191293 "filter can not be set after an object has been read" );
@@ -1571,58 +1545,29 @@ public abstract boolean get(String name, boolean val)
15711545 public abstract Object get (String name , Object val ) throws IOException , ClassNotFoundException ;
15721546 }
15731547
1574- /**
1575- * Verifies that this (possibly subclass) instance can be constructed
1576- * without violating security constraints: the subclass must not override
1577- * security-sensitive non-final methods, or else the
1578- * "enableSubclassImplementation" SerializablePermission is checked.
1579- */
1580- private void verifySubclass () {
1581- Class <?> cl = getClass ();
1582- if (cl == ObjectInputStream .class ) {
1583- return ;
1584- }
1585- @ SuppressWarnings ("removal" )
1586- SecurityManager sm = System .getSecurityManager ();
1587- if (sm == null ) {
1588- return ;
1589- }
1590- boolean result = Caches .subclassAudits .get (cl );
1591- if (!result ) {
1592- sm .checkPermission (SUBCLASS_IMPLEMENTATION_PERMISSION );
1593- }
1594- }
1595-
15961548 /**
15971549 * Performs reflective checks on given subclass to verify that it doesn't
15981550 * override security-sensitive non-final methods. Returns TRUE if subclass
15991551 * is "safe", FALSE otherwise.
16001552 */
1601- @ SuppressWarnings ("removal" )
16021553 private static Boolean auditSubclass (Class <?> subcl ) {
1603- return AccessController .doPrivileged (
1604- new PrivilegedAction <Boolean >() {
1605- public Boolean run () {
1606- for (Class <?> cl = subcl ;
1607- cl != ObjectInputStream .class ;
1608- cl = cl .getSuperclass ())
1609- {
1610- try {
1611- cl .getDeclaredMethod (
1612- "readUnshared" , (Class []) null );
1613- return Boolean .FALSE ;
1614- } catch (NoSuchMethodException ex ) {
1615- }
1616- try {
1617- cl .getDeclaredMethod ("readFields" , (Class []) null );
1618- return Boolean .FALSE ;
1619- } catch (NoSuchMethodException ex ) {
1620- }
1621- }
1622- return Boolean .TRUE ;
1623- }
1554+ for (Class <?> cl = subcl ;
1555+ cl != ObjectInputStream .class ;
1556+ cl = cl .getSuperclass ())
1557+ {
1558+ try {
1559+ cl .getDeclaredMethod (
1560+ "readUnshared" , (Class []) null );
1561+ return Boolean .FALSE ;
1562+ } catch (NoSuchMethodException ex ) {
16241563 }
1625- );
1564+ try {
1565+ cl .getDeclaredMethod ("readFields" , (Class []) null );
1566+ return Boolean .FALSE ;
1567+ } catch (NoSuchMethodException ex ) {
1568+ }
1569+ }
1570+ return Boolean .TRUE ;
16261571 }
16271572
16281573 /**
@@ -2702,16 +2647,11 @@ private static class Callback {
27022647 final ObjectInputValidation obj ;
27032648 final int priority ;
27042649 Callback next ;
2705- @ SuppressWarnings ("removal" )
2706- final AccessControlContext acc ;
27072650
2708- Callback (ObjectInputValidation obj , int priority , Callback next ,
2709- @ SuppressWarnings ("removal" ) AccessControlContext acc )
2710- {
2651+ Callback (ObjectInputValidation obj , int priority , Callback next ) {
27112652 this .obj = obj ;
27122653 this .priority = priority ;
27132654 this .next = next ;
2714- this .acc = acc ;
27152655 }
27162656 }
27172657
@@ -2740,12 +2680,10 @@ void register(ObjectInputValidation obj, int priority)
27402680 prev = cur ;
27412681 cur = cur .next ;
27422682 }
2743- @ SuppressWarnings ("removal" )
2744- AccessControlContext acc = AccessController .getContext ();
27452683 if (prev != null ) {
2746- prev .next = new Callback (obj , priority , cur , acc );
2684+ prev .next = new Callback (obj , priority , cur );
27472685 } else {
2748- list = new Callback (obj , priority , list , acc );
2686+ list = new Callback (obj , priority , list );
27492687 }
27502688 }
27512689
@@ -2756,23 +2694,15 @@ void register(ObjectInputValidation obj, int priority)
27562694 * throws an InvalidObjectException, the callback process is terminated
27572695 * and the exception propagated upwards.
27582696 */
2759- @ SuppressWarnings ("removal" )
27602697 void doCallbacks () throws InvalidObjectException {
27612698 try {
27622699 while (list != null ) {
2763- AccessController .doPrivileged (
2764- new PrivilegedExceptionAction <Void >()
2765- {
2766- public Void run () throws InvalidObjectException {
2767- list .obj .validateObject ();
2768- return null ;
2769- }
2770- }, list .acc );
2700+ list .obj .validateObject ();
27712701 list = list .next ;
27722702 }
2773- } catch (PrivilegedActionException ex ) {
2703+ } catch (InvalidObjectException ex ) {
27742704 list = null ;
2775- throw ( InvalidObjectException ) ex . getException () ;
2705+ throw ex ;
27762706 }
27772707 }
27782708
0 commit comments