Skip to content

Commit 4336d2e

Browse files
Use PrivilegedAction to use StackWalker with RETAIN_CLASS_REFERENCE option
If a SecurityManager is utilized, permissions are needed to use the StackWalker class with the RETAIN_CLASS_REFERENCE option, which RestrictedSecurity doesn't have. A PrivilegedAction is used to allow said action in this case. Signed-off-by: Kostas Tsiounis <[email protected]>
1 parent 6ae95a7 commit 4336d2e

File tree

1 file changed

+12
-3
lines changed

1 file changed

+12
-3
lines changed

closed/src/java.base/share/classes/openj9/internal/security/RestrictedSecurity.java

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -191,11 +191,20 @@ private static boolean isJarVerifierInStackTrace() {
191191
* extending profiles, instead of altering them, a digest of the profile
192192
* is calculated and compared to the expected value.
193193
*/
194+
@SuppressWarnings("removal")
194195
private static void checkHashValues() {
195196
ProfileParser parser = profileParser;
196-
if ((parser != null) && !isJarVerifierInStackTrace()) {
197-
profileParser = null;
198-
parser.checkHashValues();
197+
if (parser != null) {
198+
boolean isVerifying;
199+
if (System.getSecurityManager() == null) {
200+
isVerifying = isJarVerifierInStackTrace();
201+
} else {
202+
isVerifying = AccessController.doPrivileged((PrivilegedAction<Boolean>)(() -> isJarVerifierInStackTrace()));
203+
}
204+
if (!isVerifying) {
205+
profileParser = null;
206+
parser.checkHashValues();
207+
}
199208
}
200209
}
201210

0 commit comments

Comments
 (0)