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