Skip to content

Commit 2bf463b

Browse files
committed
java.security comment update and exclude helper methods
Signed-off-by: Theresa Mammarella <[email protected]>
1 parent 7492ec2 commit 2bf463b

File tree

3 files changed

+58
-9
lines changed

3 files changed

+58
-9
lines changed

jcl/src/java.base/share/classes/java/security/AccessControlContext.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -722,6 +722,13 @@ private boolean debugHelper(Permission perm) {
722722
}
723723

724724
/**
725+
/*[IF JAVA_SPEC_VERSION >= 24]
726+
* Throws java.security.AccessControlException
727+
*
728+
* @param perm is ignored
729+
* @exception java.security.AccessControlException
730+
* is always thrown
731+
/*[ELSE] JAVA_SPEC_VERSION >= 24
725732
* Checks if the permission <code>perm</code> is allowed in this context.
726733
* All ProtectionDomains must grant the permission for it to be granted.
727734
*
@@ -731,6 +738,7 @@ private boolean debugHelper(Permission perm) {
731738
* thrown when perm is not granted.
732739
* @exception NullPointerException
733740
* if perm is null
741+
/*[ENDIF] JAVA_SPEC_VERSION >= 24
734742
*/
735743
public void checkPermission(Permission perm) throws AccessControlException {
736744
/*[IF JAVA_SPEC_VERSION >= 24]*/

jcl/src/java.base/share/classes/java/security/AccessController.java

Lines changed: 46 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,9 @@
2323
package java.security;
2424

2525
import com.ibm.oti.util.Msg;
26+
/*[IF JAVA_SPEC_VERSION < 24]*/
2627
import sun.security.util.SecurityConstants;
28+
/*[ENDIF] JAVA_SPEC_VERSION < 24 */
2729

2830
/*[IF JAVA_SPEC_VERSION >= 9]
2931
import jdk.internal.reflect.CallerSensitive;
@@ -49,25 +51,25 @@ public final class AccessController {
4951
initializeInternal();
5052
}
5153

54+
private static native void initializeInternal();
55+
5256
/*[IF JAVA_SPEC_VERSION >= 24]*/
5357
private static AccessControlContext ACC_NO_PERM = new AccessControlContext(
5458
new ProtectionDomain[] { new ProtectionDomain(null, null) });
55-
/*[ENDIF] JAVA_SPEC_VERSION >= 24 */
56-
59+
/*[ELSE] JAVA_SPEC_VERSION >= 24 */
5760
static final int OBJS_INDEX_ACC = 0;
5861
static final int OBJS_INDEX_PDS = 1;
5962
static final int OBJS_ARRAY_SIZE = 3;
6063
static final int OBJS_INDEX_PERMS_OR_CACHECHECKED = 2;
6164

62-
private static native void initializeInternal();
63-
6465
/* [PR CMVC 188787] Enabling -Djava.security.debug option within WAS keeps JVM busy */
6566
static final class DebugRecursionDetection {
6667
private static ThreadLocal<String> tlDebug = new ThreadLocal<>();
6768
static ThreadLocal<String> getTlDebug() {
6869
return tlDebug;
6970
}
7071
}
72+
/*[ENDIF] JAVA_SPEC_VERSION >= 24 */
7173

7274
/*[PR 1FDIC6B] J9JCL:WIN95 - AccessController missing private no-arg constructor */
7375
/**
@@ -77,6 +79,7 @@ private AccessController() {
7779
super();
7880
}
7981

82+
/*[IF JAVA_SPEC_VERSION < 24]*/
8083
/**
8184
* The object array returned has following format:
8285
*
@@ -192,7 +195,6 @@ private static void throwACE(boolean debug, Permission perm, ProtectionDomain pD
192195
}
193196
}
194197

195-
/*[IF JAVA_SPEC_VERSION < 24]*/
196198
/**
197199
* Helper method to check whether the running program is allowed to access the resource
198200
* being guarded by the given Permission argument
@@ -275,7 +277,6 @@ private static boolean checkPermissionHelper(Permission perm, AccessControlConte
275277
}
276278
return limitedPermImplied;
277279
}
278-
/*[ENDIF] JAVA_SPEC_VERSION < 24 */
279280

280281
/**
281282
* Helper to print debug stack information for checkPermission().
@@ -365,15 +366,23 @@ private static boolean debugHelperJEP140(Object[] objects, Permission perm) {
365366
debugPrintStack(debug, perm);
366367
return debug;
367368
}
369+
/*[ENDIF] JAVA_SPEC_VERSION < 24 */
368370

369371
/**
372+
/*[IF JAVA_SPEC_VERSION >= 24]
373+
* Throws AccessControlException
374+
*
375+
* @param perm is ignored
376+
* @exception AccessControlException is always thrown
377+
/*[ELSE] JAVA_SPEC_VERSION >= 24
370378
* Checks whether the running program is allowed to
371379
* access the resource being guarded by the given
372380
* Permission argument.
373381
*
374382
* @param perm the permission to check
375383
* @exception AccessControlException if access is not allowed.
376384
* NullPointerException if perm is null
385+
/*[ENDIF] JAVA_SPEC_VERSION >= 24
377386
*/
378387
public static void checkPermission(Permission perm) throws AccessControlException {
379388
/*[IF JAVA_SPEC_VERSION >= 24]*/
@@ -455,6 +464,9 @@ private static void keepalive(Permission... perms) {
455464
}
456465

457466
/**
467+
/*[IF JAVA_SPEC_VERSION >= 24]
468+
* @return an AccessControlContext with no permissions
469+
/*[ELSE] JAVA_SPEC_VERSION >= 24
458470
* Answers the access controller context of the current thread,
459471
* including the inherited ones. It basically retrieves all the
460472
* protection domains from the calling stack and creates an
@@ -463,6 +475,7 @@ private static void keepalive(Permission... perms) {
463475
* @return an AccessControlContext which captures the current state
464476
*
465477
* @see AccessControlContext
478+
/*[ENDIF] JAVA_SPEC_VERSION >= 24
466479
*/
467480
public static AccessControlContext getContext() {
468481
/*[IF JAVA_SPEC_VERSION >= 24]*/
@@ -472,6 +485,7 @@ public static AccessControlContext getContext() {
472485
/*[ENDIF] JAVA_SPEC_VERSION >= 24 */
473486
}
474487

488+
/*[IF JAVA_SPEC_VERSION < 24]*/
475489
/**
476490
* This is a helper method for getContext() and doPrivilegedWithCombiner methods.
477491
* Answers the access controller context of the current thread including the inherited ones.
@@ -637,6 +651,7 @@ private static int getNewAuthorizedState(AccessControlContext acc, ProtectionDom
637651
}
638652
return newAuthorizedState;
639653
}
654+
/*[ENDIF] JAVA_SPEC_VERSION < 24 */
640655

641656
/**
642657
* Helper method to combine the ProtectionDomain objects
@@ -849,7 +864,11 @@ public static <T> T doPrivileged (PrivilegedExceptionAction<T> action, AccessCon
849864
*/
850865
@CallerSensitive
851866
public static <T> T doPrivilegedWithCombiner(PrivilegedAction<T> action) {
867+
/*[IF JAVA_SPEC_VERSION >= 24]*/
868+
return doPrivileged(action, null);
869+
/*[ELSE] JAVA_SPEC_VERSION >= 24*/
852870
return doPrivileged(action, doPrivilegedWithCombinerHelper(null));
871+
/*[ENDIF] JAVA_SPEC_VERSION >= 24*/
853872
}
854873

855874
/**
@@ -876,9 +895,14 @@ public static <T> T doPrivilegedWithCombiner(PrivilegedAction<T> action) {
876895
public static <T> T doPrivilegedWithCombiner(PrivilegedExceptionAction<T> action)
877896
throws PrivilegedActionException
878897
{
898+
/*[IF JAVA_SPEC_VERSION >= 24]*/
899+
return doPrivileged(action, null);
900+
/*[ELSE] JAVA_SPEC_VERSION >= 24*/
879901
return doPrivileged(action, doPrivilegedWithCombinerHelper(null));
902+
/*[ENDIF] JAVA_SPEC_VERSION >= 24*/
880903
}
881904

905+
/*[IF JAVA_SPEC_VERSION < 24]*/
882906
/**
883907
* Helper method to check if any permission is null
884908
*
@@ -894,6 +918,7 @@ private static void checkPermsNPE(Permission... perms) {
894918
}
895919
}
896920
}
921+
/*[ENDIF] JAVA_SPEC_VERSION < 24 */
897922

898923
/**
899924
* Performs the privileged action specified by <code>action</code>.
@@ -922,7 +947,9 @@ private static void checkPermsNPE(Permission... perms) {
922947
public static <T> T doPrivileged(PrivilegedAction<T> action,
923948
AccessControlContext context, Permission... perms)
924949
{
950+
/*[IF JAVA_SPEC_VERSION < 24]*/
925951
checkPermsNPE(perms);
952+
/*[ENDIF] JAVA_SPEC_VERSION < 24 */
926953
T result = action.run();
927954
keepalive(context);
928955
keepalive(perms);
@@ -954,8 +981,13 @@ public static <T> T doPrivileged(PrivilegedAction<T> action,
954981
public static <T> T doPrivilegedWithCombiner(PrivilegedAction<T> action,
955982
AccessControlContext context, Permission... perms)
956983
{
984+
/*[IF JAVA_SPEC_VERSION >= 24]*/
985+
return doPrivileged(action, context, perms); // 24 - perms?
986+
/*[ELSE] JAVA_SPEC_VERSION >= 24*/
957987
checkPermsNPE(perms);
958988
return doPrivileged(action, doPrivilegedWithCombinerHelper(context), perms);
989+
/*[ENDIF] JAVA_SPEC_VERSION >= 24*/
990+
959991
}
960992

961993
/**
@@ -989,7 +1021,9 @@ public static <T> T doPrivileged(PrivilegedExceptionAction<T> action,
9891021
throws PrivilegedActionException
9901022
{
9911023
try {
1024+
/*[IF JAVA_SPEC_VERSION < 24]*/
9921025
checkPermsNPE(perms);
1026+
/*[ENDIF] JAVA_SPEC_VERSION < 24 */
9931027
T result = action.run();
9941028
keepalive(context);
9951029
keepalive(perms);
@@ -1029,10 +1063,15 @@ public static <T> T doPrivilegedWithCombiner(PrivilegedExceptionAction<T> action
10291063
AccessControlContext context, Permission... perms)
10301064
throws PrivilegedActionException
10311065
{
1066+
/*[IF JAVA_SPEC_VERSION >= 24]*/
1067+
return doPrivileged(action, context, perms);
1068+
/*[ELSE] JAVA_SPEC_VERSION >= 24 */
10321069
checkPermsNPE(perms);
10331070
return doPrivileged(action, doPrivilegedWithCombinerHelper(context), perms);
1071+
/*[ENDIF] JAVA_SPEC_VERSION >= 24 */
10341072
}
10351073

1074+
/*[IF JAVA_SPEC_VERSION < 24]*/
10361075
/**
10371076
* Helper method to construct an AccessControlContext for doPrivilegedWithCombiner methods.
10381077
*
@@ -1052,5 +1091,6 @@ private static AccessControlContext doPrivilegedWithCombinerHelper(AccessControl
10521091
}
10531092
return fixedContext;
10541093
}
1094+
/*[ENDIF] JAVA_SPEC_VERSION < 24*/
10551095

10561096
}

runtime/jcl/common/java_lang_Class.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,9 +56,11 @@ typedef enum {
5656
#define STACK_WALK_STATE_FULL_DOPRIVILEGED (void *)3
5757

5858
static UDATA isPrivilegedFrameIterator(J9VMThread * currentThread, J9StackWalkState * walkState);
59+
#if JAVA_SPEC_VERSION < 24
5960
static UDATA isPrivilegedFrameIteratorGetAccSnapshot(J9VMThread * currentThread, J9StackWalkState * walkState);
6061
static UDATA frameIteratorGetAccSnapshotHelper(J9VMThread * currentThread, J9StackWalkState * walkState, j9object_t acc, j9object_t perm);
6162
static j9object_t storePDobjectsHelper(J9VMThread* vmThread, J9Class* arrayClass, J9StackWalkState* walkState, j9object_t contextObject, U_32 arraySize, UDATA framesWalked, I_32 startPos, BOOLEAN dupCallerPD);
63+
#endif /* JAVA_SPEC_VERSION < 24 */
6264
static BOOLEAN checkInnerClassHelper(J9Class* declaringClass, J9Class* declaredClass);
6365

6466
jobject JNICALL
@@ -1201,6 +1203,7 @@ Java_java_lang_Class_permittedSubclassesImpl(JNIEnv *env, jobject cls)
12011203
return permittedSubclassesHelper(env, cls);
12021204
}
12031205

1206+
#if JAVA_SPEC_VERSION < 24
12041207
static UDATA
12051208
frameIteratorGetAccSnapshotHelper(J9VMThread * currentThread, J9StackWalkState * walkState, j9object_t acc, j9object_t perm)
12061209
{
@@ -1423,13 +1426,11 @@ Java_java_security_AccessController_getAccSnapshot(JNIEnv* env, jclass jsAccessC
14231426
if (NULL != vmThread->currentException) {
14241427
goto _walkStateUninitialized;
14251428
}
1426-
#if JAVA_SPEC_VERSION < 24
14271429
/* AccessControlContext is allocated in the same space as the thread, so no exception can occur */
14281430
contextObject = vmThread->threadObject;
14291431
if (NULL != contextObject) {
14301432
contextObject = J9VMJAVALANGTHREAD_INHERITEDACCESSCONTROLCONTEXT(vmThread, contextObject);
14311433
}
1432-
#endif /* JAVA_SPEC_VERSION < 24 */
14331434
/* Walk the stack, caching the constant pools of the frames. */
14341435
walkState.skipCount = startingFrame + 1; /* skip this JNI frame as well */
14351436
walkState.userData1 = STACK_WALK_STATE_MAGIC; /* set to NULL when a limited doPrivileged frame is discovered */
@@ -1821,7 +1822,7 @@ storePDobjectsHelper(J9VMThread* vmThread, J9Class* arrayClass, J9StackWalkState
18211822
}
18221823
return arrayObject;
18231824
}
1824-
1825+
#endif /* JAVA_SPEC_VERSION < 24 */
18251826

18261827
jobject JNICALL
18271828
Java_java_lang_Class_getNestHostImpl(JNIEnv *env, jobject recv)

0 commit comments

Comments
 (0)