Skip to content

Commit

Permalink
Fix for #23922 - EAR with multiple WAR logs many false ClassNotFound …
Browse files Browse the repository at this point in the history
…warnings (#24152)

* Fix #23922 - EAR with multiple WAR logs many false ClassNotFound warnings
#23922
Also gives a meaningful message instead of exception if WAR in EAR has an unexpected name or doesn't exist.
Signed-off-by:Ondro Mihalyi <mihalyi@omnifish.ee>
  • Loading branch information
OndroMih committed Nov 7, 2022
1 parent a17041f commit 921e44c
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -373,6 +373,9 @@ public EarClassLoader run() {
for (ModuleDescriptor<BundleDescriptor> md : holder.app.getModules()) {
String moduleUri = md.getArchiveUri();
try (ReadableArchive sub = archive.getSubArchive(moduleUri)) {
if (sub == null) {
throw new IllegalArgumentException(strings.get("noSubModuleArchiveFound", moduleUri));
}
if (sub instanceof InputJarArchive) {
throw new IllegalArgumentException(strings.get("wrongArchType", moduleUri));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,6 @@

errAddLibs=Error in adding libraries in library directory
wrongArchType=Expected to find an expanded directory for submodule {0} but found a JAR. If this is a directory deployment be sure to expand all submodules.
noSubModuleArchiveFound=Expected to find an expanded directory for submodule {0} but didn''t find it. Check that the submodule file or expanded directory is in the root of the EAR being deployed and its name matches the name in META-INF/application.xml descriptor in the EAR.
noClassLoader=Cannot find a class loader for submodule {0}
errReadMetadata=Cannot read application metadata
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,13 @@ public class ServletContainerInitializerUtil {

private static final ResourceBundle rb = log.getResourceBundle();

public static interface LogContext {

public default Level getNonCriticalClassloadingErrorLogLevel() {
return Level.WARNING;
}
}

/**
* Given a class loader, check for ServletContainerInitializer
* implementations in any JAR file in the classpath
Expand Down Expand Up @@ -201,7 +208,7 @@ public static Map<Class<? extends ServletContainerInitializer>, Set<Class<?>>>
Iterable<ServletContainerInitializer> initializers,
Map<Class<?>, List<Class<? extends ServletContainerInitializer>>> interestList,
Types types,
ClassLoader cl) {
ClassLoader cl, LogContext logContext) {

if (interestList == null) {
return null;
Expand Down Expand Up @@ -304,9 +311,9 @@ public static Map<Class<? extends ServletContainerInitializer>, Set<Class<?>>>
}
}

initializerList = checkAgainstInterestList(classInfo, interestList, initializerList, cl);
initializerList = checkAgainstInterestList(classInfo, interestList, initializerList, cl, logContext);
} else {
initializerList = checkAgainstInterestList(types, interestList, initializerList, cl);
initializerList = checkAgainstInterestList(types, interestList, initializerList, cl, logContext);
}
}

Expand Down Expand Up @@ -396,7 +403,7 @@ private static Map<Class<? extends ServletContainerInitializer>, Set<Class<?>>>
Types classInfo,
Map<Class<?>, List<Class<? extends ServletContainerInitializer>>> interestList,
Map<Class<? extends ServletContainerInitializer>, Set<Class<?>>> initializerList,
ClassLoader cl) {
ClassLoader cl, LogContext logContext) {

if (classInfo==null) {
return initializerList;
Expand All @@ -421,8 +428,8 @@ private static Map<Class<? extends ServletContainerInitializer>, Set<Class<?>>>
try {
resultSet.add(cl.loadClass(ae.getName()));
} catch (Throwable t) {
if (log.isLoggable(Level.WARNING)) {
log.log(Level.WARNING,
if (log.isLoggable(logContext.getNonCriticalClassloadingErrorLogLevel())) {
log.log(logContext.getNonCriticalClassloadingErrorLogLevel(),
LogFacade.CLASS_LOADING_ERROR,
new Object[] {ae.getName(), t.toString()});
}
Expand All @@ -440,8 +447,8 @@ private static Map<Class<? extends ServletContainerInitializer>, Set<Class<?>>>
try {
resultSet.add(cl.loadClass(classModel.getName()));
} catch (Throwable t) {
if (log.isLoggable(Level.WARNING)) {
log.log(Level.WARNING,
if (log.isLoggable(logContext.getNonCriticalClassloadingErrorLogLevel())) {
log.log(logContext.getNonCriticalClassloadingErrorLogLevel(),
LogFacade.CLASS_LOADING_ERROR,
new Object[] {classModel.getName(), t.toString()});
}
Expand Down Expand Up @@ -479,7 +486,7 @@ private static Map<Class<? extends ServletContainerInitializer>, Set<Class<?>>>
ClassDependencyBuilder classInfo,
Map<Class<?>, List<Class<? extends ServletContainerInitializer>>> interestList,
Map<Class<? extends ServletContainerInitializer>, Set<Class<?>>> initializerList,
ClassLoader cl) {
ClassLoader cl, LogContext logContext) {
for(Map.Entry<Class<?>, List<Class<? extends ServletContainerInitializer>>> e :
interestList.entrySet()) {

Expand All @@ -495,8 +502,8 @@ private static Map<Class<? extends ServletContainerInitializer>, Set<Class<?>>>
Class aClass = cl.loadClass(className);
resultSet.add(aClass);
} catch (Throwable t) {
if (log.isLoggable(Level.WARNING)) {
log.log(Level.WARNING,
if (log.isLoggable(logContext.getNonCriticalClassloadingErrorLogLevel())) {
log.log(logContext.getNonCriticalClassloadingErrorLogLevel(),
LogFacade.CLASS_LOADING_ERROR,
new Object[] {className, t.toString()});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,8 @@
import jakarta.servlet.http.HttpSessionIdListener;
import jakarta.servlet.http.HttpSessionListener;
import jakarta.servlet.http.HttpUpgradeHandler;
import java.util.logging.Level;
import org.glassfish.web.loader.ServletContainerInitializerUtil;

/**
* Standard implementation of the <b>Context</b> interface. Each child container must be a Wrapper implementation to
Expand Down Expand Up @@ -806,6 +808,13 @@ public StandardContext() {

protected int servletReloadCheckSecs = 1;

// Fine tune log levels for ServletContainerInitializerUtil to avoid spurious or too verbose logging
protected ServletContainerInitializerUtil.LogContext logContext
= new ServletContainerInitializerUtil.LogContext() {
public Level getNonCriticalClassloadingErrorLogLevel() {
return isStandaloneModule() ? Level.WARNING : Level.FINE;
}
};

// ----------------------------------------------------- Context Properties

Expand Down Expand Up @@ -5283,6 +5292,10 @@ protected Types getTypes() {
return null;
}

protected boolean isStandaloneModule() {
return true;
}

protected void callServletContainerInitializers() throws LifecycleException {
Iterator<ServletContainerInitializer> initIterator = servletContainerInitializers.iterator();
List<ServletContainerInitializer> loadedServletContainerInitializers = new ArrayList<>();
Expand All @@ -5297,7 +5310,7 @@ protected void callServletContainerInitializers() throws LifecycleException {
// Get the list of ServletContainerInitializers and the classes
// they are interested in
var interestList = getInterestList(loadedServletContainerInitializers);
var initializerList = getInitializerList(loadedServletContainerInitializers, interestList, getTypes(), getClassLoader());
var initializerList = getInitializerList(loadedServletContainerInitializers, interestList, getTypes(), getClassLoader(), logContext);

if (initializerList == null) {
return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1165,6 +1165,10 @@ boolean isStandalone() {
return isStandalone;
}

protected boolean isStandaloneModule() {
return isStandalone;
}

/**
* Sets the WebBundleDescriptor (web.xml) for this WebModule.
*
Expand Down

0 comments on commit 921e44c

Please sign in to comment.