This is the mail archive of the java-patches@gcc.gnu.org mailing list for the Java project.
| Index Nav: | [Date Index] [Subject Index] [Author Index] [Thread Index] | |
|---|---|---|
| Message Nav: | [Date Prev] [Date Next] | [Thread Prev] [Thread Next] |
| Other format: | [Raw text] | |
Sorry, I accidentally sent this email with the main body as an attachment(!). Here it is again: ----- Forwarded message from Robin Green <greenrd@greenrd.org> ----- Date: Mon, 6 Dec 2004 00:22:16 +0000 To: java-patches@gcc.gnu.org Subject: [patch] File.toURI creates bogus URI Hi list, Please apply the attached 1-line patch, which fixes this issue: The way Sun recommends to turn a File object into a URL is to do file.toURI().toURL() so that proper URL escaping is done. However, the URL produced in this way in libgcj doesn't work if you want to open a connection to it, or pass it to a URLClassLoader. 2004-12-06 Robin Green <greenrd@greenrd.org> * java/io/File.java (toURI): Generate a URI which we understand I hope this email is correct - I'm not a committer so I don't know whether to put my name at the top of the changelog entry. Test case also attached. -- Robin
--- java/io/File.java.orig 2004-12-05 22:06:50.256675952 +0000
+++ java/io/File.java 2004-12-05 22:56:57.640484120 +0000
@@ -936,7 +936,7 @@
try
{
- return new URI("file", "", abspath.replace(separatorChar, '/'));
+ return new URI("file", abspath.replace(separatorChar, '/'), null);
}
catch (URISyntaxException use)
{
import java.io.*;
import java.net.*;
public class FileURLTest
{
public static void main(String args []) throws Exception
{
File f = File.createTempFile("test", null);
// This was to test that the fix works without having to recompile gcj
//test(new FixedFile(f));
// Test the real implementation
test(f);
}
public static void test(File f) throws Exception
{
f.deleteOnExit();
System.out.println("-------------------------------------");
System.out.println(f.getClass() + ": " + f.toString());
System.out.println();
System.out.println("File.toURL creates a URL which CAN be opened:");
URL url = f.toURL();
System.out.println(url);
test(url);
System.out.println();
System.out.println("File.toURI may create a URI which CAN'T be opened - if so an exception will be thrown:");
URI uri = f.toURI();
System.out.println(uri);
System.out.println("Fragment: " + uri.getFragment());
test(uri.toURL());
}
private static void test(URL url) throws IOException {
System.out.println("Anchor: " + url.getRef());
System.out.println("Stream: " + url.openStream());
}
}
Attachment:
pgp00000.pgp
Description: PGP signature
| Index Nav: | [Date Index] [Subject Index] [Author Index] [Thread Index] | |
|---|---|---|
| Message Nav: | [Date Prev] [Date Next] | [Thread Prev] [Thread Next] |