Skip to content

Commit

Permalink
The libPath field was in fact a constant which must not change
Browse files Browse the repository at this point in the history
Signed-off-by: David Matějček <david.matejcek@omnifish.ee>
  • Loading branch information
dmatej committed Jan 15, 2023
1 parent 2f97375 commit efd9ab4
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -148,11 +148,15 @@ public final class WebappClassLoader extends GlassfishUrlClassLoader

/** First try parent classloader, then own resources. */
public static final boolean DELEGATE_DEFAULT = true;

private static final Logger LOG = LogFacade.getSysLogger(WebappClassLoader.class);
private static final ResourceBundle rb = LogFacade.getLogger().getResourceBundle();

private static final Function<String, String> PACKAGE_TO_PATH = pkg -> pkg.replace('.', '/');

/** The path which will be monitored for added Jar files. */
private static final String WEB_INF_LIB = "/WEB-INF/lib";

/**
* Set of package names which are not allowed to be loaded from a webapp
* class loader without delegating first.
Expand Down Expand Up @@ -213,11 +217,6 @@ public final class WebappClassLoader extends GlassfishUrlClassLoader
*/
private final JarFileManager jarFiles = new JarFileManager();

/**
* The path which will be monitored for added Jar files.
*/
private String jarPath;

/**
* The list of JARs, in the order they should be searched
* for locally loaded classes or resources.
Expand Down Expand Up @@ -440,11 +439,10 @@ public void addEEPermissions(PermissionCollection eePc) throws SecurityException


/**
* Change the Jar path.
* @return the Jar path.
*/
public void setJarPath(String jarPath) {
checkStatus(LifeCycleStatus.NEW, LifeCycleStatus.RUNNING);
this.jarPath = jarPath;
public String getLibJarPath() {
return WEB_INF_LIB;
}


Expand Down Expand Up @@ -496,7 +494,7 @@ public void addRepository(String repository) {
checkStatus(LifeCycleStatus.NEW, LifeCycleStatus.RUNNING);
// Ignore any of the standard repositories, as they are set up using
// either addJar or addRepository
if (repository.startsWith("/WEB-INF/lib") || repository.startsWith("/WEB-INF/classes")) {
if (repository.startsWith(WEB_INF_LIB) || repository.startsWith("/WEB-INF/classes")) {
return;
}

Expand Down Expand Up @@ -534,9 +532,9 @@ public void addJar(String filePath, File file) throws IOException {

super.addURL(getURL(file));

if (jarPath != null && filePath.startsWith(jarPath)) {
String jarName = filePath.substring(jarPath.length());
while (jarName.startsWith("/")) {
if (filePath.startsWith(WEB_INF_LIB)) {
String jarName = filePath.substring(WEB_INF_LIB.length());
while (jarName.charAt(0) == '/') {
jarName = jarName.substring(1);
}
jarNames.add(jarName);
Expand Down Expand Up @@ -620,14 +618,9 @@ public boolean modified() {
}
}

// Check if JARs have been added or removed
if (this.jarPath == null) {
return false;
}

try {
NamingEnumeration<Binding> bindings = jndiResources.listBindings(this.jarPath);
length = jarNames.size();
NamingEnumeration<Binding> bindings = jndiResources.listBindings(WEB_INF_LIB);
int i = 0;
while (bindings.hasMoreElements() && i < length) {
NameClassPair ncPair = bindings.nextElement();
Expand Down Expand Up @@ -660,7 +653,7 @@ public boolean modified() {
return true;
}
} catch (NamingException | ClassCastException e) {
LOG.log(ERROR, LogFacade.FAILED_TRACKING_MODIFICATIONS, this.jarPath, e.getMessage());
LOG.log(ERROR, LogFacade.FAILED_TRACKING_MODIFICATIONS, WEB_INF_LIB, e.getMessage());
}

// No classes have been modified
Expand Down Expand Up @@ -1216,7 +1209,6 @@ public void close() throws IOException {
jndiResources = null;
repositoryManager.close();
repositoryURLs = null;
jarPath = null;
jarNames.clear();
lastModifiedDates = null;
paths = null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -982,19 +982,15 @@ private void setRepositories() throws IOException {
}

// Setting up the JAR repository (/WEB-INF/lib), if it exists

String libPath = "/WEB-INF/lib";

classLoader.setJarPath(libPath);

String libPath = classLoader.getLibJarPath();
DirContext libDir = null;
// Looking up directory /WEB-INF/lib in the context
try {
Object object = resources.lookup(libPath);
if (object instanceof DirContext) {
libDir = (DirContext) object;
}
} catch(NamingException e) {
} catch (NamingException e) {
// Silent catch: it's valid that no /WEB-INF/lib collection
// exists
}
Expand Down

0 comments on commit efd9ab4

Please sign in to comment.