Skip to content

Conversation

@rjrudin
Copy link
Contributor

@rjrudin rjrudin commented Jan 5, 2026

Doing this before adding support for XML exclusions in the incremental write feature. Standardizes on a single way of creating a DocumentBuilderFactory.

Also made a year-change-based fix in LegalHoldsTest.

Copilot AI review requested due to automatic review settings January 5, 2026 19:41
@github-actions
Copy link

github-actions bot commented Jan 5, 2026

Copyright Validation Results
Total: 19 | Passed: 19 | Failed: 0 | Skipped: 0 | at: 2026-01-05 19:57:42 UTC | commit: c4ad7de

✅ Valid Files

  • marklogic-client-api/src/main/java/com/marklogic/client/impl/NodeConverter.java
  • marklogic-client-api/src/main/java/com/marklogic/client/impl/XmlFactories.java
  • marklogic-client-api/src/main/java/com/marklogic/client/io/DOMHandle.java
  • marklogic-client-api/src/main/java/com/marklogic/client/io/DocumentMetadataHandle.java
  • marklogic-client-api/src/test/java/com/marklogic/client/test/BufferableHandleTest.java
  • marklogic-client-api/src/test/java/com/marklogic/client/test/Common.java
  • marklogic-client-api/src/test/java/com/marklogic/client/test/DeleteSearchTest.java
  • marklogic-client-api/src/test/java/com/marklogic/client/test/EvalTest.java
  • marklogic-client-api/src/test/java/com/marklogic/client/test/GeospatialRegionQueriesTest.java
  • marklogic-client-api/src/test/java/com/marklogic/client/test/HandleAsTest.java
  • marklogic-client-api/src/test/java/com/marklogic/client/test/PlanGeneratedBase.java
  • marklogic-client-api/src/test/java/com/marklogic/client/test/QueryOptionsManagerTest.java
  • marklogic-client-api/src/test/java/com/marklogic/client/test/RawQueryDefinitionTest.java
  • marklogic-client-api/src/test/java/com/marklogic/client/test/RequestLoggerTest.java
  • marklogic-client-api/src/test/java/com/marklogic/client/test/SearchFacetTest.java
  • marklogic-client-api/src/test/java/com/marklogic/client/test/XMLDocumentTest.java
  • marklogic-client-api/src/test/java/com/marklogic/client/test/datamovement/LegalHoldsTest.java
  • marklogic-client-api/src/test/java/com/marklogic/client/test/datamovement/ScenariosTest.java
  • marklogic-client-api/src/test/java/com/marklogic/client/test/io/DocumentMetadataHandleTest.java

✅ All files have valid copyright headers!

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR refactors JAXP usage to standardize XML parsing across the codebase by consolidating DocumentBuilderFactory creation into a single utility class. The refactoring replaces scattered instances of DocumentBuilderFactory configuration with calls to a centralized XmlFactories.getDocumentBuilderFactory() method. Additionally, a year-based fix is applied to LegalHoldsTest to prevent test failures due to date progression.

  • Centralizes DocumentBuilderFactory creation in XmlFactories class with secure default configuration
  • Removes duplicate DocumentBuilderFactory initialization code across test and production classes
  • Updates LegalHoldsTest to address a year-progression issue

Reviewed changes

Copilot reviewed 19 out of 19 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
XmlFactories.java Adds new makeNewDocumentBuilderFactory() method and getDocumentBuilderFactory() public method with secure defaults; refactors to use method references instead of anonymous classes
DOMHandle.java Removes makeDocumentBuilderFactory() method and delegates to XmlFactories
NodeConverter.java Removes static DocumentBuilderFactory field and getter, delegates to XmlFactories
DocumentMetadataHandle.java Replaces inline DocumentBuilderFactory creation with XmlFactories call
Multiple test files Replace inline DocumentBuilderFactory creation with XmlFactories calls; removes unused imports
LegalHoldsTest.java Increments year roll from -10 to -11 to fix year-dependent test failure
DeleteSearchTest.java Additional fix to swap assertEquals parameter order

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

}
});
new CachedInstancePerThreadSupplier<>(XmlFactories::makeNewOutputFactory);

Copy link

Copilot AI Jan 5, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The new cachedDocumentBuilderFactory field should have a javadoc comment explaining its purpose, similar to how cachedOutputFactory has documentation. This helps maintain consistency in the code and clarifies why DocumentBuilderFactory instances are cached per thread.

Suggested change
/**
* Cached per-thread {@link DocumentBuilderFactory} instances.
* <p>
* Creating {@link DocumentBuilderFactory} instances is relatively expensive and they are
* not guaranteed to be thread safe. To avoid repeated initialization cost while preserving
* thread safety, we cache one instance per thread using {@link CachedInstancePerThreadSupplier}.
* New instances are created via {@link #makeNewDocumentBuilderFactory()} when no cached
* value is available for the current thread.
*/

Copilot uses AI. Check for mistakes.
try {
factory.setFeature(XMLConstants.FEATURE_SECURE_PROCESSING, true);
} catch (ParserConfigurationException e) {
logger.warn("Unable to set FEATURE_SECURE_PROCESSING on DocumentBuilderFactory; cause: {}", e.getMessage());
Copy link

Copilot AI Jan 5, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The warning message format is inconsistent with other warning messages in the same method. Lines 97, 102, 107, and 112 use feature name descriptions (e.g., 'disallow-doctype-decl'), while line 92 uses the constant name. For consistency, consider using the constant name format like 'Unable to set {} on DocumentBuilderFactory; cause: {}' with XMLConstants.FEATURE_SECURE_PROCESSING as a parameter, similar to how the logTransformerWarning method works.

Suggested change
logger.warn("Unable to set FEATURE_SECURE_PROCESSING on DocumentBuilderFactory; cause: {}", e.getMessage());
logger.warn("Unable to set {} on DocumentBuilderFactory; cause: {}", XMLConstants.FEATURE_SECURE_PROCESSING, e.getMessage());

Copilot uses AI. Check for mistakes.
// use some rework to ensure that it doesn't fail every time the year changes, but this comment is being left here
// so that if/when this does fail in the future, it'll be easy to fix.
date.roll(Calendar.YEAR, -10);
date.roll(Calendar.YEAR, -11);
Copy link

Copilot AI Jan 5, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This fix addresses an immediate issue but perpetuates the problem mentioned in the comment above (lines 88-90). The test is fragile and will continue to fail each year. Consider refactoring to use a fixed date (e.g., Calendar.getInstance(); date.set(2014, Calendar.JANUARY, 1)) or calculate the year offset dynamically based on the current year to prevent future annual failures.

Copilot uses AI. Check for mistakes.
@rjrudin rjrudin force-pushed the feature/26427-refactor-dbf branch from 7090603 to 187fbd9 Compare January 5, 2026 19:50
Doing this before adding support for XML exclusions in the incremental write feature. Standardizes on a single way of creating a DocumentBuilderFactory.

Also made a year-change-based fix in LegalHoldsTest.
@rjrudin rjrudin force-pushed the feature/26427-refactor-dbf branch from 187fbd9 to c4ad7de Compare January 5, 2026 19:57
@rjrudin rjrudin merged commit acdeb0c into develop Jan 5, 2026
3 checks passed
@rjrudin rjrudin deleted the feature/26427-refactor-dbf branch January 5, 2026 21:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants