Skip to content

Commit

Permalink
Test failure with java-21 on LogManagerPropertiesTest #700 (#704)
Browse files Browse the repository at this point in the history
Signed-off-by: jmehrens <[email protected]>
  • Loading branch information
jmehrens authored Jan 25, 2024
1 parent 46d429c commit 86ee859
Show file tree
Hide file tree
Showing 8 changed files with 770 additions and 1,542 deletions.
10 changes: 8 additions & 2 deletions doc/release/CHANGES.txt
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,12 @@ Bug IDs that start with "G" can be found in the GlassFish Issue Tracker
Seven digit bug numbers are from the old Sun bug database, which is no
longer available.

CHANGES IN THE 1.6.8 RELEASE
----------------------------
The following bugs have been fixed in the 1.6.8 release.

E 700 Test failure with java-21 on LogManagerPropertiesTest


CHANGES IN THE 1.6.7 RELEASE
----------------------------
Expand Down Expand Up @@ -110,7 +116,7 @@ GH 334 gimap set labels error with some non english characters
The following bugs have been fixed in the 1.6.1 release.

GH 262 Some IMAP servers send EXPUNGE responses for unknown messages
GH 278 BODYSTRUCTURE Parser fails on specific IMAP Server response
GH 278 BODYSTRUCTURE Parser fails on specific IMAP Server response
GH 283 clean up connections when closing IMAPStore
GH 287 Allow relaxed Content-Disposition parsing
GH 289 use a different IMAP tag prefix for each connection
Expand Down Expand Up @@ -831,7 +837,7 @@ The following bugs have been fixed in the 1.1.2 release.
<no id> fix bug in SMTP output that sometimes duplicated "."
<no id> close SMTP transport on I/O error
4230541 don't send SMTP NOOP unnecessarily
4216666 IMAP provider INTERNALDATE formatter error, causing
4216666 IMAP provider INTERNALDATE formatter error, causing
problems during appendMessages()
4227888 IMAP provider does not honor the UID item in its FetchProfile

Expand Down
14 changes: 3 additions & 11 deletions logging/src/main/java/FileErrorManager.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* Copyright (c) 2009, 2019 Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2009, 2019 Jason Mehrens. All Rights Reserved.
* Copyright (c) 2009, 2024 Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2009, 2024 Jason Mehrens. All Rights Reserved.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Distribution License v. 1.0, which is available at
Expand All @@ -11,8 +11,6 @@

import java.io.*;
import java.lang.reflect.Constructor;
import java.security.AccessController;
import java.security.PrivilegedAction;
import java.util.logging.ErrorManager;
import java.util.logging.Level;
import java.util.logging.LogManager;
Expand Down Expand Up @@ -262,13 +260,7 @@ private File getEmailStore() {
String dir = manager.getProperty(
getClass().getName().concat(".pattern"));
if (dir == null) {
dir = AccessController.doPrivileged(new PrivilegedAction<String>() {

@Override
public String run() {
return System.getProperty("java.io.tmpdir", ".");
}
});
dir = System.getProperty("java.io.tmpdir", ".");
}
return new File(dir);
}
Expand Down
17 changes: 2 additions & 15 deletions logging/src/main/java/MailHandlerDemo.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* Copyright (c) 2009, 2019 Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2009, 2018 Jason Mehrens. All Rights Reserved.
* Copyright (c) 2009, 2024 Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2009, 2024 Jason Mehrens. All Rights Reserved.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Distribution License v. 1.0, which is available at
Expand Down Expand Up @@ -139,19 +139,6 @@ private static void checkConfig(String prefix, PrintStream err) {
+ ManagementFactory.getRuntimeMXBean().getName());
err.println(prefix + ": java.security.debug="
+ System.getProperty("java.security.debug"));
SecurityManager sm = System.getSecurityManager();
if (sm != null) {
err.println(prefix + ": SecurityManager.class="
+ sm.getClass().getName());
err.println(prefix + ": SecurityManager classLoader="
+ toString(sm.getClass().getClassLoader()));
err.println(prefix + ": SecurityManager.toString=" + sm);
} else {
err.println(prefix + ": SecurityManager.class=null");
err.println(prefix + ": SecurityManager.toString=null");
err.println(prefix + ": SecurityManager classLoader=null");
}

