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

Use try-with-resources #999

Merged
merged 2 commits into from
Mar 19, 2025
Merged

Conversation

simon04
Copy link
Contributor

@simon04 simon04 commented Mar 18, 2025

No description provided.

@simon04 simon04 requested a review from hierynomus as a code owner March 18, 2025 20:03
Copy link
Contributor

@exceptionfactory exceptionfactory left a comment

Choose a reason for hiding this comment

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

Thanks for proposing the improvements @simon04.

The GitHub build workflow is failing due to an incompatibility with Java 8 as highlighted. Adjusting the approach should resolve the compatibility problem.

@@ -318,10 +318,8 @@ public void writeShort(int v)
public void writeUTF(String str)
throws IOException {
final DataOutputStream dos = new DataOutputStream(rf.new RemoteFileOutputStream(fp));
try {
try (dos) {
Copy link
Contributor

Choose a reason for hiding this comment

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

This changes is not supported on Java 8 according to the automated tests:

/home/runner/work/sshj/sshj/src/main/java/net/schmizz/sshj/sftp/RandomAccessRemoteFile.java:321: error: variables in try-with-resources are not supported in -source 8
        try (dos) {
                ^
  (use -source 9 or higher to enable variables in try-with-resources)

It looks like fp could be updated inside the try block.

@simon04 simon04 force-pushed the try-with-resources branch from fa3f848 to be9c5ce Compare March 19, 2025 06:59
@hierynomus
Copy link
Owner

Thanks for the PRs, keep them coming! 🎉

@hierynomus hierynomus merged commit 11921e2 into hierynomus:master Mar 19, 2025
3 checks passed
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

Successfully merging this pull request may close these issues.

3 participants