Skip to content

Commit

Permalink
Remove SecurityManager references from logging package #16
Browse files Browse the repository at this point in the history
Signed-off-by: jmehrens <jason_mehrens@hotmail.com>
  • Loading branch information
jmehrens committed Jan 15, 2024
1 parent 4c0d552 commit 0f62189
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -768,18 +768,12 @@ static <T> T newObjectFrom(String name, Class<T> type) throws Exception {
* @param ite any invocation target.
* @return the exception.
* @throws VirtualMachineError if present as cause.
* @throws ThreadDeath if present as cause.
* @since JavaMail 1.4.5
*/
private static Exception paramOrError(InvocationTargetException ite) {
final Throwable cause = ite.getCause();
if (cause != null) {
//Bitwise inclusive OR produces tighter bytecode for instanceof
//and matches with multicatch syntax.
if (cause instanceof VirtualMachineError
| cause instanceof ThreadDeath) {
throw (Error) cause;
}
if (cause instanceof VirtualMachineError) {
throw (Error) cause;
}
return ite;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ public void testCheckLogManagerAccess() {
}
}

private static boolean isAccessController() {
private static boolean isInvokeAccessController() {
for (StackTraceElement frame : new Throwable().getStackTrace()) {
if ("invokeAccessController".equals(frame.getMethodName())
&& LogManagerProperties.class.getName().equals(frame.getClassName())) {
Expand All @@ -110,9 +110,21 @@ private static boolean isAccessController() {
return false;
}

private static boolean isAccessController() {
for (StackTraceElement frame : new Throwable().getStackTrace()) {
if ("doPrivileged".equals(frame.getMethodName())
&& "java.security.AccessController".equals(
frame.getClassName())) {
return true;
}
}
return false;
}

@Test
public void testRun() {
PrivilegedAction<Boolean> p = () -> {
assertFalse(isInvokeAccessController());
assertFalse(isAccessController());
return true;
};
Expand All @@ -122,8 +134,8 @@ public void testRun() {
@Test
public void testDoPrivileged() {
PrivilegedAction<Boolean> p = () -> {
if (isAccessController()) {
return true;
if (isInvokeAccessController()) {
return isAccessController();
}
throw new SecurityException();
};
Expand All @@ -140,7 +152,7 @@ public void testDoPrivileged() {
public void testDoPrivilegedRuntimeException() {
RuntimeException cause = new RuntimeException();
PrivilegedAction<Boolean> p = () -> {
if (isAccessController()) {
if (isInvokeAccessController()) {
throw cause;
}
throw new SecurityException();
Expand All @@ -163,7 +175,7 @@ public void testDoPrivilegedRuntimeException() {
public void testDoPrivilegedError() {
Error cause = new Error();
PrivilegedAction<Boolean> p = () -> {
if (isAccessController()) {
if (isInvokeAccessController()) {
throw cause;
}
throw new SecurityException();
Expand Down Expand Up @@ -1033,11 +1045,11 @@ public void testEscapingAuthenticator() throws Exception {
a = LogManagerProperties.newObjectFrom(k.getName(), Authenticator.class);
assertEquals(k, a.getClass());

setPending(new ThreadDeath());
setPending(new StackOverflowError());
try {
a = LogManagerProperties.newObjectFrom(k.getName(), Authenticator.class);
fail(String.valueOf(a));
} catch (ThreadDeath expect) {
} catch (StackOverflowError expect) {
}

setPending(new OutOfMemoryError());
Expand All @@ -1060,11 +1072,11 @@ public void testEscapingComparator() throws Exception {
c = LogManagerProperties.newComparator(k.getName());
assertEquals(k, c.getClass());

setPending(new ThreadDeath());
setPending(new StackOverflowError());
try {
c = LogManagerProperties.newComparator(k.getName());
fail(String.valueOf(c));
} catch (ThreadDeath expect) {
} catch (StackOverflowError expect) {
}

setPending(new OutOfMemoryError());
Expand All @@ -1087,11 +1099,11 @@ public void testEscapingErrorErrorManager() throws Exception {
f = LogManagerProperties.newErrorManager(k.getName());
assertEquals(k, f.getClass());

setPending(new ThreadDeath());
setPending(new StackOverflowError());
try {
f = LogManagerProperties.newErrorManager(k.getName());
fail(String.valueOf(f));
} catch (ThreadDeath expect) {
} catch (StackOverflowError expect) {
}

setPending(new OutOfMemoryError());
Expand All @@ -1114,11 +1126,11 @@ public void testEscapingFilter() throws Exception {
f = LogManagerProperties.newFilter(k.getName());
assertEquals(k, f.getClass());

setPending(new ThreadDeath());
setPending(new StackOverflowError());
try {
f = LogManagerProperties.newFilter(k.getName());
fail(String.valueOf(f));
} catch (ThreadDeath expect) {
} catch (StackOverflowError expect) {
}

setPending(new OutOfMemoryError());
Expand All @@ -1141,11 +1153,11 @@ public void testEscapingFormatter() throws Exception {
f = LogManagerProperties.newFormatter(k.getName());
assertEquals(k, f.getClass());

setPending(new ThreadDeath());
setPending(new StackOverflowError());
try {
f = LogManagerProperties.newFormatter(k.getName());
fail(String.valueOf(f));
} catch (ThreadDeath expect) {
} catch (StackOverflowError expect) {
}

setPending(new OutOfMemoryError());
Expand Down

0 comments on commit 0f62189

Please sign in to comment.