[
https://issues.apache.org/jira/browse/IMAGING-359?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
]
Marcono1234 updated IMAGING-359:
--------------------------------
Description:
The unit tests contain a lot of code which obtains a {{URL}} from
{{Class.getResource(String)}}, and then calls {{URL.getFile()}} to use that as
file path.
The problem is that, despite sounding similar, {{URL.getFile()}} is completely
unrelated to file paths and actually returns an URL encoded value. So what this
means is that you encounter a lot of test failures due to
{{NoSuchFileException}} if you have the project in a directory with space (or
non-ASCII characters?) in its file path.
The solution is to call {{URL.toURI()}} and then either {{new File(URI)}} or
{{Paths.get(URI)}} (respectively {{Path.of(URI)}}).
Maybe a separate helper method shared by all test code is needed for this
because {{toURI}} unfortunately throws a checked {{URISyntaxException}}.
was:
The unit tests contain a lot of code which obtains a {{URL}} from
{{Class.getResource(String)}}, and then calls {{URL.getFile()}} to use that as
file path.
The problem is that, despite sounding similar, {{URL.getFile()}} is completely
unrelated to file paths and actually returns an URL encoded value. So what this
means is that you encounter a lot of test failures due to
{{NoSuchFileException}} if you have the project in a directory with space or
non-ASCII characters in its file path.
The solution is to call {{URL.toURI()}} and then either {{new File(URI)}} or
{{Paths.get(URI)}} (respectively {{Path.of(URI)}}).
Maybe a separate helper method shared by all test code is needed for this
because {{toURI}} unfortunately throws a checked {{URISyntaxException}}.
> Faulty usage of URL.getFile() in tests
> --------------------------------------
>
> Key: IMAGING-359
> URL: https://issues.apache.org/jira/browse/IMAGING-359
> Project: Commons Imaging
> Issue Type: Bug
> Reporter: Marcono1234
> Priority: Major
>
> The unit tests contain a lot of code which obtains a {{URL}} from
> {{Class.getResource(String)}}, and then calls {{URL.getFile()}} to use that
> as file path.
> The problem is that, despite sounding similar, {{URL.getFile()}} is
> completely unrelated to file paths and actually returns an URL encoded value.
> So what this means is that you encounter a lot of test failures due to
> {{NoSuchFileException}} if you have the project in a directory with space (or
> non-ASCII characters?) in its file path.
> The solution is to call {{URL.toURI()}} and then either {{new File(URI)}} or
> {{Paths.get(URI)}} (respectively {{Path.of(URI)}}).
> Maybe a separate helper method shared by all test code is needed for this
> because {{toURI}} unfortunately throws a checked {{URISyntaxException}}.
--
This message was sent by Atlassian Jira
(v8.20.10#820010)