Symbol ``['' and a java.net.URI.create method

Christopher Hegarty - Sun Microsystems Ireland Christopher.Hegarty at Sun.COM
Tue Apr 29 09:21:43 PDT 2008


The square bracket characters ('[' and ']') are reserved characters in a 
URI. If they are to be used then they need to percent encoded. That is, 
'[' is percent encoded to be %5B.

The single argument java.net.URI constructor requires any illegal 
characters in its argument to be quoted and preserves any escaped octets 
and other characters that are present. The static create method simply 
invokes the URI(String) constructor, with some extra Exception handling. 
Therefore any reserved characters need to be percent encoded before 
passing the String as an argument.

You can look at the java.net.URI class description to give you a better 
understanding of how this encoding works.

-Chris.

Christopher Hegarty - Sun Microsystems Ireland wrote:
> Since this is a question about java.net.URI I am moving this question to 
> the OpenJDK Net Dev alias.
> 
> I will try to answer it there.
> 
> -Chris.
> 
> Michal Vyskocil wrote:
>> Hi all,
>>
>> I'm working on adopting of jpackage project to openSUSE and got a 
>> problem with build of maven. The jpackage's folks have a script 
>> build-jar-repository, which symlinks the jar files in /usr/share/java 
>> to defined dir.
>>
>> My problem is, that the script produces a links in this form - 
>> /foo/bar/[ant].jar which later causes an IllegalArgumentException, 
>> because a java.net.URI.create dissallows ``[]'' in URI. The response 
>> from jpackage is, that java.net.URI.create has a bug, because symbol 
>> ``['' is valid in a Unix path.
>>
>>
>> I'm testing several JRE implementations, but only gcj allows the 
>> ``[]'' in URI, other ones not.
>>
>> What do you think about? Is this really a bug in handling of unix 
>> filenames?
>>
>> Regards
>> Michal Vyskocil



More information about the net-dev mailing list