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

Remove throws MessagingException on jakarta.mail.internet.MimeMessage addHeader/removeHeader functions #640

Open
nvsnvikram opened this issue Nov 9, 2022 · 1 comment
Assignees
Labels

Comments

@nvsnvikram
Copy link

nvsnvikram commented Nov 9, 2022

Is your feature request related to a problem? Please describe.
MimeMessage class has addHeader and removeHeader functions that throw MessagingException. But the underlying function does not throw these exceptions. This causes the callers to unnecessarily catch and discard the MessagingException or throw it back to callers.

Describe the solution you'd like
Java allows sub classes to remove checked exceptions on overridden methods. Can we remove MessagingException on addHeader and removeHeader?

Describe alternatives you've considered

Additional context

@jmehrens jmehrens self-assigned this Jan 22, 2024
@jmehrens
Copy link
Contributor

jmehrens commented Jan 23, 2024

Removing the throws MessagingException from addHeader/removeHeader of MimeMessage is not possible due to IMAPMessage and POP3Messaging extending MimeMessage and overriding those functions to throw a checked exception.

Some possible alternatives are:

  1. Add new public methods to MimeMessage that can add and remove headers that doesn't throw checked exceptions. It might have to declare some new type of unchecked exception.
  2. Add a getter to expose the internal jakarta.mail.internet.InternetHeaders. This object has getHeader/removeHeader calls that doesn't throw checked exceptions. However, some more thought is needed to determine how to handle read only messages. Also need to determine if exposing this causes more issues than it solves.
  3. Modify SMTPMessage override addHeader/removeHeader in the way you describe. Unfortunately, this was not done when the class was created so changing this compatibility issue. It still might be possible to modify this class instead of the larger MimeMessage.

@jmehrens jmehrens added the enhancement New feature or request label Jan 23, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants