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

Switch from AssertionError to IllegalStateException #264

Closed
LBoraz opened this issue May 5, 2020 · 4 comments
Closed

Switch from AssertionError to IllegalStateException #264

LBoraz opened this issue May 5, 2020 · 4 comments

Comments

@LBoraz
Copy link

LBoraz commented May 5, 2020

Is it possible to remove the AssertionErrors thrown by the Mailer, for example in case of empty MimeMessage body? I think it should be converted to an Exception. I understand what you are trying to do there, but as java applications normally don't catch Errors this leads applications to crash/fail for what it should really be a ValidationException (most likely recoverable, at least in my use-case).

@bbottema
Copy link
Owner

bbottema commented May 5, 2020

Sounds reasonable. I'll change it, thanks for the suggestion.

@bbottema
Copy link
Owner

bbottema commented May 11, 2020

I'm having second thoughts about this.

Assertion errors indicate the system has reached an unsupported and more importantly an unknown state and continuing could mean anything else the application does could be garbage.

Essentially I cannot assume it is recoverable, in fact as a library designer I have to assume the opposite. It is an Error precisely so that the system halts.

@LBoraz
Copy link
Author

LBoraz commented May 28, 2020

yes, i know the intention is to signal an impossibility to continue and from your point of view you can't know if the application will be able to recover, but maybe that's exactly why the choice should be left to the application.

I think (but of course my perspective on this is limited to my use-case) that most people will end up catching the AssertionError like i did, in order to recover.

Just to add context, imagine this sequence (from my use-case)
worker node receives a mime-message from an external system -> it tries to "forward" it somewhere else using the library -> the library throws an AssertionError -> the worker node dies (because the Error kills the process) -> health checks trigger the start up of a new worker node to replace the dead one -> the worker tries to consume again the same "broken" message -> worker node never recovers (because normally java.lang.Errors are not handled)

https://docs.oracle.com/javase/7/docs/api/java/lang/Error.html

Let me know what you think

@bbottema
Copy link
Owner

bbottema commented Jul 5, 2020

Released in 6.1.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants