diff --git a/api/src/main/java/jakarta/mail/Multipart.java b/api/src/main/java/jakarta/mail/Multipart.java index f119cbe3..73083e44 100644 --- a/api/src/main/java/jakarta/mail/Multipart.java +++ b/api/src/main/java/jakarta/mail/Multipart.java @@ -20,6 +20,7 @@ import java.io.IOException; import java.io.OutputStream; +import java.util.ServiceConfigurationError; import java.util.Vector; /** @@ -275,7 +276,15 @@ protected StreamProvider getStreamProvider() throws MessagingException { if (parent != null) { return parent.getStreamProvider(); } else { - return Session.getDefaultInstance(System.getProperties(), null).getStreamProvider(); + try { + try { + return Session.getDefaultInstance(System.getProperties(), null).getStreamProvider(); + } catch (ServiceConfigurationError sce) { + throw new IllegalStateException(sce); + } + } catch (RuntimeException re) { + throw new MessagingException("Unable to get " + StreamProvider.class.getName(), re); + } } } diff --git a/api/src/main/java/jakarta/mail/Part.java b/api/src/main/java/jakarta/mail/Part.java index d99562c7..4a18e28c 100644 --- a/api/src/main/java/jakarta/mail/Part.java +++ b/api/src/main/java/jakarta/mail/Part.java @@ -23,6 +23,7 @@ import java.io.InputStream; import java.io.OutputStream; import java.util.Enumeration; +import java.util.ServiceConfigurationError; /** * The Part interface is the common base interface for @@ -465,6 +466,14 @@ Enumeration
getNonMatchingHeaders(String[] header_names) * @since JavaMail 2.2 */ default StreamProvider getStreamProvider() throws MessagingException { - return Session.getDefaultInstance(System.getProperties(), null).getStreamProvider(); + try { + try { + return Session.getDefaultInstance(System.getProperties(), null).getStreamProvider(); + } catch (ServiceConfigurationError sce) { + throw new IllegalStateException(sce); + } + } catch (RuntimeException re) { + throw new MessagingException("Unable to get " + StreamProvider.class.getName(), re); + } } }