34
34
import java .lang .reflect .Modifier ;
35
35
import java .lang .reflect .Proxy ;
36
36
import 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 ;
42
37
import java .util .Arrays ;
43
- import java .util .Map ;
44
38
import java .util .Objects ;
45
39
46
40
import jdk .internal .access .JavaLangAccess ;
49
43
import jdk .internal .misc .Unsafe ;
50
44
import jdk .internal .util .ByteArray ;
51
45
import sun .reflect .misc .ReflectUtil ;
52
- import sun .security .action .GetBooleanAction ;
53
- import sun .security .action .GetIntegerAction ;
54
46
55
47
/**
56
48
* An ObjectInputStream deserializes primitive data and objects previously
@@ -278,26 +270,26 @@ protected Boolean computeValue(Class<?> type) {
278
270
* have been read.
279
271
* See {@link #setObjectInputFilter(ObjectInputFilter)}
280
272
*/
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" );
283
275
284
276
/**
285
277
* Property to control {@link GetField#get(String, Object)} conversion of
286
278
* {@link ClassNotFoundException} to {@code null}. If set to {@code true}
287
279
* {@link GetField#get(String, Object)} returns null otherwise
288
280
* throwing {@link ClassNotFoundException}.
289
281
*/
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" );
292
284
293
285
/**
294
286
* Property to override the implementation limit on the number
295
287
* of interfaces allowed for Proxies. The property value is clamped to 0..65535.
296
288
* The maximum number of interfaces allowed for a proxy is limited to 65535 by
297
289
* {@link java.lang.reflect.Proxy#newProxyInstance(ClassLoader, Class[], InvocationHandler)}.
298
290
*/
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 );
301
293
}
302
294
303
295
/*
@@ -386,7 +378,6 @@ private static class Logging {
386
378
*/
387
379
@ SuppressWarnings ("this-escape" )
388
380
public ObjectInputStream (InputStream in ) throws IOException {
389
- verifySubclass ();
390
381
bin = new BlockDataInputStream (in );
391
382
handles = new HandleTable (10 );
392
383
vlist = new ValidationList ();
@@ -416,11 +407,6 @@ public ObjectInputStream(InputStream in) throws IOException {
416
407
* fails due to invalid serial filter or serial filter factory properties.
417
408
*/
418
409
protected ObjectInputStream () throws IOException {
419
- @ SuppressWarnings ("removal" )
420
- SecurityManager sm = System .getSecurityManager ();
421
- if (sm != null ) {
422
- sm .checkPermission (SUBCLASS_IMPLEMENTATION_PERMISSION );
423
- }
424
410
bin = null ;
425
411
handles = null ;
426
412
vlist = null ;
@@ -907,13 +893,6 @@ protected boolean enableResolveObject(boolean enable) {
907
893
if (enable == enableResolve ) {
908
894
return enable ;
909
895
}
910
- if (enable ) {
911
- @ SuppressWarnings ("removal" )
912
- SecurityManager sm = System .getSecurityManager ();
913
- if (sm != null ) {
914
- sm .checkPermission (SUBSTITUTION_PERMISSION );
915
- }
916
- }
917
896
enableResolve = enable ;
918
897
return !enableResolve ;
919
898
}
@@ -1309,11 +1288,6 @@ public final ObjectInputFilter getObjectInputFilter() {
1309
1288
* @since 9
1310
1289
*/
1311
1290
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
- }
1317
1291
if (totalObjectRefs > 0 && !Caches .SET_FILTER_AFTER_READ ) {
1318
1292
throw new IllegalStateException (
1319
1293
"filter can not be set after an object has been read" );
@@ -1571,58 +1545,29 @@ public abstract boolean get(String name, boolean val)
1571
1545
public abstract Object get (String name , Object val ) throws IOException , ClassNotFoundException ;
1572
1546
}
1573
1547
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
-
1596
1548
/**
1597
1549
* Performs reflective checks on given subclass to verify that it doesn't
1598
1550
* override security-sensitive non-final methods. Returns TRUE if subclass
1599
1551
* is "safe", FALSE otherwise.
1600
1552
*/
1601
- @ SuppressWarnings ("removal" )
1602
1553
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 ) {
1624
1563
}
1625
- );
1564
+ try {
1565
+ cl .getDeclaredMethod ("readFields" , (Class []) null );
1566
+ return Boolean .FALSE ;
1567
+ } catch (NoSuchMethodException ex ) {
1568
+ }
1569
+ }
1570
+ return Boolean .TRUE ;
1626
1571
}
1627
1572
1628
1573
/**
@@ -2702,16 +2647,11 @@ private static class Callback {
2702
2647
final ObjectInputValidation obj ;
2703
2648
final int priority ;
2704
2649
Callback next ;
2705
- @ SuppressWarnings ("removal" )
2706
- final AccessControlContext acc ;
2707
2650
2708
- Callback (ObjectInputValidation obj , int priority , Callback next ,
2709
- @ SuppressWarnings ("removal" ) AccessControlContext acc )
2710
- {
2651
+ Callback (ObjectInputValidation obj , int priority , Callback next ) {
2711
2652
this .obj = obj ;
2712
2653
this .priority = priority ;
2713
2654
this .next = next ;
2714
- this .acc = acc ;
2715
2655
}
2716
2656
}
2717
2657
@@ -2740,12 +2680,10 @@ void register(ObjectInputValidation obj, int priority)
2740
2680
prev = cur ;
2741
2681
cur = cur .next ;
2742
2682
}
2743
- @ SuppressWarnings ("removal" )
2744
- AccessControlContext acc = AccessController .getContext ();
2745
2683
if (prev != null ) {
2746
- prev .next = new Callback (obj , priority , cur , acc );
2684
+ prev .next = new Callback (obj , priority , cur );
2747
2685
} else {
2748
- list = new Callback (obj , priority , list , acc );
2686
+ list = new Callback (obj , priority , list );
2749
2687
}
2750
2688
}
2751
2689
@@ -2756,23 +2694,15 @@ void register(ObjectInputValidation obj, int priority)
2756
2694
* throws an InvalidObjectException, the callback process is terminated
2757
2695
* and the exception propagated upwards.
2758
2696
*/
2759
- @ SuppressWarnings ("removal" )
2760
2697
void doCallbacks () throws InvalidObjectException {
2761
2698
try {
2762
2699
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 ();
2771
2701
list = list .next ;
2772
2702
}
2773
- } catch (PrivilegedActionException ex ) {
2703
+ } catch (InvalidObjectException ex ) {
2774
2704
list = null ;
2775
- throw ( InvalidObjectException ) ex . getException () ;
2705
+ throw ex ;
2776
2706
}
2777
2707
}
2778
2708
0 commit comments