-
Notifications
You must be signed in to change notification settings - Fork 38.4k
Replace XMLReaderFactory with SAXParserFactory #27239
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Frederick888
wants to merge
2
commits into
spring-projects:main
from
Frederick888:migrate-xml-reader
Closed
Replace XMLReaderFactory with SAXParserFactory #27239
Frederick888
wants to merge
2
commits into
spring-projects:main
from
Frederick888:migrate-xml-reader
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
XMLReaderFactory has been marked as deprecated and without additional configuration, and it's slower than SAXParserFactory. Previously `XMLReaderFactory.createXMLReader()` is called upon every request. This is an anti-pattern as mentioned in [1] and it can be very slow since it loads the jar service file unless a parser has been pre-assigned [2] (e.g. by setting org.xml.sax.driver). SAXParserFactory uses a FactoryFinder [3] instead, which takes advantage of a thread-local cache provided by ServiceLoader. Developers can still pre-assign a factory by setting javax.xml.parsers.SAXParserFactory to make it faster. [1] https://bugs.openjdk.java.net/browse/JDK-6925410 [2] https://github.com/openjdk/jdk/blob/c8add223a10030e40ccef42e081fd0d8f00e0593/src/java.xml/share/classes/org/xml/sax/helpers/XMLReaderFactory.java#L144-L148 [3] https://github.com/openjdk/jdk/blob/66c653c561b3b5e904579af62e23ff94952bca05/src/java.xml/share/classes/javax/xml/parsers/SAXParserFactory.java#L181-L185
Sorry I should've replaced it outside spring-web as well. UPDATE Pushed. |
f8b5930
to
877974b
Compare
@Frederick888 thanks for the PR and sorry it took so long to process it. With |
snicoll
pushed a commit
that referenced
this pull request
Dec 2, 2021
XMLReaderFactory has been marked as deprecated and without additional configuration, and it's slower than SAXParserFactory. Previously `XMLReaderFactory.createXMLReader()` is called upon every request. This is an anti-pattern as mentioned in [1] and it can be very slow since it loads the jar service file unless a parser has been pre-assigned [2] (e.g. by setting org.xml.sax.driver). SAXParserFactory uses a FactoryFinder [3] instead, which takes advantage of a thread-local cache provided by ServiceLoader. Developers can still pre-assign a factory by setting javax.xml.parsers.SAXParserFactory to make it faster. [1] https://bugs.openjdk.java.net/browse/JDK-6925410 [2] https://github.com/openjdk/jdk/blob/c8add223a10030e40ccef42e081fd0d8f00e0593/src/java.xml/share/classes/org/xml/sax/helpers/XMLReaderFactory.java#L144-L148 [3] https://github.com/openjdk/jdk/blob/66c653c561b3b5e904579af62e23ff94952bca05/src/java.xml/share/classes/javax/xml/parsers/SAXParserFactory.java#L181-L185 See gh-27239
snicoll
added a commit
that referenced
this pull request
Dec 2, 2021
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Labels
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
XMLReaderFactory has been marked as deprecated and without additional
configuration, and it's slower than SAXParserFactory.
Previously
XMLReaderFactory.createXMLReader()
is called upon everyrequest. This is an anti-pattern as mentioned in [1] and it can be very
slow since it loads the jar service file unless a parser has been
pre-assigned [2] (e.g. by setting org.xml.sax.driver).
SAXParserFactory uses a FactoryFinder [3] instead, which takes advantage
of a thread-local cache provided by ServiceLoader. Developers can still
pre-assign a factory by setting javax.xml.parsers.SAXParserFactory to
make it faster.
[1] https://bugs.openjdk.java.net/browse/JDK-6925410
[2] https://github.com/openjdk/jdk/blob/c8add223a10030e40ccef42e081fd0d8f00e0593/src/java.xml/share/classes/org/xml/sax/helpers/XMLReaderFactory.java#L144-L148
[3] https://github.com/openjdk/jdk/blob/66c653c561b3b5e904579af62e23ff94952bca05/src/java.xml/share/classes/javax/xml/parsers/SAXParserFactory.java#L181-L185
Related: #19055
Upstream discussion: https://mail.openjdk.java.net/pipermail/jdk-dev/2021-August/005853.html