jakartaee / mail-api

Jakarta Mail Specification project
https://jakartaee.github.io/mail-api
Other
242 stars 100 forks source link

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

Open nvsnvikram opened 1 year ago

nvsnvikram commented 1 year ago

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 commented 5 months ago

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.