Skip to content

Commit

Permalink
Merge pull request #24789 from kaido207/fix_lifecycle_app_log
Browse files Browse the repository at this point in the history
Fixes #24788 No stacktrace is printed in server log when exception occurs in class specified by Lifecycle Module
  • Loading branch information
dmatej authored Feb 6, 2024
2 parents 72e120b + 3b9d280 commit c1cb590
Showing 1 changed file with 12 additions and 17 deletions.
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

0 comments on commit c1cb590

Please sign in to comment.