GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — requestImage crashes app when URL file cannot be found · Issue #727 · processing/processing-android

requestImage crashes app when URL file cannot be found #727

New issue
Copy link
New issue
Copy link
Open
Open
requestImage crashes app when URL file cannot be found#727
Copy link
Labels
bugcore

Description

@ajavamind
ajavamind
opened on Feb 15, 2023
Issue body actions

I came across this error and found a solution.

Here is test code to create the problem

///////////////////////////////////////////////////
// requestImage test
PImage img;
boolean go = true;

void setup() {
size(800, 600);
}

void draw() {
if (go) {
//img = requestImage("http://192.168.0.112/DCIM/100PHOTO/SAM_0001.JPG"); // Loads the image from server successfully
img = requestImage("http://192.168.0.112/DCIM/PHOTO/SAM_0001.JPG"); // App crashes with exception
// java.lang.IllegalArgumentException: File http://192.168.0.112/DCIM/PHOTO/SAM_0001.JPG contains a path separator
go = false;
}
float ar = (float)img.width/(float)img.height;
if (img != null && img.width > 0 && img.height > 0) {
image(img, 0, 0, width, (float)width/ar);
} else {
text("Error ", width/2, height/2);
}
}
void mousePressed() {
go = true;
}
///-----------------------------------------------------------------

Process: processing.test.requestimagetest, PID: 8066
java.lang.IllegalArgumentException: File http://192.168.0.112/DCIM/PHOTO/SAM_0001.JPG contains a path separator
at android.app.ContextImpl.makeFilename(ContextImpl.java:2484)
at android.app.ContextImpl.getFileStreamPath(ContextImpl.java:699)
at android.content.ContextWrapper.getFileStreamPath(ContextWrapper.java:216)
at android.content.ContextWrapper.getFileStreamPath(ContextWrapper.java:216)
at processing.core.PSurfaceNone.getFileStreamPath(PSurfaceNone.java:319)
at processing.core.PApplet.sketchPath(PApplet.java:5506)
at processing.core.PApplet.createInputRaw(PApplet.java:5031)
at processing.core.PApplet.createInput(PApplet.java:4863)
at processing.core.PApplet.loadImage(PApplet.java:4003)
at processing.core.PApplet$AsyncImageLoader.run(PApplet.java:4076)

In PApplet.java createInputRaw() null is not returned when the file cannot be found causing expectation for non-URL filename

line 4879
/**

  • Call createInput() without automatic gzip decompression.
    */
    public InputStream createInputRaw(String filename) {
    // Additional considerations for Android version:
    // http://developer.android.com/guide/topics/resources/resources-i18n.html
    InputStream stream = null;
if (filename == null) return null;

if (filename.length() == 0) {
  // an error will be called by the parent function
  //System.err.println("The filename passed to openStream() was empty.");
  return null;
}

// safe to check for this as a url first. this will prevent online
// access logs from being spammed with GET /sketchfolder/http://blahblah
if (filename.indexOf(":") != -1) {  // at least smells like URL
  try {
    // Workaround for Android bug 6066
    // http://code.google.com/p/android/issues/detail?id=6066
    // http://code.google.com/p/processing/issues/detail?id=629

// URL url = new URL(filename);
// stream = url.openStream();
// return stream;
URL url = new URL(filename);
HttpURLConnection con = (HttpURLConnection) url.openConnection();
con.setRequestMethod("GET");
con.setDoInput(true);
con.connect();
return con.getInputStream();
//The following code is deprecaded by Android
// HttpGet httpRequest = null;
// httpRequest = new HttpGet(URI.create(filename));
// HttpClient httpclient = new DefaultHttpClient();
// HttpResponse response = (HttpResponse) httpclient.execute(httpRequest);
// HttpEntity entity = response.getEntity();
// return entity.getContent();
// can't use BufferedHttpEntity because it may try to allocate a byte
// buffer of the size of the download, bad when DL is 25 MB... [0200]
// BufferedHttpEntity bufHttpEntity = new BufferedHttpEntity(entity);
// return bufHttpEntity.getContent();

  } catch (MalformedURLException mfue) {
    // not a url, that's fine

**************************may need return null; // if it is really a URL it needs return null
} catch (FileNotFoundException fnfe) {
// Java 1.5 likes to throw this when URL not available. (fix for 0119)
// http://dev.processing.org/bugs/show_bug.cgi?id=403
**************************needs return null; // because this URL could not find the file, go no further
} catch (IOException e) {
// changed for 0117, shouldn't be throwing exception
printStackTrace(e);
//System.err.println("Error downloading from URL " + filename);
return null;
//throw new RuntimeException("Error downloading from URL " + filename);
}
}

Activity

  1. codeanticode commented on Mar 20, 2023

    @codeanticode
    codeanticode
    on Mar 20, 2023
    Contributor
    More actions

    @ajavamind Thanks for bringing this up and suggesting a fix. I will tag it for inclusion in the next release.

  2. codeanticode
    added
    bug
    core
    on Mar 20, 2023
  3. codeanticode
    added this to the 4.5.1 bugfixes milestone on Mar 20, 2023
  4. codeanticode
    removed this from the 4.6 bugfixes milestone on Jun 10, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugcore

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

      You are visitor 01402503 — GeezerVison does not store the pages you look up.
      Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.