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

Resources are closed incorrectly #14

Open
QiAnXinCodeSafe opened this issue Jul 8, 2019 · 0 comments
Open

Resources are closed incorrectly #14

QiAnXinCodeSafe opened this issue Jul 8, 2019 · 0 comments

Comments

@QiAnXinCodeSafe
Copy link

The outputStream may throw an exception before the resource is closed,you should use try-catch-finally or try-with-resource to close the resource.
Connection.getinputstream () and connection.geterrorstream () are not closed.

HttpURLConnection connection = getConnection();
connection.setDoOutput(true);
DataOutputStream outputStream = new DataOutputStream(connection.getOutputStream());
outputStream.writeBytes(requestJson.toString());
outputStream.flush();
outputStream.close();
int responseCode = connection.getResponseCode();
if (responseCode == 200) {
String response = inputstreamToString(connection.getInputStream());
logger.info("Message sent to Firebase for delivery, response:");
logger.info(response);
} else {
logger.info("Unable to send message to Firebase:");
String response = inputstreamToString(connection.getErrorStream());
logger.info(response);

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