You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@maven.apache.org by "gnodet (via GitHub)" <gi...@apache.org> on 2023/03/07 19:18:19 UTC

[GitHub] [maven] gnodet commented on a diff in pull request #1033: replace deprecated methods that don't properly handle encoding

gnodet commented on code in PR #1033:
URL: https://github.com/apache/maven/pull/1033#discussion_r1128428710


##########
maven-compat/src/main/java/org/apache/maven/artifact/repository/metadata/DefaultRepositoryMetadataManager.java:
##########
@@ -267,19 +266,17 @@ private boolean loadMetadata(
      * TODO share with DefaultPluginMappingManager.
      */
     protected Metadata readMetadata(File mappingFile) throws RepositoryMetadataReadException {
-        Metadata result;
 
-        try (Reader reader = ReaderFactory.newXmlReader(mappingFile)) {
-            MetadataXpp3Reader mappingReader = new MetadataXpp3Reader();
-
-            result = mappingReader.read(reader, false);
+        MetadataXpp3Reader mappingReader = new MetadataXpp3Reader();
+        try (InputStream in = Files.newInputStream(mappingFile.toPath())) {
+            Metadata result = mappingReader.read(in, false);
+            return result;
         } catch (FileNotFoundException e) {

Review Comment:
   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`.



##########
maven-compat/src/main/java/org/apache/maven/artifact/repository/metadata/DefaultRepositoryMetadataManager.java:
##########
@@ -310,8 +307,8 @@ private void fixTimestamp(File metadataFile, Metadata metadata, Metadata referen
         if (changed) {
             getLogger().debug("Repairing metadata in " + metadataFile);
 
-            try (Writer writer = WriterFactory.newXmlWriter(metadataFile)) {
-                new MetadataXpp3Writer().write(writer, metadata);
+            try (OutputStream out = Files.newOutputStream(metadataFile.toPath())) {
+                new MetadataXpp3Writer().write(out, metadata);

Review Comment:
   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.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@maven.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org