You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@maven.apache.org by "M.P. Korstanje (Jira)" <ji...@apache.org> on 2020/12/30 01:33:00 UTC

[jira] [Commented] (SUREFIRE-1869) Classloader.getResource() doesn't encode blanks with forkCount=0

    [ https://issues.apache.org/jira/browse/SUREFIRE-1869?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17256221#comment-17256221 ] 

M.P. Korstanje commented on SUREFIRE-1869:
------------------------------------------

Worth nothing that:

1. The test case only fails when running tests in-process. The test case does not fail when forking the jvm.

2. This happens because the isolated class loader urls are constructed from the absolute path here:

[https://github.com/apache/maven-surefire/blob/master/surefire-booter/src/main/java/org/apache/maven/surefire/booter/Classpath.java#L149]


{code:java}
 classLoader.addURL( new File( classPathElement ).toURL() );{code}

And then turned into URLS here:



[https://github.com/apache/maven-surefire/blob/master/surefire-booter/src/main/java/org/apache/maven/surefire/booter/Classpath.java#L149]

 
{code:java}
classLoader.addURL( new File( classPathElement ).toURL() );{code}

Following [https://bugs.openjdk.java.net/browse/JDK-6227069] this should probably be: 
{code:java}
classLoader.addURL( new File( classPathElement ).toURI().toURL() );{code}

> Classloader.getResource() doesn't encode blanks with forkCount=0
> ----------------------------------------------------------------
>
>                 Key: SUREFIRE-1869
>                 URL: https://issues.apache.org/jira/browse/SUREFIRE-1869
>             Project: Maven Surefire
>          Issue Type: Bug
>    Affects Versions: 2.20, 2.22.2, 3.0.0-M5
>            Reporter: René Kraneis
>            Priority: Major
>
> We found this bug when running cucumber tests, having project paths with spaces and forkCount set to 0 (see [https://github.com/cucumber/cucumber-jvm/issues/2196] for the but report there). A minimal reproducing example would be
> {code:java}
> $ pwd
> /home/rene/Projects/path with space/classpath test{code}
> {code:java}
> $ tree
> .
> ├── pom.xml
> └── src
>     └── test
>         └── java
>             └── ClassPathTest.java{code}
> {code:java}
> $ cat src/test/java/ClassPathTest.java
> import java.io.IOException;
> import java.net.URI;
> import java.net.URISyntaxException;
> public class ClassPathTest {
>   public void testClassPath() throws IOException, URISyntaxException {
>     URI uri = ClassPathTest.class.getClassLoader()
>       .getResources(".")
>       .nextElement()
>       .toURI();
>       System.out.println(uri);
>   }
> }{code}
> {code:java}
> $ mvn clean test -DforkCount=0
> ...
> [INFO] --- maven-surefire-plugin:2.20:test (default-test) @ ClassPathTest ---
> [WARNING] useSystemClassloader setting has no effect when not forking
> [INFO] Running ClassPathTest
> [ERROR] Tests run: 1, Failures: 1, Errors: 0, Skipped: 0, Time elapsed: 0.002 s <<< FAILURE! - in ClassPathTest
> [ERROR] ClassPathTest.testClassPath()  Time elapsed: 0.001 s  <<< FAILURE!
> java.net.URISyntaxException: Illegal character in path at index 29: file:/home/rene/Projects/path with space/classpath test/target/test-classes/
> 	at java.net.URI$Parser.fail(URI.java:2848)
> 	at java.net.URI$Parser.checkChars(URI.java:3021)
> 	at java.net.URI$Parser.parseHierarchical(URI.java:3105)
> 	at java.net.URI$Parser.parse(URI.java:3053)
> 	at java.net.URI.<init>(URI.java:588)
> 	at java.net.URL.toURI(URL.java:964)
> 	at ClassPathTest.testClassPath(ClassPathTest.java:13)
> ...
> {code}
> Last working version of surefire is 2.19.1. The build does not contain any additional dependencies and relies on pojo test execution. The same problem also happens when running tests with junit, junit vintage or junit platform.



--
This message was sent by Atlassian Jira
(v8.3.4#803005)