Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes #24788 No stacktrace is printed in server log when exception occurs in class specified by Lifecycle Module #24789

Merged
merged 2 commits into from
Feb 6, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2023 Contributors to the Eclipse Foundation
* Copyright (c) 2023, 2024 Contributors to the Eclipse Foundation
* Copyright (c) 1997, 2018 Oracle and/or its affiliates. All rights reserved.
*
* This program and the accompanying materials are made available under the
Expand Down Expand Up @@ -36,6 +36,7 @@
import com.sun.appserv.server.LifecycleListener;
import com.sun.appserv.server.ServerLifecycleException;
import com.sun.enterprise.util.LocalStringManagerImpl;
import org.glassfish.api.logging.LogHelper;

/**
* @author Sridatta Viswanath
Expand Down Expand Up @@ -112,18 +113,18 @@ LifecycleListener loadServerLifecycle() throws ServerLifecycleException {
classLoader = ctx.getLifecycleParentClassLoader();
} else {
URL[] urls = getURLs();
_logger.log(Level.FINE, "Lifecycle module = {0} has classpath URLs = {1}", new Object[] {getName(), urls});
_logger.log(Level.FINE, "Lifecycle module = {0} has classpath URLs = {1}", new Object[] { getName(), urls });
this.urlClassLoader = new GlassfishUrlClassLoader(urls, ctx.getLifecycleParentClassLoader());
classLoader = this.urlClassLoader;
}
@SuppressWarnings("unchecked")
Class<LifecycleListener> clazz = (Class<LifecycleListener>) Class.forName(className, true, classLoader);
slcl = clazz.getDeclaredConstructor().newInstance();
} catch (Exception ee) {
_logger.log(Level.SEVERE, KernelLoggerInfo.exceptionLoadingLifecycleModule, new Object[] {this.name, ee});
LogHelper.log(_logger, Level.SEVERE, KernelLoggerInfo.exceptionLoadingLifecycleModule, ee, new Object[] { this.name, ee });
if (isFatal) {
throw new ServerLifecycleException(localStrings.getLocalString("lifecyclemodule.loadExceptionIsFatal",
"Treating failure loading the lifecycle module as fatal", this.name));
"Treating failure loading the lifecycle module as fatal", this.name));
}
}

Expand All @@ -132,16 +133,15 @@ LifecycleListener loadServerLifecycle() throws ServerLifecycleException {

private URL[] getURLs() {
List<URL> urlList = ASClassLoaderUtil.getURLsFromClasspath(
this.classpath, File.pathSeparator, "");
this.classpath, File.pathSeparator, "");
return ASClassLoaderUtil.convertURLListToArray(urlList);
}


private void postEvent(int eventType, Object data) throws ServerLifecycleException {
if (slcl == null) {
if (isFatal) {
throw new ServerLifecycleException(localStrings.getLocalString("lifecyclemodule.loadExceptionIsFatal",
"Treating failure loading the lifecycle module as fatal", this.name));
"Treating failure loading the lifecycle module as fatal", this.name));
}
return;
}
Expand All @@ -150,48 +150,43 @@ private void postEvent(int eventType, Object data) throws ServerLifecycleExcepti
setClassLoader();
}

LifecycleEvent slcEvent= new LifecycleEvent(this, eventType, data, this.leContext);
LifecycleEvent slcEvent = new LifecycleEvent(this, eventType, data, this.leContext);
try {
slcl.handleEvent(slcEvent);
} catch (ServerLifecycleException sle) {
_logger.log(Level.WARNING, KernelLoggerInfo.serverLifecycleException, new Object[] {this.name, sle});
LogHelper.log(_logger, Level.WARNING, KernelLoggerInfo.serverLifecycleException, sle, new Object[] { this.name, sle });
if (isFatal) {
throw sle;
}
} catch (Exception ee) {
_logger.log(Level.WARNING, KernelLoggerInfo.lifecycleModuleException, new Object[] {this.name, ee});
LogHelper.log(_logger, Level.WARNING, KernelLoggerInfo.lifecycleModuleException, ee, new Object[] { this.name, ee });
if (isFatal) {
throw new ServerLifecycleException(localStrings.getLocalString("lifecyclemodule.event_exceptionIsFatal", "Treating the exception from lifecycle module event handler as fatal"), ee);
throw new ServerLifecycleException(localStrings.getLocalString("lifecyclemodule.event_exceptionIsFatal",
"Treating the exception from lifecycle module event handler as fatal"), ee);
}
}
}


public void onInitialization() throws ServerLifecycleException {
postEvent(LifecycleEvent.INIT_EVENT, props);
}


public void onStartup() throws ServerLifecycleException {
postEvent(LifecycleEvent.STARTUP_EVENT, props);
}


public void onReady() throws ServerLifecycleException {
postEvent(LifecycleEvent.READY_EVENT, props);
}


public void onShutdown() throws ServerLifecycleException {
postEvent(LifecycleEvent.SHUTDOWN_EVENT, props);
}


public void onTermination() throws ServerLifecycleException {
postEvent(LifecycleEvent.TERMINATION_EVENT, props);
}


private void setClassLoader() {
// set the url class loader as the thread context class loader
PrivilegedAction<Void> action = () -> {
Expand Down