String policy = System.getProperty("java.security.policy");
if (policy != null) {
File f = new File(policy);
Expand Down
119 changes: 85 additions & 34 deletions mail/src/main/java/com/sun/mail/util/logging/LogManagerProperties.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* Copyright (c) 2009, 2021 Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2009, 2021 Jason Mehrens. All rights reserved.
* Copyright (c) 2009, 2024 Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2009, 2024 Jason Mehrens. All rights reserved.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0, which is available at
Expand All @@ -21,7 +21,6 @@
import java.lang.reflect.Method;
import java.lang.reflect.Modifier;
import java.lang.reflect.UndeclaredThrowableException;
import java.security.AccessController;
import java.security.PrivilegedAction;
import java.util.*;
import java.util.logging.*;
Expand Down Expand Up @@ -81,7 +80,7 @@ final class LogManagerProperties extends Properties {
private static final Method ZDT_OF_INSTANT;

/**
* MethodHandle is available starting at JDK7 and Andriod API 26.
* MethodHandle is available starting at JDK7 and Android API 26.
*/
static { //Added in JDK16 see JDK-8245302
Method lrtid = null;
Expand All @@ -94,7 +93,7 @@ final class LogManagerProperties extends Properties {
LR_GET_LONG_TID = lrtid;
}

static {
static { //Added in JDK9 see JDK-8072645
Method lrgi = null;
Method zisd = null;
Method zdtoi = null;
Expand All @@ -105,7 +104,6 @@ final class LogManagerProperties extends Properties {
zisd = findClass("java.time.ZoneId")
.getMethod("systemDefault");
if (!Modifier.isStatic(zisd.getModifiers())) {
zisd = null;
throw new NoSuchMethodException(zisd.toString());
}

Expand All @@ -115,7 +113,6 @@ final class LogManagerProperties extends Properties {
if (!Modifier.isStatic(zdtoi.getModifiers())
|| !Comparable.class.isAssignableFrom(
zdtoi.getReturnType())) {
zdtoi = null;
throw new NoSuchMethodException(zdtoi.toString());
}
} catch (final RuntimeException ignore) {
Expand Down Expand Up @@ -155,7 +152,7 @@ final class LogManagerProperties extends Properties {
*/
private static Object loadLogManager() {
Object m;
try {
try { //GAE will forbid access to LogManager
m = LogManager.getLogManager();
} catch (final LinkageError restricted) {
m = readConfiguration();
Expand Down Expand Up @@ -247,16 +244,31 @@ static void checkLogManagerAccess() {
if (m != null) {
try {
if (m instanceof LogManager) {
checked = true;
((LogManager) m).checkAccess();
try {
LogManager.class.getMethod("checkAccess").invoke(m);
checked = true;
} catch (InvocationTargetException ite) {
Throwable cause = ite.getCause();
if (cause instanceof SecurityException) {
checked = true;
throw (SecurityException) cause;
}

if (cause instanceof UnsupportedOperationException) {
checked = true;
}
} catch (NoSuchMethodException removed) {
checked = true;
} catch (ReflectiveOperationException fallthrough) {
}
}
} catch (final SecurityException notAllowed) {
if (checked) {
throw notAllowed;
}
} catch (final LinkageError restricted) {
} catch (final RuntimeException unexpected) {
}
} //GAE will forbid access to LogManager
}

if (!checked) {
Expand All @@ -279,25 +291,15 @@ private static void checkLoggingAccess() {
* indirect way of checking for LoggingPermission when the LogManager is
* not present. The root logger will lazy create handlers so the global
* logger is used instead as it is a known named logger with well
* defined behavior. If the global logger is a subclass then fallback to
* using the SecurityManager.
* defined behavior. Contractually, Logger::remove will check
* permission before checking if the argument is null.
* See JDK-8023168
*/
boolean checked = false;
final Logger global = Logger.getLogger("global");
try {
if (Logger.class == global.getClass()) {
global.removeHandler((Handler) null);
checked = true;
}
global.removeHandler((Handler) null);
} catch (final NullPointerException unexpected) {
}

if (!checked) {
final SecurityManager sm = System.getSecurityManager();
if (sm != null) {
sm.checkPermission(new LoggingPermission("control", null));
}
}
}

/**
Expand Down Expand Up @@ -784,18 +786,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 Expand Up @@ -871,7 +867,7 @@ private static Class<?> tryLoad(String name, ClassLoader l) throws ClassNotFound
* @return any array of class loaders. Indexes may be null.
*/
private static ClassLoader[] getClassLoaders() {
return AccessController.doPrivileged(new PrivilegedAction<ClassLoader[]>() {
return runOrDoPrivileged(new PrivilegedAction<ClassLoader[]>() {

@SuppressWarnings("override") //JDK-6954234
public ClassLoader[] run() {
Expand All @@ -891,6 +887,61 @@ public ClassLoader[] run() {
}
});
}

/**
* Executes a PrivilegedAction without permissions then falling back to
* running with elevated permissions.
*
* Any unchecked exceptions from the action are passed through this API.
*
* @param <T> the action return type.
* @param a the PrivilegedAction object.
* @return the result.
* @throws NullPointerException if the given action is null.
* @throws UndeclaredThrowableException if a checked exception is thrown.
* @since JavaMail 1.6.8
*/
static <T> T runOrDoPrivileged(final PrivilegedAction<T> a) {
if (a == null) {
throw new NullPointerException();
}
try {
return a.run();
} catch (SecurityException sandbox) {
return invokeAccessController(a);
}
}

/**
* Reflective call to access controller for sandbox environments.
* Any unchecked exceptions from the action are passed through this API.
*
* @param <T> the return type of the action.
* @param a a non-null action.
* @return the result.
* @throws UnsupportedOperationException if not allowed.
* @throws UndeclaredThrowableException if a checked exception is thrown.
* @since JavaMail 1.6.8
*/
@SuppressWarnings("unchecked")
private static <T> T invokeAccessController(final PrivilegedAction<T> a) {
assert a != null;
try {
Class<?> c = Class.forName("java.security.AccessController");
return (T) c.getMethod("doPrivileged", PrivilegedAction.class)
.invoke((Object) null, a);
} catch (ReflectiveOperationException roe) {
Throwable cause = roe.getCause();
if (cause instanceof RuntimeException) {
throw (RuntimeException) cause;
} else if (cause instanceof Error) {
throw (Error) cause;
} else {
throw new UndeclaredThrowableException(roe);
}
}
}

/**
* The namespace prefix to search LogManager and defaults.
*/
Expand Down
9 changes: 4 additions & 5 deletions mail/src/main/java/com/sun/mail/util/logging/MailHandler.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* Copyright (c) 2009, 2020 Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2009, 2020 Jason Mehrens. All rights reserved.
* Copyright (c) 2009, 2024 Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2009, 2024 Jason Mehrens. All rights reserved.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0, which is available at
Expand All @@ -24,7 +24,6 @@
import java.net.URLConnection;
import java.net.UnknownHostException;
import java.nio.charset.Charset;
import java.security.AccessController;
import java.security.PrivilegedAction;
import java.util.*;
import java.util.logging.*;
Expand Down Expand Up @@ -578,7 +577,7 @@ public boolean isLoggable(final LogRecord record) {
if (record == null) { //JDK-8233979
return false;
}

int levelValue = getLevel().intValue();
if (record.getLevel().intValue() < levelValue || levelValue == offValue) {
return false;
Expand Down Expand Up @@ -4139,7 +4138,7 @@ private Object getAndSetContextClassLoader(final Object ccl) {
} else {
pa = new GetAndSetContext(ccl);
}
return AccessController.doPrivileged(pa);
return LogManagerProperties.runOrDoPrivileged(pa);
} catch (final SecurityException ignore) {
}
}
Expand Down
Loading

0 comments on commit 86ee859

Please sign in to comment.