diff --git a/src/main/java/org/apache/commons/xml/SaxonProvider.java b/src/main/java/org/apache/commons/xml/SaxonProvider.java
index 654c0e1..9453796 100644
--- a/src/main/java/org/apache/commons/xml/SaxonProvider.java
+++ b/src/main/java/org/apache/commons/xml/SaxonProvider.java
@@ -94,6 +94,12 @@ public XMLReader makeParser(final String className) throws TransformerFactoryCon
}
}
+ /**
+ * Sole holder of Saxon symbolic references, so that the outer class verifies without Saxon on the classpath.
+ *
+ *
{@link SaxonProvider#isSaxon} runs on every harden call, Saxon present or not, and the JVM verifier may load classes eagerly to prove class-typed
+ * assignability; keeping every Saxon reference in this nested class defers that loading until a Saxon factory has actually been recognized.
+ */
private static final class SaxonProviderConfigurer {
private static TransformerFactory configure(final TransformerFactory factory) {
@@ -109,6 +115,10 @@ private static XPathFactory configure(final XPathFactory factory) {
((XPathFactoryImpl) factory).setConfiguration(config);
return factory;
}
+
+ private static Supplier emptySourceSupplier() {
+ return EmptySource::getInstance;
+ }
}
static TransformerFactory configure(final TransformerFactory factory) {
@@ -117,9 +127,6 @@ static TransformerFactory configure(final TransformerFactory factory) {
} catch (final ClassCastException e) {
// A Saxon-package factory the configurer cannot lock down; refuse it rather than returning it unhardened.
throw new HardeningException("Unsupported Saxon TransformerFactory " + factory.getClass().getName(), e);
- } catch (final LinkageError e) {
- // Unlikely, but protects method execution from missing optional dependency
- throw new IllegalStateException(e);
}
}
@@ -129,9 +136,6 @@ static XPathFactory configure(final XPathFactory factory) {
} catch (final ClassCastException e) {
// A Saxon-package factory the configurer cannot lock down; refuse it rather than returning it unhardened.
throw new HardeningException("Unsupported Saxon XPathFactory " + factory.getClass().getName(), e);
- } catch (final LinkageError e) {
- // Unlikely, but protects method execution from missing optional dependency
- throw new IllegalStateException(e);
}
}
@@ -141,7 +145,7 @@ static XPathFactory configure(final XPathFactory factory) {
* @return a supplier for Saxon's empty {@link Source}.
*/
static Supplier emptySourceSupplier() {
- return EmptySource::getInstance;
+ return SaxonProviderConfigurer.emptySourceSupplier();
}
/**