HCL-TECH-SOFTWARE / domino-jnx

Modern Domino Java API based on JNA access to Domino's C API
https://opensource.hcltechsw.com/domino-jnx/
Apache License 2.0
13 stars 3 forks source link

TestMimeReadWrite#testCreateMailInMailDb hits ClassCastException when using the Notes JVM #6

Open jesse-gallagher opened 3 years ago

jesse-gallagher commented 3 years ago

This is presumably from picking up a provider that's present in the Notes JVM jvm/lib/ext directory.

java.lang.ClassCastException: com.sun.mail.handlers.text_plain incompatible with jakarta.activation.DataContentHandler
    at jakarta.activation.MailcapCommandMap.getDataContentHandler(MailcapCommandMap.java:601)
    at jakarta.activation.MailcapCommandMap.createDataContentHandler(MailcapCommandMap.java:554)
    at jakarta.activation.DataHandler.getDataContentHandler(DataHandler.java:590)
    at jakarta.activation.DataHandler.writeTo(DataHandler.java:289)
    at jakarta.mail.internet.MimeUtility.getEncoding(MimeUtility.java:316)
    at jakarta.mail.internet.MimeBodyPart.updateHeaders(MimeBodyPart.java:1551)
    at jakarta.mail.internet.MimeBodyPart.updateHeaders(MimeBodyPart.java:1148)
    at jakarta.mail.internet.MimeMultipart.updateHeaders(MimeMultipart.java:498)
    at jakarta.mail.internet.MimeBodyPart.updateHeaders(MimeBodyPart.java:1509)
    at jakarta.mail.internet.MimeBodyPart.updateHeaders(MimeBodyPart.java:1148)
    at jakarta.mail.internet.MimeMultipart.updateHeaders(MimeMultipart.java:498)
    at jakarta.mail.internet.MimeBodyPart.updateHeaders(MimeBodyPart.java:1509)
    at jakarta.mail.internet.MimeBodyPart.updateHeaders(MimeBodyPart.java:1148)
    at jakarta.mail.internet.MimeMultipart.updateHeaders(MimeMultipart.java:498)
    at jakarta.mail.internet.MimeBodyPart.updateHeaders(MimeBodyPart.java:1509)
    at jakarta.mail.internet.MimeMessage.updateHeaders(MimeMessage.java:2238)
    at jakarta.mail.internet.MimeMessage.saveChanges(MimeMessage.java:2198)
    at jakarta.mail.internet.MimeMessage.writeTo(MimeMessage.java:1877)
    at jakarta.mail.internet.MimeMessage.writeTo(MimeMessage.java:1854)
    at com.hcl.domino.jna.test.TestMimeReadWrite.lambda$0(TestMimeReadWrite.java:97)

This was observed in Notes 11.0.0 on macOS, but not on 11.0.1, so it may be a moot point. Still worth keeping an eye on for the short term, though.

jesse-gallagher commented 3 years ago

From 2020-06-22:

In investigating a bit, I think our main option is to register a factory with DataHandler.setDataContentHandlerFactory that provides implementations of the handlers that don't rely on the conflicted com.sun.* classes found in both the old and new Mail APIs. The down sides here are both the duplication of code and the fact that DataHandler enforces that only one such factory is ever set - which could end up being an annoying bit of behavior in some cases.

I also tried registering a handler with META-INF/mailcap, but I don't think we have any way to make our handler class name take precedence over the one in the API JAR itself.

jesse-gallagher commented 3 years ago

From 2020-06-22:

It may also work to juggle classloaders somewhere, since the bit of code that loads the class by name uses the thread context class loader. However, since the stack that leads to this problem doesn't actually run through the API, it would have to be up to the app side to do so.

jesse-gallagher commented 3 years ago

From 2021-05-03:

We could also potentially add a method to MimeWriter to write to an OutputStream and document this as the rationale for its existence.