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

ExpectedSystemExit improvement in multi-threads environment #46

Open
wants to merge 17 commits into
base: master
Choose a base branch
from

Conversation

akryvtsun
Copy link

Implementation of #44 fix

private Integer statusOfFirstExitCall = null;

public NoExitSecurityManager(SecurityManager originalSecurityManager) {
this(originalSecurityManager, new EmptySynchLatch());
Copy link
Owner

@stefanbirkner stefanbirkner Nov 2, 2016

Choose a reason for hiding this comment

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

Please delete this constructor because we don't need it anymore. It is only used by the test and you can use new NoExitSecurityManager(..., 0) instead.

Copy link
Owner

Choose a reason for hiding this comment

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

I just saw that this was the case before your last commit. I suggest to revert your last commit because it does not improve the code in a way that I want. It adds another layer of abstraction by using a new type. I prefer simple code :-)

Copy link
Owner

@stefanbirkner stefanbirkner Nov 2, 2016

Choose a reason for hiding this comment

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

Nevertheless you can delete the old constructor.

Copy link
Author

Choose a reason for hiding this comment

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

@stefanbirkner good point! agreed.

@akryvtsun
Copy link
Author

Implemented your notes. Fixed FindBug warning.

return statusOfFirstExitCall != null;
public boolean isCheckExitCalled() throws InterruptedException {
boolean wasCountDown = synchLatch.await(timeout, TimeUnit.MILLISECONDS);
return statusOfFirstExitCall != null && wasCountDown;
Copy link
Owner

Choose a reason for hiding this comment

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

You don't have to check statusOfFirstExitCall anymore. You can remove the second line and immediately return the result of line 36: return synchLatch.await(...). By the way could you rename syncLatch to exitLatch.

Copy link
Author

Choose a reason for hiding this comment

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

@stefanbirkner agreed. Also it's possible to change type of statusOfFirstExitCall from Integer to simply int and remove if statement at all here:

    @Override
    public void checkExit(int status) {
        if (statusOfFirstExitCall == null)
            statusOfFirstExitCall = status;
        exitLatch.countDown();
        throw new CheckExitCalled(status);
    }

WDYT?

handleSystemExitWithStatus(securityManager.getStatusOfFirstCheckExitCall());
else
handleMissingSystemExit();
} catch (InterruptedException e) {
Copy link
Owner

Choose a reason for hiding this comment

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

Don't catch that exception. By rethrowing it, the developer gets the full stacktrace of that exception which can be valuable. Additionally it is less code on our side.

Copy link
Author

Choose a reason for hiding this comment

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

Agreed. Fixed.

@stefanbirkner
Copy link
Owner

stefanbirkner commented Nov 3, 2016

We are getting closer to a final version of the pull request. Thank you for your patience.

throw new CheckExitCalled(status);
}

public boolean isCheckExitCalled() {
return statusOfFirstExitCall != null;
public boolean isCheckExitCalled() throws InterruptedException {
Copy link
Owner

@stefanbirkner stefanbirkner Nov 3, 2016

Choose a reason for hiding this comment

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

Could you add the timeout as a parameter to the isCheckExitCalled method instead of using a field in that class.

Copy link
Author

Choose a reason for hiding this comment

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

@akryvtsun
Copy link
Author

akryvtsun commented Nov 4, 2016

@stefanbirkner you have to supprese Firebugs check for intentional ignoring return value in line exitStatusHolder.offer(status); somehow.

@akryvtsun
Copy link
Author

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