This is an automated email from the ASF dual-hosted git repository. robertlazarski pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/axis-axis2-java-rampart.git
commit 8a8e804c10be5a338fbdb342ce82134399539d25 Author: Robert Lazarski <[email protected]> AuthorDate: Fri Oct 16 03:17:09 2026 -1000 RAMPART-459: also record Error failures from OpenSAML init Classpath faults such as NoClassDefFoundError or ServiceConfigurationError escaped the cache, so they were retried per message and failed non-SAML traffic too. They are now wrapped and recorded; VirtualMachineError still propagates uncached. Co-Authored-By: Claude Opus 5.5 <[email protected]> --- .../rahas/impl/util/OpenSAMLInitializer.java | 7 +++++ .../rahas/impl/util/OpenSAMLInitializerTest.java | 30 ++++++++++++++++++++-- 2 files changed, 35 insertions(+), 2 deletions(-) diff --git a/modules/rampart-trust/src/main/java/org/apache/rahas/impl/util/OpenSAMLInitializer.java b/modules/rampart-trust/src/main/java/org/apache/rahas/impl/util/OpenSAMLInitializer.java index eb9fcf17..5a4695fd 100644 --- a/modules/rampart-trust/src/main/java/org/apache/rahas/impl/util/OpenSAMLInitializer.java +++ b/modules/rampart-trust/src/main/java/org/apache/rahas/impl/util/OpenSAMLInitializer.java @@ -130,6 +130,13 @@ public final class OpenSAMLInitializer { } catch (RuntimeException e) { // Module initialisers can fail unchecked; InitializationService does not wrap. throw recordFailure(new InitializationException("OpenSAML initialization failed: " + e, e)); + } catch (VirtualMachineError e) { + throw e; + } catch (Error e) { + // Classpath faults (NoClassDefFoundError, ServiceConfigurationError, + // FactoryConfigurationError) are as permanent as the exceptions above, + // and unwrapped they would also fail every non-SAML message. + throw recordFailure(new InitializationException("OpenSAML initialization failed: " + e, e)); } initialized = true; if (log.isDebugEnabled()) { diff --git a/modules/rampart-trust/src/test/java/org/apache/rahas/impl/util/OpenSAMLInitializerTest.java b/modules/rampart-trust/src/test/java/org/apache/rahas/impl/util/OpenSAMLInitializerTest.java index 3073e573..70aee11d 100644 --- a/modules/rampart-trust/src/test/java/org/apache/rahas/impl/util/OpenSAMLInitializerTest.java +++ b/modules/rampart-trust/src/test/java/org/apache/rahas/impl/util/OpenSAMLInitializerTest.java @@ -106,11 +106,37 @@ public class OpenSAMLInitializerTest extends TestCase { } public void testUncheckedFailureIsWrappedAndNotRetried() throws Exception { + assertWrappedAndNotRetried(new IllegalArgumentException("maxElementDepth")); + } + + public void testClasspathErrorIsWrappedAndNotRetried() throws Exception { + assertWrappedAndNotRetried(new NoClassDefFoundError("org/apache/xerces/Missing")); + } + + public void testVirtualMachineErrorIsNotRecorded() throws Exception { + final AtomicInteger attempts = new AtomicInteger(); + OpenSAMLInitializer initializer = new OpenSAMLInitializer(() -> { + if (attempts.incrementAndGet() == 1) { + throw new OutOfMemoryError("transient"); + } + }); + try { + initializer.ensure(); + fail("OutOfMemoryError must propagate"); + } catch (OutOfMemoryError expected) { + } + initializer.ensure(); + assertEquals("a VirtualMachineError must not be cached as a failure", 2, attempts.get()); + } + + private static void assertWrappedAndNotRetried(final Throwable cause) throws Exception { final AtomicInteger attempts = new AtomicInteger(); - final IllegalArgumentException cause = new IllegalArgumentException("maxElementDepth"); OpenSAMLInitializer initializer = new OpenSAMLInitializer(() -> { attempts.incrementAndGet(); - throw cause; + if (cause instanceof Error) { + throw (Error) cause; + } + throw (RuntimeException) cause; }); InitializationException first = null;
