Skip to content

Commit 4beb0fc

Browse files
committed
Fixed path resolution in CommonClassLoaderServiceImpl
- Original code broke when path contained spaces - Added validation of the path before it was added anywhere. - Note that FileUtils.toFile throws IAE when the path is empty too, however this code is now probably unreachable because of the validation. Signed-off-by: David Matějček <[email protected]>
1 parent e275229 commit 4beb0fc

File tree

1 file changed

+17
-8
lines changed

1 file changed

+17
-8
lines changed

nucleus/core/kernel/src/main/java/com/sun/enterprise/v3/server/CommonClassLoaderServiceImpl.java

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2022, 2024 Contributors to the Eclipse Foundation
2+
* Copyright (c) 2022, 2025 Contributors to the Eclipse Foundation
33
* Copyright (c) 2007, 2018 Oracle and/or its affiliates. All rights reserved.
44
*
55
* This program and the accompanying materials are made available under the
@@ -19,6 +19,7 @@
1919

2020
import com.sun.enterprise.module.bootstrap.StartupContext;
2121
import com.sun.enterprise.util.SystemPropertyConstants;
22+
import com.sun.enterprise.util.io.FileUtils;
2223

2324
import jakarta.inject.Inject;
2425

@@ -32,7 +33,6 @@
3233
import java.util.Collections;
3334
import java.util.List;
3435
import java.util.Properties;
35-
import java.util.function.Predicate;
3636
import java.util.jar.JarFile;
3737
import java.util.jar.Manifest;
3838
import java.util.logging.Level;
@@ -159,6 +159,7 @@ public ClassLoader getCommonClassLoader() {
159159
* @throws UnsupportedOperationException If adding not supported by the classloader
160160
*/
161161
public void addToClassPath(URL url) {
162+
validateUrl(url);
162163
if (commonClassLoader == null) {
163164
commonClassLoader = new GlassfishUrlClassLoader(new URL[] {url}, APIClassLoader);
164165
} else {
@@ -171,13 +172,21 @@ public String getCommonClassPath() {
171172
return commonClassPath;
172173
}
173174

175+
private static URL validateUrl(URL url) {
176+
if (url == null) {
177+
throw new IllegalArgumentException("URL cannot be null");
178+
}
179+
if (!url.getProtocol().equalsIgnoreCase("file")) {
180+
throw new IllegalArgumentException("URL must be a file URL");
181+
}
182+
if (url.getPath().isEmpty()) {
183+
throw new IllegalArgumentException("URL path cannot be empty");
184+
}
185+
return url;
186+
}
187+
174188
private static String urlsToClassPath(Stream<URL> urls) {
175-
return urls
176-
.map(URL::getFile)
177-
.filter(Predicate.not(String::isBlank))
178-
.map(File::new)
179-
.map(File::getAbsolutePath)
180-
.collect(Collectors.joining(File.pathSeparator));
189+
return urls.map(FileUtils::toFile).map(File::getAbsolutePath).collect(Collectors.joining(File.pathSeparator));
181190
}
182191

183192
private List<File> findDerbyClient() {

0 commit comments

Comments
 (0)