Skip to content

Use try-with-resources #1521

@elharo

Description

@elharo

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or requestgood first issueGood for newcomerspriority:minorMinor loss of function, or other problem where easy workaround is present

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions