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

Usman Ashraf Bajwah edited comment on VFS-840 at 7/26/23 9:28 AM:
------------------------------------------------------------------

The problem here is not with resolvefile method. it is correctly working as per 
my understanding. The issue lies with getPath() method which is not encoding 
the URI while converting it to get the Path. Resolving with your method may be 
good if we have known directory from which we need to get the files. But my 
scenario is different.

 

If I use your method still getPath giving me same error.

 

A path is given to the application which can be a local file system path, over 
the network or UNC path. I have to get all the folders and files and collect 
the information and then pass some of the files to another program/api for 
further processing. Using apache VFS so we could include other schemes as well 
in future. The easiest way for me is to give this path to get FileObject and 
then hierarchically get the Path and other information. It is working fine but 
when there are special characters in that its failing.


was (Author: JIRAUSER301519):
The problem here is not with resolvefile method. it is correctly working as per 
my understanding. The issue lies with getPath() method which is not encoding 
the URI while converting it to get the Path. Resolving with your method may be 
good if we have known directory from which we need to get the files. But my 
scenario is different.

A path is given to the application which can be a local file system path, over 
the network or UNC path. I have to get all the folders and files and collect 
the information and then pass some of the files to another program/api for 
further processing. Using apache VFS so we could include other schemes as well 
in future. The easiest way for me is to give this path to get FileObject and 
then hierarchically get the Path and other information. It is working fine but 
when there are special characters in that its failing.

> IllegalArgumentException when using special characters in filename eg [ or ] 
> and calling FileObject.getPath method
> ------------------------------------------------------------------------------------------------------------------
>
>                 Key: VFS-840
>                 URL: https://issues.apache.org/jira/browse/VFS-840
>             Project: Commons VFS
>          Issue Type: Bug
>    Affects Versions: 2.9.0
>         Environment: Windows 10
> Java 17
> Apache VFS 2.9.0
>            Reporter: Usman Ashraf Bajwah
>            Priority: Major
>
> When special characters ([ or ] for example there might be others also) are 
> used in filename FileObject resolve it alright but calling its getPath method 
> fails with following exception.
>  
> +java.lang.IllegalArgumentException+{color:#ff0000}: Illegal character in 
> path at index 17: file:///D:/citrus[1].jpg{color}
> {color:#ff0000} at 
> java.base/java.net.URI.create({color}+URI.java:906+{color:#ff0000}){color}
> {color:#ff0000} at 
> org.apache.commons.vfs2.FileObject.getURI({color}+FileObject.java:310+{color:#ff0000}){color}
> {color:#ff0000} at 
> org.apache.commons.vfs2.FileObject.getPath({color}+FileObject.java:320+{color:#ff0000}){color}
> {color:#ff0000} at 
> com.gallerysystems.tms.common.util.FileUtil.main({color}+FileUtil.java:859+{color:#ff0000}){color}
> {color:#ff0000}Caused by: 
> {color}+java.net.URISyntaxException+{color:#ff0000}: Illegal character in 
> path at index 17: file:///D:/citrus[1].jpg{color}
> {color:#ff0000} at 
> java.base/java.net.URI$Parser.fail({color}+URI.java:2974+{color:#ff0000}){color}
> {color:#ff0000} at 
> java.base/java.net.URI$Parser.checkChars({color}+URI.java:3145+{color:#ff0000}){color}
> {color:#ff0000} at 
> java.base/java.net.URI$Parser.parseHierarchical({color}+URI.java:3227+{color:#ff0000}){color}
> {color:#ff0000} at 
> java.base/java.net.URI$Parser.parse({color}+URI.java:3175+{color:#ff0000}){color}
> {color:#ff0000} at 
> java.base/java.net.URI.<init>({color}+URI.java:623+{color:#ff0000}){color}
> {color:#ff0000} at 
> java.base/java.net.URI.create({color}+URI.java:904+{color:#ff0000}){color}
> {color:#ff0000} ... 3 more{color}
>  
> Following is the code to reproduce the issue.
> {color:#7f0055}try{color}{color:#000000} {{color}
> {color:#000000} String {color}{color:#6a3e3e}fileName{color}{color:#000000} = 
> {color}{color:#2a00ff}"D:\\citrus[1].jpg"{color}{color:#000000};{color}
> {color:#000000} FileSystemManager 
> {color}{color:#6a3e3e}fsManager{color}{color:#000000} = 
> VFS.{color}{color:#000000}getManager{color}{color:#000000}();{color}
> {color:#000000} FileObject 
> {color}{color:#6a3e3e}fileObject{color}{color:#000000} = 
> {color}{color:#6a3e3e}fsManager{color}{color:#000000}.resolveFile({color}{color:#6a3e3e}fileName{color}{color:#000000});{color}
> {color:#000000} 
> System.{color}{color:#0000c0}out{color}{color:#000000}.println({color}{color:#6a3e3e}fileObject{color}{color:#000000}.getPath());{color}
> {color:#000000} }{color}{color:#7f0055}catch{color}{color:#000000}(Exception 
> {color}{color:#6a3e3e}ex{color}{color:#000000}) {{color}
> {color:#000000} 
> {color}{color:#6a3e3e}ex{color}{color:#000000}.printStackTrace();{color}
> {color:#000000} }{color}



--
This message was sent by Atlassian Jira
(v8.20.10#820010)

Reply via email to