Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

A network request is not being handled on failure #455

Open
amazuerar opened this issue Aug 13, 2021 · 0 comments
Open

A network request is not being handled on failure #455

amazuerar opened this issue Aug 13, 2021 · 0 comments

Comments

@amazuerar
Copy link

Dear Developer!

My name is Alejandro Mazuera-Rozo, I am a PhD Student at Universidad de los Andes, and at Università della Svizzera italiana. I am part of a research on the usage of network libraries within Android apps. As result of this we identified some code locations that might have network related problems.

In this case, we address the code locations that are related to a network request which is not being assessed on failure. In order to avoid misbehaviour when performing network operations it is recommended to handle failure scenarios.

In order to address this issue we recommend:

  1. To implement the catch statement in which one defines a block of code to be executed if an error occurs.

Potential Code Location not handling failure scenarios when performing a network request

try {
URL url = new URL("http://nilsbraden.de/android/tt-rss/minSupportedVersion.txt");
HttpURLConnection con = (HttpURLConnection) url.openConnection(Proxy.NO_PROXY);
con.connect();
int code = con.getResponseCode();
if (code < 400 || code >= 600) {
BufferedReader br = new BufferedReader(new InputStreamReader(con.getInputStream()));
String content = br.readLine(); // Just read one line!
// Only ever read the integer if it matches the regex and is not too long
if (content.matches("[0-9]*[\\r\\n]*")) {
content = content.replaceAll("[^0-9]*", "");
Controller.getInstance().setAppLatestVersion(Integer.parseInt(content));
}
}
} catch (Exception e) {
// Empty!
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant