maven-resolver icon indicating copy to clipboard operation
maven-resolver copied to clipboard

Use try-with-resources

Open elharo opened this issue 1 year ago • 9 comments

New feature, improvement proposal

There's a lot of code like this scattered throughout the project:

        FileOutputStream fos = null;
        try {
            fos = new FileOutputStream(file);

            if (data != null) {
                fos.write(data.getBytes(StandardCharsets.UTF_8));
            }

            fos.close();
            fos = null;
        } finally {
            try {
                if (fos != null) {
                    fos.close();
                }
            } catch (final IOException e) {
                // Suppressed due to an exception already thrown in the try block.
            }
        }

Use try-with-resources from Java 7

elharo avatar Jul 09 '25 12:07 elharo

Hi @elharo,

I’m interested in contributing to this issue. Could you please provide more details on where to start? For example, are there specific classes or files that need changes, or does this require broader modifications across the codebase? Any guidance on the scope of the work would be greatly appreciated.

Thanks!

sidhantmourya avatar Jul 09 '25 18:07 sidhantmourya

Hi @elharo,

I’m interested in contributing to this issue. Could you please provide more details on where to start? For example, are there specific classes or files that need changes, or does this require broader modifications across the codebase? Any guidance on the scope of the work would be greatly appreciated.

Thanks!

Hi @sidhantmourya, it's affect the whole codebase. Just go through file by file.

Bukama avatar Jul 15 '25 08:07 Bukama

hi @Bukama, thank you for the heads-up! I’ve gone through the documentation on contributing patches: https://maven.apache.org/guides/development/guide-maven-development.html. While it explains the patch creation process, I’m still unsure about how to actually start working on the project — especially in terms of debugging or navigating the codebase.

I’ve already forked the repository, but since I’ve never contributed to a large open-source Java project like this before, I’d really appreciate some guidance on how to set up the development environment. For example:

Is there a recommended IDE for working with Maven’s codebase? (e.g., IntelliJ IDEA or Eclipse)

Do I need to import it as a Maven project into the IDE, or is working directly from a text editor like VS Code also feasible?

Are there specific tips or best practices for exploring or understanding the project layout?

Any help on how to effectively get started with the development workflow would be greatly appreciated!

sidhantmourya avatar Jul 15 '25 16:07 sidhantmourya

Hi @Bukama if this issue is still open I want to work on it

hemanthlucifer avatar Sep 11 '25 09:09 hemanthlucifer

Fixed: https://github.com/apache/maven-resolver/pull/1623

dheeraj1010 avatar Oct 08 '25 19:10 dheeraj1010

Hi,

I noticed that PR #1623 appears to address the changes proposed here. Is there any remaining work related to this issue, or should it be considered resolved?

Thanks.

anukalp2804 avatar Dec 13 '25 11:12 anukalp2804

It isn't resolved until it's fixed. #1623 is not merged at this time.

elharo avatar Dec 13 '25 13:12 elharo

hello @elharo , I saw the recent discussion and the clarification that the issue is still open since PR #1623 hasn't merged. I would like to take this on now and complete the refactoring of all remaining try-finally blocks to use try-with-resources. I will submit a new Pull Request shortly.

Rakeshrakeeeee avatar Dec 13 '25 14:12 Rakeshrakeeeee

It isn't resolved until it's fixed. #1623 is not merged at this time.

Thanks for the clarification.

Given that this affects the whole codebase and some related changes are already in progress, would it be acceptable to contribute smaller, focused PRs (e.g., one module or test package at a time) to continue this work? If so, is there any specific area you’d recommend starting with?

Thanks.

anukalp2804 avatar Dec 13 '25 16:12 anukalp2804