Skip to content

Commit

Permalink
Avoid crashing due to FileSystemNotFound while behind a Spring boot e…
Browse files Browse the repository at this point in the history
…mbedded JAR
  • Loading branch information
ctabin committed Oct 13, 2023
1 parent 6cf5bfe commit f566d17
Showing 1 changed file with 19 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -43,31 +43,23 @@

import com.sun.enterprise.module.HK2Module;
import com.sun.enterprise.module.ModulesRegistry;
import com.sun.enterprise.util.io.FileUtils;
import org.glassfish.api.deployment.DeployCommandParameters;
import org.glassfish.api.deployment.DeploymentContext;
import org.glassfish.hk2.api.ServiceLocator;
import org.glassfish.internal.api.ClassLoaderHierarchy;
import org.glassfish.internal.data.ApplicationRegistry;
import org.glassfish.internal.data.ApplicationInfo;
import org.glassfish.api.admin.ServerEnvironment;
import com.sun.enterprise.deployment.deploy.shared.Util;
import com.sun.enterprise.util.OS;
import java.io.File;
import java.io.FileFilter;
import java.io.IOException;
import java.io.InputStream;
import java.io.FileInputStream;
import java.net.MalformedURLException;
import java.net.URI;
import java.net.URISyntaxException;
import java.net.URL;
import java.nio.file.FileSystemNotFoundException;
import java.nio.file.Paths;
import java.util.logging.Level;
import java.util.logging.Logger;
import java.util.logging.LogRecord;
import java.util.jar.Manifest;
import java.util.jar.Attributes;
import java.util.*;

import org.glassfish.logging.annotation.LogMessageInfo;
Expand Down Expand Up @@ -254,26 +246,38 @@ private static synchronized String getModulesClasspath(ServiceLocator habitat) {
if (mr != null) {
for (HK2Module module : mr.getModules()) {
for (URI uri : module.getModuleDefinition().getLocations()) {
if (uri.toString().startsWith("reference:")) {
String uriString = uri.toString();
if (uriString.startsWith("reference:")) {
try {
// OSGi modules can have "reference:" prepended to them if they're exploded, except
// there doesn't appear to be an actual FileSystemProvider for this type
tmpString.append(new URI(uri.toString().substring("reference:".length())));
tmpString.append(new URI(uriString.substring("reference:".length())));
tmpString.append(File.pathSeparator);
} catch (URISyntaxException use) {
deplLogger.log(Level.WARNING,
"Error truncating URI with prefix of \"reference:\"",
use);
}
} else if (uri.toString().startsWith("jardir:")) {
} else if (uriString.startsWith("jardir:")) {
// OSGi fileinstall created modules can have a "jardir:" schema for directory
// structures, but there is no FileSystemProvider for this type.
// Since the path is the file system path, just substitute the "file:" schema
tmpString.append("file:").append(uri.toString().substring("jardir:".length()));
tmpString.append("file:").append(uriString.substring("jardir:".length()));
tmpString.append(File.pathSeparator);
} else if (uriString.startsWith("jar:")) {
// In Spring Boot application, the URIs are pointing to embedded JARs in a JAR,
// resulting in a FileSystemNotFoundException when parsed with Paths.get(...)
deplLogger.log(Level.INFO, "The URI has been ignored: {0}", uriString);
} else {
tmpString.append(Paths.get(uri).toString());
tmpString.append(File.pathSeparator);
try {
tmpString.append(Paths.get(uri).toString());
tmpString.append(File.pathSeparator);
} catch(FileSystemNotFoundException fsNotFound) {
LogRecord logRecord = new LogRecord(Level.WARNING, "Unable to add the URI in the classpath: {0}");
logRecord.setParameters(new Object[]{uri});
logRecord.setThrown(fsNotFound);
deplLogger.log(logRecord);
}
}
}
}
Expand Down

0 comments on commit f566d17

Please sign in to comment.