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

HttpResponse not closed on Exception. #84

Closed
gantzm opened this issue Jun 5, 2017 · 1 comment
Closed

HttpResponse not closed on Exception. #84

gantzm opened this issue Jun 5, 2017 · 1 comment

Comments

@gantzm
Copy link

gantzm commented Jun 5, 2017

In the following code, JsonApiClient.java:

  @Override
    protected  <T> T unmarshall(HttpResponse response, TypeReference<T> clazz) throws IOException {
        if (response.getEntity() == null || clazz.getType().equals(Void.class)) {
            EntityUtils.consume(response.getEntity());
            return null;
        }
        InputStream inputStream = response.getEntity().getContent();
        JsonParser parser = objectMapper.getFactory().createParser(inputStream);
        T toReturn = parser.readValueAs(clazz);
        EntityUtils.consume(response.getEntity());
        return toReturn;
    }

The response is not properly consumed if "parser.readValueAs(clazz)" throws an exception.

The EntityUtils.consume call should be placed in a finally block.

@bdemers
Copy link
Contributor

bdemers commented Nov 9, 2017

No longer a problem in the current version

@bdemers bdemers closed this as completed Nov 9, 2017
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

2 participants