Skip to content

Commit 72284b6

Browse files
committed
"java.class.path" uses an incorrect separator #107
1 parent c665ca5 commit 72284b6

File tree

4 files changed

+36
-3
lines changed

4 files changed

+36
-3
lines changed

RELEASE-NOTES.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
* #67 JJAVA_STARTUP_SCRIPT can't start up spark
44
* #102 Eval startup snippets explicitly
55
* #105 Exploding classpath
6+
* #107 "java.class.path" uses an incorrect separator
67

78
## 1.0-a6
89

jjava-kernel/src/main/java/org/dflib/jjava/kernel/execution/JJavaLoaderDelegate.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
public class JJavaLoaderDelegate implements LoaderDelegate {
1616

1717
private static final String CLASSPATH_PROPERTY = "java.class.path";
18+
private static final String PATH_SEPARATOR = System.getProperty("path.separator");
1819

1920
private final Map<String, byte[]> declaredClasses;
2021
private final Map<String, Class<?>> loadedClasses;
@@ -57,9 +58,10 @@ public void addToClasspath(String path) throws ExecutionControl.InternalExceptio
5758
try {
5859
classLoader.addURL(Path.of(next).toUri().toURL());
5960

60-
String classpath = System.getProperty(CLASSPATH_PROPERTY);
61-
classpath += System.lineSeparator() + next;
62-
System.setProperty(CLASSPATH_PROPERTY, classpath);
61+
System.setProperty(
62+
CLASSPATH_PROPERTY,
63+
System.getProperty(CLASSPATH_PROPERTY) + PATH_SEPARATOR + next);
64+
6365
} catch (MalformedURLException e) {
6466
throw new ExecutionControl.InternalException("Unable to resolve classpath " + next
6567
+ ": " + e.getMessage());
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
package org.dflib.jjava.kernel;
2+
3+
import jdk.jshell.spi.ExecutionControl;
4+
import org.dflib.jjava.kernel.execution.JJavaLoaderDelegate;
5+
import org.junit.jupiter.api.Test;
6+
7+
import java.io.File;
8+
import java.net.URISyntaxException;
9+
10+
import static org.junit.jupiter.api.Assertions.*;
11+
12+
public class JJavaLoaderDelegateTest {
13+
14+
@Test
15+
public void addToClasspath() throws URISyntaxException, ExecutionControl.InternalException {
16+
File extraCp = new File(getClass().getResource("cp").toURI());
17+
assertTrue(extraCp.isDirectory());
18+
19+
JJavaLoaderDelegate ld = new JJavaLoaderDelegate();
20+
21+
String cp1 = System.getProperty("java.class.path");
22+
23+
ld.addToClasspath(extraCp.getAbsolutePath());
24+
String cp2 = System.getProperty("java.class.path");
25+
assertEquals(cp1 + System.getProperty("path.separator") + extraCp.getAbsolutePath(), cp2);
26+
27+
// TODO: test that classes from this location were actually loaded
28+
}
29+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# placeholder to keep the empty directory in version control

0 commit comments

Comments
 (0)