Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 11 additions & 7 deletions src/main/java/org/apache/commons/xml/SaxonProvider.java
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
* <p>{@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.</p>
*/
private static final class SaxonProviderConfigurer {

private static TransformerFactory configure(final TransformerFactory factory) {
Expand All @@ -109,6 +115,10 @@ private static XPathFactory configure(final XPathFactory factory) {
((XPathFactoryImpl) factory).setConfiguration(config);
return factory;
}

private static Supplier<Source> emptySourceSupplier() {
return EmptySource::getInstance;
}
}

static TransformerFactory configure(final TransformerFactory factory) {
Expand All @@ -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);
}
}

Expand All @@ -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);
}
}

Expand All @@ -141,7 +145,7 @@ static XPathFactory configure(final XPathFactory factory) {
* @return a supplier for Saxon's empty {@link Source}.
*/
static Supplier<Source> emptySourceSupplier() {
return EmptySource::getInstance;
return SaxonProviderConfigurer.emptySourceSupplier();
}

/**
Expand Down
Loading