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 these issues we recommend:
- To add a
try
statement allowing you to define a block of code to be assessed while being executed.
- To implement a
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
There is no try-catch
statement handling the openConnection()
request in:
|
connection = (HttpURLConnection) new URL(url).openConnection(); |
Despite the fact there is a throws IOException
, It would be better to handle the issue within the method in order to directly provide informative message to the user
|
private HttpURLConnection openConnection(String url) throws IOException { |