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

8216400: improve handling of IOExceptions in JavaCompiler.close() #1895

Closed
wants to merge 4 commits into from

Conversation

lgxbslgx
Copy link
Member

@lgxbslgx lgxbslgx commented Dec 25, 2020

Hi all,

This little patch enhances the code according to the comment by using a simplest way. I found JDK-8069116 is a similar issue. A better way would be appreciated.

Thank you for taking the time to reivew.

Best Regards.


Progress

  • Change must not contain extraneous whitespace
  • Commit message must refer to an issue
  • Change must be properly reviewed

Issues

  • JDK-8216400: improve handling of IOExceptions in JavaCompiler.close()
  • JDK-8069116: improve fatal error handling in JavaCompiler

Reviewers

Download

$ git fetch https://git.openjdk.java.net/jdk pull/1895/head:pull/1895
$ git checkout pull/1895

@bridgekeeper
Copy link

@bridgekeeper bridgekeeper bot commented Dec 25, 2020

👋 Welcome back lgxbslgx! A progress list of the required criteria for merging this PR into master will be added to the body of your pull request. There are additional pull request commands available for use with this pull request.

@openjdk openjdk bot added the rfr label Dec 25, 2020
@openjdk
Copy link

@openjdk openjdk bot commented Dec 25, 2020

@lgxbslgx The following label will be automatically applied to this pull request:

  • compiler

When this pull request is ready to be reviewed, an "RFR" email will be sent to the corresponding mailing list. If you would like to change these labels, use the /label pull request command.

@openjdk openjdk bot added the compiler label Dec 25, 2020
@mlbridge
Copy link

@mlbridge mlbridge bot commented Dec 25, 2020

Webrevs

for (Closeable c: closeables) {
try {
c.close();
} catch (IOException e) {
// When javac uses JDK 7 as a baseline, this code would be
// better written to set any/all exceptions from all the
// Closeables as suppressed exceptions on the FatalError
// that is thrown.
} catch (Exception e) {
JCDiagnostic msg = diagFactory.fragment(Fragments.FatalErrCantClose);
throw new FatalError(msg, e);
}
Copy link
Contributor

@jonathan-gibbons jonathan-gibbons Dec 25, 2020

Choose a reason for hiding this comment

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

The comment is meant to suggest the following:

FatalError fe = null;
for (Closable c : closeables) {
    try {
        c.close();
    } catch (IOException e) {
        if (fe == null) {
            JCDiagnostic msg = diagFactory.fragment(Fragments.FatalErrCantClose);
            fe = new FatalError(msg, e):
        } else {
            fe.addSuppressed(e);
        }
    }
}
if (fe != null) {
    throw fe;
}

(Apologies if there are any errors in that: I just typed it in directly.)

This is probably a case where you could probably get away with no test and use the label norge-hard. If you were to write a test, it would have to involve creating multiple file system artifacts that cannot be closed, perhaps by creating wrappers that always throw exceptions when close() is called.

Copy link
Member Author

@lgxbslgx lgxbslgx Dec 26, 2020

Choose a reason for hiding this comment

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

Oops, I misunderstood the meaning of any/all exceptions from all the Closeables.

@lgxbslgx
Copy link
Member Author

@lgxbslgx lgxbslgx commented Dec 26, 2020

/issue add JDK-8069116

@openjdk
Copy link

@openjdk openjdk bot commented Dec 26, 2020

@lgxbslgx
Adding additional issue to issue list: 8069116: improve fatal error handling in JavaCompiler.

Copy link
Contributor

@jonathan-gibbons jonathan-gibbons left a comment

OK. Clever test; well done.
Without the test, I would not personally have approved the work, since I suggested the code. (I would have wanted another set of Reviewer eyes on the suggestion.)
But given the addition of the test to verify the behavior, I think it's OK to go ahead.


try {
compiler.close();
} catch(FatalError fatalError) {
Copy link
Contributor

@jonathan-gibbons jonathan-gibbons Dec 26, 2020

Choose a reason for hiding this comment

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

(minor) add space after "catch"

Copy link
Member Author

@lgxbslgx lgxbslgx Dec 26, 2020

Choose a reason for hiding this comment

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

Fixed.

Copy link
Contributor

@jonathan-gibbons jonathan-gibbons Dec 26, 2020

Choose a reason for hiding this comment

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

👍

@openjdk
Copy link

@openjdk openjdk bot commented Dec 26, 2020

@lgxbslgx This change now passes all automated pre-integration checks.

ℹ️ This project also has non-automated pre-integration requirements. Please see the file CONTRIBUTING.md for details.

After integration, the commit message for the final commit will be:

8216400: improve handling of IOExceptions in JavaCompiler.close()
8069116: improve fatal error handling in JavaCompiler

Reviewed-by: jjg

You can use pull request commands such as /summary, /contributor and /issue to adjust it as needed.

At the time when this comment was updated there had been no new commits pushed to the master branch. If another commit should be pushed before you perform the /integrate command, your PR will be automatically rebased. If you prefer to avoid any potential automatic rebasing, please check the documentation for the /integrate command for further details.

As you do not have Committer status in this project an existing Committer must agree to sponsor your change. Possible candidates are the reviewers of this PR (@jonathan-gibbons) but any other Committer may sponsor as well.

➡️ To flag this PR as ready for integration with the above commit message, type /integrate in a new comment. (Afterwards, your sponsor types /sponsor in a new comment to perform the integration).

@openjdk openjdk bot added the ready label Dec 26, 2020
@lgxbslgx
Copy link
Member Author

@lgxbslgx lgxbslgx commented Dec 26, 2020

/integrate

@openjdk openjdk bot added the sponsor label Dec 26, 2020
@openjdk
Copy link

@openjdk openjdk bot commented Dec 26, 2020

@lgxbslgx
Your change (at version ae642c2) is now ready to be sponsored by a Committer.

@jonathan-gibbons
Copy link
Contributor

@jonathan-gibbons jonathan-gibbons commented Dec 26, 2020

/sponsor

@openjdk openjdk bot closed this Dec 26, 2020
@openjdk openjdk bot added integrated and removed sponsor ready rfr labels Dec 26, 2020
@openjdk
Copy link

@openjdk openjdk bot commented Dec 26, 2020

@jonathan-gibbons @lgxbslgx Pushed as commit 97c99b5.

💡 You may see a message that your pull request was closed with unmerged commits. This can be safely ignored.

@lgxbslgx lgxbslgx deleted the JDK-8216400 branch Dec 26, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
compiler integrated
2 participants