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

8274809: Update java.base classes to use try-with-resources #5818

Closed
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions src/java.base/share/classes/sun/net/NetProperties.java
Original file line number Diff line number Diff line change
@@ -68,8 +68,9 @@ private static void loadDefaultProperties() {
File f = new File(fname, "conf");
f = new File(f, "net.properties");
fname = f.getCanonicalPath();
try (FileInputStream fis = new FileInputStream(fname)) {
props.load(fis);
try (FileInputStream in = new FileInputStream(fname)) {
BufferedInputStream bin = new BufferedInputStream(in);
props.load(bin);
}
} catch (Exception e) {
// Do nothing. We couldn't find or access the file
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2003, 2012, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2003, 2021, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@@ -30,7 +30,6 @@
import java.io.EOFException;
import java.io.IOException;
import java.net.URI;
import java.net.URL;
import java.net.HttpURLConnection;
import java.util.*;

@@ -112,7 +111,7 @@ public TSResponse generateTimestamp(TSRequest tsQuery) throws IOException {
connection.connect(); // No HTTP authentication is performed

// Send the request
try (DataOutputStream output = new DataOutputStream(connection.getOutputStream())) {
try (var output = new DataOutputStream(connection.getOutputStream())) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just wondering why you chose to switch stylistically to using the var keyword.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's one of the places where I personally would always use the var keyword too: it makes the line shorter and the type is already clearly visible in the RHS of the assignment, so repeating it on the left hand side does not bring much value...

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just interesting that the style wasn't consistent. Both ways are fine by me.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I used var only in places, where it allows to reduce line length to be less than 80.

byte[] request = tsQuery.encode();
output.write(request, 0, request.length);
output.flush();
@@ -124,7 +123,7 @@ public TSResponse generateTimestamp(TSRequest tsQuery) throws IOException {

// Receive the reply
byte[] replyBuffer = null;
try (BufferedInputStream input = new BufferedInputStream(connection.getInputStream())) {
try (var input = new BufferedInputStream(connection.getInputStream())) {
if (debug != null) {
String header = connection.getHeaderField(0);
debug.println(header);