(geronimo-mail) branch main updated: GERONIMO-6884 - Fix SocketFactory creation (#2)
[email protected] Sun, 16 Nov 2025 08:00:44 +0000
| Newsgroups | gmane.comp.java.geronimo.cvs |
|---|---|
| Message-ID | <[email protected]> |
This is an automated email from the ASF dual-hosted git repository.
rzo1 pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/geronimo-mail.git
The following commit(s) were added to refs/heads/main by this push:
new d5a8206 GERONIMO-6884 - Fix SocketFactory creation (#2)
d5a8206 is described below
commit d5a8206dbc06069e047adfcf9a8ebc349fef8106
Author: sebsoftware <[email protected]>
AuthorDate: Sun Nov 16 09:00:40 2025 +0100
GERONIMO-6884 - Fix SocketFactory creation (#2)
* Fix SocketFactory creation
try to instantiate socketFactoryClass. If it fails try to use the geDefault method.
This is the way documented in JavaDoc and also used by i.E. angus-mail.
getDefault is the only way to get fallback to "javax.net.ssl.SSLSocketFactory" work. Because
SSLSocketFactory is an abstract class and not instantiable without subclassing.
* improved error handling information
---------
Co-authored-by: Jens Heitmann <[email protected]>
---
.../java/org/apache/geronimo/mail/util/MailConnection.java | 14 +++++++++++++-
1 file changed, 13 insertions(+), 1 deletion(-)
diff --git a/geronimo-mail_2.1_impl/geronimo-mail_2.1_provider/src/main/java/org/apache/geronimo/mail/util/MailConnection.java b/geronimo-mail_2.1_impl/geronimo-mail_2.1_provider/src/main/java/org/apache/geronimo/mail/util/MailConnection.java
index fd151c3..818af23 100644
--- a/geronimo-mail_2.1_impl/geronimo-mail_2.1_provider/src/main/java/org/apache/geronimo/mail/util/MailConnection.java
+++ b/geronimo-mail_2.1_impl/geronimo-mail_2.1_provider/src/main/java/org/apache/geronimo/mail/util/MailConnection.java
@@ -354,10 +354,22 @@ public class MailConnection {
// done indirectly, we need to invoke the method using reflection.
// This retrieves a factory instance.
//Method getDefault = factoryClass.getMethod("getDefault", new Class[0]); //TODO check instantiation of socket factory
- Object defFactory = factoryClass.newInstance();// getDefault.invoke(new Object(), new Object[0]);
+ // Object defFactory = factoryClass.newInstance();// getDefault.invoke(new Object(), new Object[0]);
// now that we have the factory, there are two different createSocket() calls we use,
// depending on whether we have a localAddress override.
+ Object defFactory;
+ try {
+ defFactory = factoryClass.newInstance();
+ } catch (Throwable t) {
+ Method getDefault = factoryClass.getMethod("getDefault", new Class[0]); //TODO check instantiation of socket factory
+ defFactory = getDefault.invoke(new Object(), new Object[0]);
+
+ if (defFactory == null) {
+ throw new Exception("Can not create factory class '" + factoryClass.getName() + "' neither by creating a new instance or using getDefault()", t);
+ }
+ }
+
if (localAddress != null && !layer) {
// retrieve the createSocket(String, int, InetAddress, int) method.
Class[] createSocketSig = new Class[] { String.class, Integer.TYPE, InetAddress.class, Integer.TYPE };