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

Avoid PrintWriter #189

Closed
elharo opened this issue Sep 6, 2018 · 0 comments
Closed

Avoid PrintWriter #189

elharo opened this issue Sep 6, 2018 · 0 comments
Assignees
Labels
type: cleanup An internal cleanup or hygiene concern.

Comments

@elharo
Copy link
Contributor

elharo commented Sep 6, 2018

This code is dangerous because PrintWriter swallows IOExceptions:

  @Override
  public AccessToken refreshAccessToken() throws IOException {
    Socket socket = new Socket("localhost", this.getAuthPort());
    socket.setSoTimeout(READ_TIMEOUT_MS);
    AccessToken token;
    try {    
      PrintWriter out =
        new PrintWriter(socket.getOutputStream(), true);
      out.println(GET_AUTH_TOKEN_REQUEST);
    
      BufferedReader input =
          new BufferedReader(new InputStreamReader(socket.getInputStream()));
      input.readLine(); // Skip over the first line
      JsonParser parser = OAuth2Utils.JSON_FACTORY.createJsonParser(input);
      List<Object> messageArray = (List<Object>) parser.parseArray(ArrayList.class, Object.class);
      String accessToken = messageArray.get(ACCESS_TOKEN_INDEX).toString();
      token =  new AccessToken(accessToken, null);
    } finally {
      socket.close();
    }
    return token;
  }
@JustinBeckwith JustinBeckwith added the triage me I really want to be triaged. label Sep 7, 2018
@chingor13 chingor13 added the type: cleanup An internal cleanup or hygiene concern. label Sep 10, 2018
@JustinBeckwith JustinBeckwith removed the triage me I really want to be triaged. label Sep 10, 2018
@chingor13 chingor13 self-assigned this Dec 19, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: cleanup An internal cleanup or hygiene concern.
Projects
None yet
Development

No branches or pull requests

3 participants