#47 Can't put URLs on command line

closed-fixed
parsing (14)
7
2002-06-21
2002-02-15
No

It is not possible to put a URL on the command line
with some JREs. This is because (in those JREs) java.io.File doesn't understand URLs, and strips out what it thinks are extraneous /s, breaking the URL syntax. For example

http://internal.synaptics.com/apps/config.jnlp

becomes

http:/internal.synaptics.com/apps/config.jnlp

Since this isn't what the JRE expects for URL, some portion of the classpath will get appended to it, presenting instead
someting like
/home/cheiny/projects/http:/internal.synaptics.com/apps/config.jnlp
which is unlikely to be loadable.

I've checked this against several JREs under Linux:
Sun 1.4.0 - breaks
Sun 1.3.1 - breaks
Sun 1.3 - hangs
Kaffe 1.0.6 - works

It would probably be a much better idea for handleOpenFile to accept java.net.URL instead of java.io.File. This appears to work reliably across the JREs I checked.

Here's a test program:
-----------------------------------

* FTest.java
*
* Created on February 14, 2002, 7:01 PM
*/

import java.io.File;
import java.net.URL;

/**
*
* @author cheiny
* @version
*/
public class FTest {

/** Creates new FTest */
public FTest() {
}

/**
* @param args the command line arguments
*/
public static void main (String args[]) {
if ( args.length != 1 ) {
System.err.println ( "I expect only one arg!" );
System.exit(-1);
}
String fn = new String ( args[0] );
File f = new File ( fn );
System.out.println ( "fn " + fn );
System.out.println ( "f " + f );
try {
URL u = new URL ( fn );
System.out.println ( "url " + u );
} catch ( java.net.MalformedURLException x ) {
System.err.println ( "Failed to create URL " + x.getMessage() );
x.printStackTrace();
}

System.exit(0);
}

}

Discussion

    • priority: 5 --> 7
     
  • Logged In: YES
    user_id=6750

    org.nanode.jnlp.JNLPParser.main() handles this, it is designed to take URLs on the command line (it's how external launching is done).

    I don't understand why command line arguments would be wrapped in java.io.File. They should be wrapped in java.net.URL directly. I suggest something like this:

    public static void main(String[] args) {
    URL u = null;

    try {
    u = new URL(args[0]);
    } catch (MalformedURLException e) { }

    if (u == null) {
    try {
    u = new File(args[0]).toURL();
    } catch (MalformedURLException e) {
    Sytem.err.println("bad URL: " + arg[0]);
    }
    }

    if (u != null) {
    System.out.println("URL is " + u);
    }

    System.exit(0);
    }

     
    • assigned_to: nobody --> clheiny
     
  • Logged In: YES
    user_id=117164

    From the command line, everything is handled as a URL. Plain
    filenames are converted to fully qualified "file:/" URLs before
    being loaded. All other URLs (http, ftp, and file) are passed
    without change.

     
    • status: open --> open-fixed
     
  • Logged In: YES
    user_id=6750

    Changed so every non-option argument is tried as a URL first, and if it can't be used to create a URL then it is opened as a file.

     
    • status: open-fixed --> closed-fixed