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

Make synthetic classes used in a try with resources statement implement AutoCloseable #337

Merged
merged 13 commits into from
Jul 26, 2024

Conversation

kelloggm
Copy link
Collaborator

Based on a problem I noticed while investigating why Specimin wasn't handling na-176 properly. There are probably other issues with that bug, but this one seemed like a good place to start.

@kelloggm kelloggm requested a review from theron-wang July 26, 2024 14:59
Copy link
Collaborator

@theron-wang theron-wang left a comment

Choose a reason for hiding this comment

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

Besides one comment regarding the test case's behavior, the code changes look good to me. By the way, before I realized you were working on this issue, I was looking into this issue and created a minimal reproducible test case for the IllegalStateException, if it helps:

package test;

public class Foo {
    // target method
    public void foo() {
        Baz.test();
    }

    public void bar() {
        Baz<String> baz;
    }
}


class Simple {

private ThirdResource r;
Copy link
Collaborator

Choose a reason for hiding this comment

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

For this test case, we might want to change this to private final ThirdResource r = new ThirdResource() to prevent the compilation error we see in the CI. Not sure how Specimin will handle this (if it will remove the initializer or not) but we could force Specimin to preserve all used fields if they are used with try-with-resources.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I changed it to just initialize it to null, which is what Specimin would do anyway. The actual value of the resource doesn't matter here, since we're not going to run the code - javac just checks that it's final.

@kelloggm
Copy link
Collaborator Author

Besides one comment regarding the test case's behavior, the code changes look good to me. By the way, before I realized you were working on this issue, I was looking into this issue and created a minimal reproducible test case for the IllegalStateException, if it helps

Definitely! I actually haven't investigated that part of the crash yet at all - I looked at the code that was causing the problem and immediately noticed the try-with-resources and realized that Specimin didn't handle that case at all, so I just started working on fixing that. I'll look into this problem next, starting with your test case.

@kelloggm kelloggm requested a review from theron-wang July 26, 2024 16:10
Copy link
Collaborator

@theron-wang theron-wang left a comment

Choose a reason for hiding this comment

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

Looks good to me!

@kelloggm kelloggm merged commit c689d39 into main Jul 26, 2024
2 checks passed
@kelloggm kelloggm deleted the try-with-resources branch July 26, 2024 16:22
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.

2 participants