23
23
package java .lang ;
24
24
25
25
import java .io .InputStream ;
26
- import java .security .AccessControlContext ;
27
- import java .security .ProtectionDomain ;
28
- import java .security .Permissions ;
29
26
/*[IF JAVA_SPEC_VERSION >= 12]*/
30
27
import java .lang .constant .ClassDesc ;
31
28
/*[ENDIF] JAVA_SPEC_VERSION >= 12*/
35
32
import java .lang .reflect .*;
36
33
import java .net .URL ;
37
34
import java .lang .annotation .*;
35
+ /*[IF JAVA_SPEC_VERSION < 24]*/
36
+ import java .security .AccessControlContext ;
37
+ import java .security .AccessController ;
38
+ import java .security .PrivilegedAction ;
39
+ import java .security .PrivilegedActionException ;
40
+ import java .security .PrivilegedExceptionAction ;
41
+ /*[ENDIF] JAVA_SPEC_VERSION < 24 */
42
+ import java .security .Permissions ;
43
+ import java .security .ProtectionDomain ;
38
44
import java .util .Collection ;
39
45
import java .util .HashMap ;
40
46
/*[IF JAVA_SPEC_VERSION >= 16]*/
49
55
/*[ENDIF] JAVA_SPEC_VERSION >= 12 */
50
56
import java .util .concurrent .ConcurrentHashMap ;
51
57
import java .util .concurrent .atomic .AtomicInteger ;
52
- import java .security .AccessController ;
53
- import java .security .PrivilegedExceptionAction ;
54
- import java .security .PrivilegedAction ;
55
58
import java .lang .ref .*;
56
59
/*[IF JAVA_SPEC_VERSION >= 12]*/
57
60
import java .lang .constant .ClassDesc ;
91
94
import java .lang .annotation .Repeatable ;
92
95
import java .lang .invoke .*;
93
96
import com .ibm .oti .reflect .TypeAnnotationParser ;
94
- import java .security .PrivilegedActionException ;
95
97
import sun .security .util .SecurityConstants ;
96
98
97
99
/*[IF JAVA_SPEC_VERSION >= 18]*/
@@ -484,7 +486,16 @@ boolean casAnnotationType(AnnotationType oldType, AnnotationType newType) {
484
486
AnnotationVars localAnnotationVars = getAnnotationVars ();
485
487
long localTypeOffset = AnnotationVars .annotationTypeOffset ;
486
488
if (-1 == localTypeOffset ) {
487
- Field field = AccessController .doPrivileged (new PrivilegedAction <Field >() {
489
+ Field field ;
490
+ /*[IF JAVA_SPEC_VERSION >= 24]*/
491
+ try {
492
+ field = AnnotationVars .class .getDeclaredField ("annotationType" ); //$NON-NLS-1$
493
+ } catch (Exception e ) {
494
+ throw newInternalError (e );
495
+ }
496
+ /*[ELSE] JAVA_SPEC_VERSION >= 24 */
497
+ field = AccessController .doPrivileged (new PrivilegedAction <Field >() {
498
+ @ Override
488
499
public Field run () {
489
500
try {
490
501
return AnnotationVars .class .getDeclaredField ("annotationType" ); //$NON-NLS-1$
@@ -493,6 +504,7 @@ public Field run() {
493
504
}
494
505
}
495
506
});
507
+ /*[ENDIF] JAVA_SPEC_VERSION >= 24 */
496
508
localTypeOffset = getUnsafe ().objectFieldOffset (field );
497
509
AnnotationVars .annotationTypeOffset = localTypeOffset ;
498
510
}
@@ -509,7 +521,9 @@ public Field run() {
509
521
* of a class as described in the class definition of
510
522
* java.lang.Class, however Classes representing base
511
523
* types can not be found using this method.
524
+ /*[IF JAVA_SPEC_VERSION < 24]
512
525
* Security rules will be obeyed.
526
+ /*[ENDIF] JAVA_SPEC_VERSION < 24
513
527
*
514
528
* @param className The name of the non-base type class to find
515
529
* @param initializeBoolean A boolean indicating whether the class should be
@@ -614,7 +628,9 @@ private static Class<?> forNameHelper(
614
628
* It does not invoke the class initializer.
615
629
* Note that this method does not check whether the
616
630
* requested class is accessible to its caller.
631
+ /*[IF JAVA_SPEC_VERSION < 24]
617
632
* Security rules will be obeyed.
633
+ /*[ENDIF] JAVA_SPEC_VERSION < 24
618
634
*
619
635
* @param module The name of the module
620
636
* @param name The name of the non-base type class to find
@@ -629,14 +645,15 @@ public static Class<?> forName(Module module, String name)
629
645
/*[IF JAVA_SPEC_VERSION >= 18]*/
630
646
return forNameHelper (module , name , null , false );
631
647
/*[ELSE] JAVA_SPEC_VERSION >= 18 */
632
- @ SuppressWarnings ("removal" )
633
- SecurityManager sm = null ;
634
648
ClassLoader classLoader ;
635
649
Class <?> c ;
636
650
637
651
if ((null == module ) || (null == name )) {
638
652
throw new NullPointerException ();
639
653
}
654
+ /*[IF JAVA_SPEC_VERSION < 24]*/
655
+ @ SuppressWarnings ("removal" )
656
+ SecurityManager sm = null ;
640
657
if (J9VMInternals .initialized ) {
641
658
sm = System .getSecurityManager ();
642
659
}
@@ -651,7 +668,9 @@ public ClassLoader run() {
651
668
return module .getClassLoader ();
652
669
}
653
670
});
654
- } else {
671
+ } else
672
+ /*[ENDIF] JAVA_SPEC_VERSION < 24 */
673
+ {
655
674
classLoader = module .getClassLoader ();
656
675
}
657
676
@@ -694,7 +713,7 @@ private static Class<?> forNameHelper(Module module, String name, Class<?> calle
694
713
if ((null == module ) || (null == name )) {
695
714
throw new NullPointerException ();
696
715
}
697
- /*[IF JAVA_SPEC_VERSION < 24]*/
716
+ /*[IF JAVA_SPEC_VERSION < 24]*/
698
717
@ SuppressWarnings ("removal" )
699
718
SecurityManager sm = null ;
700
719
if (J9VMInternals .initialized ) {
@@ -714,7 +733,7 @@ public ClassLoader run() {
714
733
}
715
734
});
716
735
} else
717
- /*[ENDIF] JAVA_SPEC_VERSION < 24 */
736
+ /*[ENDIF] JAVA_SPEC_VERSION < 24 */
718
737
{
719
738
classLoader = module .getClassLoader ();
720
739
}
@@ -840,7 +859,9 @@ public ClassLoader getClassLoader() {
840
859
/**
841
860
* Returns the classloader used to load the receiver's class.
842
861
* Returns null if the class was loaded by the bootstrap (system) class loader.
862
+ /*[IF JAVA_SPEC_VERSION < 24]
843
863
* This skips security checks.
864
+ /*[ENDIF] JAVA_SPEC_VERSION < 24
844
865
* @return the receiver's class loader or null
845
866
* @see java.lang.ClassLoader
846
867
*/
@@ -1848,7 +1869,9 @@ private Method throwExceptionOrReturnNull(boolean throwException, String name, C
1848
1869
* public Method getMethod(String name, Class<?>... parameterTypes)
1849
1870
* List<Method> getDeclaredPublicMethods(String name, Class<?>... parameterTypes)
1850
1871
* Method findMethod(boolean publicOnly, String methodName, Class<?>... parameterTypes)
1872
+ /*[IF JAVA_SPEC_VERSION < 24]
1851
1873
* without going thorough security checking
1874
+ /*[ENDIF] JAVA_SPEC_VERSION < 24
1852
1875
*
1853
1876
* @param throwException boolean
1854
1877
* true - throw exception in this helper;
@@ -2428,8 +2451,10 @@ public String getName() {
2428
2451
* Note: In order to conserve space in embedded targets, we allow this
2429
2452
* method to answer null for classes in the system protection domain
2430
2453
* (i.e. for system classes). System classes are always given full
2431
- * permissions (i.e. AllPermission). This is not changeable via the
2432
- * java.security.Policy.
2454
+ * permissions (i.e. AllPermission).
2455
+ /*[IF JAVA_SPEC_VERSION < 24]
2456
+ * This is not changeable via the java.security.Policy.
2457
+ /*[ENDIF] JAVA_SPEC_VERSION < 24
2433
2458
*
2434
2459
* @return ProtectionDomain
2435
2460
* the receiver's ProtectionDomain.
@@ -3573,9 +3598,12 @@ private MethodHandle getValueMethod(final Class<? extends Annotation> containedT
3573
3598
MethodHandle valueMethod = localAnnotationVars .valueMethod ;
3574
3599
if (valueMethod == null ) {
3575
3600
final MethodType methodType = MethodType .methodType (Array .newInstance (containedType , 0 ).getClass ());
3601
+ /*[IF JAVA_SPEC_VERSION < 24]*/
3576
3602
valueMethod = AccessController .doPrivileged (new PrivilegedAction <MethodHandle >() {
3577
3603
@ Override
3578
3604
public MethodHandle run () {
3605
+ /*[ENDIF] JAVA_SPEC_VERSION < 24 */
3606
+ MethodHandle handle ;
3579
3607
try {
3580
3608
MethodHandles .Lookup localImplLookup = implLookup ;
3581
3609
if (localImplLookup == null ) {
@@ -3592,7 +3620,7 @@ public MethodHandle run() {
3592
3620
getUnsafe ().putOrderedObject (Class .class , implLookupOffset , localImplLookup );
3593
3621
/*[ENDIF] JAVA_SPEC_VERSION >= 9 */
3594
3622
}
3595
- MethodHandle handle = localImplLookup .findVirtual (Class .this , "value" , methodType ); //$NON-NLS-1$
3623
+ handle = localImplLookup .findVirtual (Class .this , "value" , methodType ); //$NON-NLS-1$
3596
3624
if (AnnotationVars .valueMethodOffset == -1 ) {
3597
3625
Field valueMethodField = AnnotationVars .class .getDeclaredField ("valueMethod" ); //$NON-NLS-1$
3598
3626
AnnotationVars .valueMethodOffset = getUnsafe ().objectFieldOffset (valueMethodField );
@@ -3604,14 +3632,18 @@ public MethodHandle run() {
3604
3632
/*[ELSE] JAVA_SPEC_VERSION >= 9 */
3605
3633
getUnsafe ().putOrderedObject (localAnnotationVars , AnnotationVars .valueMethodOffset , handle );
3606
3634
/*[ENDIF] JAVA_SPEC_VERSION >= 9 */
3607
- return handle ;
3608
3635
} catch (NoSuchMethodException e ) {
3609
- return null ;
3636
+ handle = null ;
3610
3637
} catch (IllegalAccessException | NoSuchFieldException e ) {
3611
3638
throw newInternalError (e );
3612
3639
}
3640
+ /*[IF JAVA_SPEC_VERSION >= 24]*/
3641
+ valueMethod = handle ;
3642
+ /*[ELSE] JAVA_SPEC_VERSION >= 24 */
3643
+ return handle ;
3613
3644
}
3614
3645
});
3646
+ /*[ENDIF] JAVA_SPEC_VERSION >= 24 */
3615
3647
}
3616
3648
return valueMethod ;
3617
3649
}
@@ -3981,6 +4013,10 @@ T[] getEnumConstantsShared() {
3981
4013
T [] enums = localEnumVars .cachedEnumConstants ;
3982
4014
if (null == enums && isEnum ()) {
3983
4015
try {
4016
+ /*[IF JAVA_SPEC_VERSION >= 24]*/
4017
+ Method values = getMethod ("values" ); //$NON-NLS-1$
4018
+ values .setAccessible (true );
4019
+ /*[ELSE] JAVA_SPEC_VERSION >= 24 */
3984
4020
final PrivilegedExceptionAction <Method > privilegedAction = new PrivilegedExceptionAction <Method >() {
3985
4021
@ Override
3986
4022
public Method run () throws Exception {
@@ -3993,6 +4029,7 @@ public Method run() throws Exception {
3993
4029
};
3994
4030
3995
4031
Method values = AccessController .doPrivileged (privilegedAction );
4032
+ /*[ENDIF] JAVA_SPEC_VERSION >= 24 */
3996
4033
Object rawEnums = values .invoke (this );
3997
4034
if ((rawEnums == null ) || !rawEnums .getClass ().isArray ()) {
3998
4035
return null ;
@@ -4016,7 +4053,14 @@ public Method run() throws Exception {
4016
4053
/*[ELSE] JAVA_SPEC_VERSION >= 9 */
4017
4054
getUnsafe ().putOrderedObject (localEnumVars , localEnumConstantsOffset , enums );
4018
4055
/*[ENDIF] JAVA_SPEC_VERSION >= 9 */
4019
- } catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException | PrivilegedActionException e ) {
4056
+ } catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException
4057
+ /*[IF JAVA_SPEC_VERSION >= 24]*/
4058
+ | NoSuchMethodException
4059
+ /*[ELSE] JAVA_SPEC_VERSION >= 24 */
4060
+ | PrivilegedActionException
4061
+ /*[ENDIF] JAVA_SPEC_VERSION >= 24 */
4062
+ e
4063
+ ) {
4020
4064
enums = null ;
4021
4065
}
4022
4066
}
0 commit comments