Skip to content
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

Replace deprecated methods that don't properly handle encoding #1033

Merged
merged 1 commit into from
Mar 8, 2023
Merged

Conversation

elharo
Copy link
Contributor

@elharo elharo commented Mar 4, 2023

No description provided.

@elharo elharo requested a review from gnodet March 4, 2023 14:37
Copy link
Contributor

@gnodet gnodet left a comment

Choose a reason for hiding this comment

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

Could you set up a small test case showing what the actual problem is ?
I fail to see what the change brings....

MetadataXpp3Reader mappingReader = new MetadataXpp3Reader();
try (InputStream in = Files.newInputStream(mappingFile.toPath())) {
Metadata result = mappingReader.read(in, false);
return result;
} catch (FileNotFoundException e) {
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't see the benefit of the change.
mappingReader.read( Files.newInputStream( mappingFile.toPath() ), false ) is exactly the same as mappingReader.read( ReaderFactory.newXmlReader( mappingFile ), false ).
The reason is that the read method accepting an InputStream does create an xml reader using ReaderFactory.newXmlReader.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That is indeed something else that needs to be changed. There is no reason to convert an input stream to a reader immediately before passing it to an XML parser, and in fact that introduces an additional way things can break if the encoding is guessed wrong.

Until that can be done too, this at least removes a couple more dependencies on plexus-util.

try (Writer writer = WriterFactory.newXmlWriter(metadataFile)) {
new MetadataXpp3Writer().write(writer, metadata);
try (OutputStream out = Files.newOutputStream(metadataFile.toPath())) {
new MetadataXpp3Writer().write(out, metadata);
Copy link
Contributor

Choose a reason for hiding this comment

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

If the change has an actual effect, this means that the XmlWriter created by the WriterFactory cannot detect the encoding properly. If that's the case, it should also be fixed.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

WriterFactory here is an unnecessary layer of indirection. It accomplishes nothing that can't be done with JDK standard APIs. I ultimately want to get rid of it.

@elharo
Copy link
Contributor Author

elharo commented Mar 7, 2023

Test cases here would be iffy, because the behavior is system dependent and most of the time this will just work. However there can be flaky behavior with non-ASCII characters when the Locale is something uncommon like Turkish. Generally when parsing XML one should let the parser detect the encoding, rather than trying to guess it.

@gnodet gnodet changed the title replace deprecated methods that don't properly handle encoding Replace deprecated methods that don't properly handle encoding Mar 7, 2023
@gnodet gnodet added this to the 4.0.0-alpha-5 milestone Mar 7, 2023
@elharo elharo merged commit bec19ec into master Mar 8, 2023
@elharo elharo deleted the more branch March 8, 2023 00:11
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.

2 participants