Shikhar13 / codenameone

Automatically exported from code.google.com/p/codenameone
0 stars 0 forks source link

J2ME implementation: public boolean exists(String file) should catch IllegalArgumentException #197

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
I try to load a file from jar. The CN1 first checks for a file like that:

 public Object createImage(String path) throws IOException {
        if(exists(path)){
            InputStream is = null;
            try {
                is = openInputStream(path);
                return createImage(is);
            } finally {
                is.close();
            }
        }
        return javax.microedition.lcdui.Image.createImage(path);
    }

which I totally disagree with, but anyway,

 public boolean exists(String file) throws an illegalargument exception:

'Did not find ':' in the path.

Thats because I did not intend to load it from file! (and so now you know my 
disagreement).

Anyway changing the function to such works:
 public boolean exists(String file) {
        FileConnection fc = null;
        try {
            fc = (FileConnection)Connector.open(file, Connector.READ);
            return fc.exists();
        } catch(IllegalArgumentException err) {
            return false;
        } catch(IOException err) {
            return false;
        } finally {
            cleanup(fc);
        }
    }

Original issue reported on code.google.com by jkoo...@gmail.com on 25 May 2012 at 2:03

GoogleCodeExporter commented 9 years ago
Assigning to Chen

Original comment by shai.almog on 25 May 2012 at 4:37

GoogleCodeExporter commented 9 years ago
not sure against what code are you working with, the implementation code in the 
svn is:

    public Object createImage(String path) throws IOException {
        if(path.startsWith("file:") && exists(path)){
            InputStream is = null;
            try {
                is = openInputStream(path);
                return createImage(is);
            } finally {
                is.close();
            }
        }
        return javax.microedition.lcdui.Image.createImage(path);
    }

Original comment by cf27...@gmail.com on 26 May 2012 at 5:00

GoogleCodeExporter commented 9 years ago
the current code is fixed

Original comment by cf27...@gmail.com on 28 May 2012 at 7:18

GoogleCodeExporter commented 9 years ago
yup, checked. the latest has the fix in. thanks! :)

Original comment by jkoo...@gmail.com on 28 May 2012 at 1:29