You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@logging.apache.org by vy...@apache.org on 2022/12/19 10:21:13 UTC

[logging-log4j2] 07/33: LOG4J2-3628 Minor corrections.

This is an automated email from the ASF dual-hosted git repository.

vy pushed a commit to branch mvn-site-simplified
in repository https://gitbox.apache.org/repos/asf/logging-log4j2.git

commit 6d505b6f2cd19af9ea3a7418df2b74db05ff122c
Author: Volkan Yazıcı <vo...@yazi.ci>
AuthorDate: Wed Nov 23 13:16:37 2022 +0100

    LOG4J2-3628 Minor corrections.
---
 .../log4j/internal/util/PositionalSaxEventHandler.java |  2 +-
 .../logging/log4j/internal/util/StringUtils.java       |  2 +-
 .../apache/logging/log4j/internal/util/XmlReader.java  |  9 ++++++++-
 .../apache/logging/log4j/internal/util/XmlWriter.java  |  3 +--
 .../log4j/internal/util/changelog/ChangelogEntry.java  | 18 +++++++++++-------
 .../log4j/internal/util/changelog/ChangelogFiles.java  |  2 +-
 .../internal/util/changelog/ChangelogRelease.java      |  2 +-
 7 files changed, 24 insertions(+), 14 deletions(-)

diff --git a/log4j-internal-util/src/main/java/org/apache/logging/log4j/internal/util/PositionalSaxEventHandler.java b/log4j-internal-util/src/main/java/org/apache/logging/log4j/internal/util/PositionalSaxEventHandler.java
index b74f75018e..7ca575c951 100644
--- a/log4j-internal-util/src/main/java/org/apache/logging/log4j/internal/util/PositionalSaxEventHandler.java
+++ b/log4j-internal-util/src/main/java/org/apache/logging/log4j/internal/util/PositionalSaxEventHandler.java
@@ -6,7 +6,7 @@
  * (the "License"); you may not use this file except in compliance with
  * the License. You may obtain a copy of the License at
  *
- *      http://www.apache.org/licenses/LICENSE-2.0
+ *      https://www.apache.org/licenses/LICENSE-2.0
  *
  * Unless required by applicable law or agreed to in writing, software
  * distributed under the License is distributed on an "AS IS" BASIS,
diff --git a/log4j-internal-util/src/main/java/org/apache/logging/log4j/internal/util/StringUtils.java b/log4j-internal-util/src/main/java/org/apache/logging/log4j/internal/util/StringUtils.java
index 93bc1c942a..950e5f5844 100644
--- a/log4j-internal-util/src/main/java/org/apache/logging/log4j/internal/util/StringUtils.java
+++ b/log4j-internal-util/src/main/java/org/apache/logging/log4j/internal/util/StringUtils.java
@@ -6,7 +6,7 @@
  * (the "License"); you may not use this file except in compliance with
  * the License. You may obtain a copy of the License at
  *
- *      http://www.apache.org/licenses/LICENSE-2.0
+ *      https://www.apache.org/licenses/LICENSE-2.0
  *
  * Unless required by applicable law or agreed to in writing, software
  * distributed under the License is distributed on an "AS IS" BASIS,
diff --git a/log4j-internal-util/src/main/java/org/apache/logging/log4j/internal/util/XmlReader.java b/log4j-internal-util/src/main/java/org/apache/logging/log4j/internal/util/XmlReader.java
index f4045315d7..35650ed1ba 100644
--- a/log4j-internal-util/src/main/java/org/apache/logging/log4j/internal/util/XmlReader.java
+++ b/log4j-internal-util/src/main/java/org/apache/logging/log4j/internal/util/XmlReader.java
@@ -6,7 +6,7 @@
  * (the "License"); you may not use this file except in compliance with
  * the License. You may obtain a copy of the License at
  *
- *      http://www.apache.org/licenses/LICENSE-2.0
+ *      https://www.apache.org/licenses/LICENSE-2.0
  *
  * Unless required by applicable law or agreed to in writing, software
  * distributed under the License is distributed on an "AS IS" BASIS,
@@ -64,6 +64,13 @@ public final class XmlReader {
         return document;
     }
 
+    public static String requireAttribute(final Element element, final String attributeName) {
+        if (!element.hasAttribute(attributeName)) {
+            throw failureAtXmlNode(element, "missing attribute: `%s`", attributeName);
+        }
+        return element.getAttribute(attributeName);
+    }
+
     public static RuntimeException failureAtXmlNode(
             final Node node,
             final String messageFormat,
diff --git a/log4j-internal-util/src/main/java/org/apache/logging/log4j/internal/util/XmlWriter.java b/log4j-internal-util/src/main/java/org/apache/logging/log4j/internal/util/XmlWriter.java
index b797eb0853..8eeadf182a 100644
--- a/log4j-internal-util/src/main/java/org/apache/logging/log4j/internal/util/XmlWriter.java
+++ b/log4j-internal-util/src/main/java/org/apache/logging/log4j/internal/util/XmlWriter.java
@@ -6,7 +6,7 @@
  * (the "License"); you may not use this file except in compliance with
  * the License. You may obtain a copy of the License at
  *
- *      http://www.apache.org/licenses/LICENSE-2.0
+ *      https://www.apache.org/licenses/LICENSE-2.0
  *
  * Unless required by applicable law or agreed to in writing, software
  * distributed under the License is distributed on an "AS IS" BASIS,
@@ -30,7 +30,6 @@ import java.io.StringWriter;
 import java.nio.charset.Charset;
 import java.nio.charset.StandardCharsets;
 import java.nio.file.Files;
-import java.nio.file.OpenOption;
 import java.nio.file.Path;
 import java.nio.file.StandardOpenOption;
 import java.util.function.Consumer;
diff --git a/log4j-internal-util/src/main/java/org/apache/logging/log4j/internal/util/changelog/ChangelogEntry.java b/log4j-internal-util/src/main/java/org/apache/logging/log4j/internal/util/changelog/ChangelogEntry.java
index f662a75c9b..fb2bac38d2 100644
--- a/log4j-internal-util/src/main/java/org/apache/logging/log4j/internal/util/changelog/ChangelogEntry.java
+++ b/log4j-internal-util/src/main/java/org/apache/logging/log4j/internal/util/changelog/ChangelogEntry.java
@@ -6,7 +6,7 @@
  * (the "License"); you may not use this file except in compliance with
  * the License. You may obtain a copy of the License at
  *
- *      http://www.apache.org/licenses/LICENSE-2.0
+ *      https://www.apache.org/licenses/LICENSE-2.0
  *
  * Unless required by applicable law or agreed to in writing, software
  * distributed under the License is distributed on an "AS IS" BASIS,
@@ -156,7 +156,7 @@ public final class ChangelogEntry {
 
         // Read the `entry` root element.
         final Element entryElement = XmlReader.readXmlFileRootElement(path, "entry");
-        final String typeAttribute = entryElement.getAttribute("type");
+        final String typeAttribute = XmlReader.requireAttribute(entryElement, "type");
         final Type type;
         try {
             type = Type.fromXmlAttribute(typeAttribute);
@@ -171,8 +171,8 @@ public final class ChangelogEntry {
                 .range(0, issueCount)
                 .mapToObj(issueIndex -> {
                     final Element issueElement = (Element) issueElements.item(issueIndex);
-                    final String issueId = issueElement.getAttribute("id");
-                    final String issueLink = issueElement.getAttribute("link");
+                    final String issueId = XmlReader.requireAttribute(issueElement, "id");
+                    final String issueLink = XmlReader.requireAttribute(issueElement, "link");
                     return new Issue(issueId, issueLink);
                 })
                 .collect(Collectors.toList());
@@ -187,8 +187,12 @@ public final class ChangelogEntry {
                 .range(0, authorCount)
                 .mapToObj(authorIndex -> {
                     final Element authorElement = (Element) authorElements.item(authorIndex);
-                    final String authorId = authorElement.getAttribute("id");
-                    final String authorName = authorElement.getAttribute("name");
+                    final String authorId = authorElement.hasAttribute("id")
+                            ? authorElement.getAttribute("id")
+                            : null;
+                    final String authorName = authorElement.hasAttribute("name")
+                            ? authorElement.getAttribute("name")
+                            : null;
                     return new Author(authorId, authorName);
                 })
                 .collect(Collectors.toList());
@@ -201,7 +205,7 @@ public final class ChangelogEntry {
                     entryElement, "was expecting a single `description` element, found: %d", descriptionCount);
         }
         final Element descriptionElement = (Element) descriptionElements.item(0);
-        final String descriptionFormat = descriptionElement.getAttribute("format");
+        final String descriptionFormat = XmlReader.requireAttribute(descriptionElement, "format");
         final String descriptionText = trimNullable(descriptionElement.getTextContent());
         final Description description = new Description(descriptionFormat, descriptionText);
 
diff --git a/log4j-internal-util/src/main/java/org/apache/logging/log4j/internal/util/changelog/ChangelogFiles.java b/log4j-internal-util/src/main/java/org/apache/logging/log4j/internal/util/changelog/ChangelogFiles.java
index 598c6e378a..fc0b05aab6 100644
--- a/log4j-internal-util/src/main/java/org/apache/logging/log4j/internal/util/changelog/ChangelogFiles.java
+++ b/log4j-internal-util/src/main/java/org/apache/logging/log4j/internal/util/changelog/ChangelogFiles.java
@@ -6,7 +6,7 @@
  * (the "License"); you may not use this file except in compliance with
  * the License. You may obtain a copy of the License at
  *
- *      http://www.apache.org/licenses/LICENSE-2.0
+ *      https://www.apache.org/licenses/LICENSE-2.0
  *
  * Unless required by applicable law or agreed to in writing, software
  * distributed under the License is distributed on an "AS IS" BASIS,
diff --git a/log4j-internal-util/src/main/java/org/apache/logging/log4j/internal/util/changelog/ChangelogRelease.java b/log4j-internal-util/src/main/java/org/apache/logging/log4j/internal/util/changelog/ChangelogRelease.java
index d044f42eca..38c62019ae 100644
--- a/log4j-internal-util/src/main/java/org/apache/logging/log4j/internal/util/changelog/ChangelogRelease.java
+++ b/log4j-internal-util/src/main/java/org/apache/logging/log4j/internal/util/changelog/ChangelogRelease.java
@@ -6,7 +6,7 @@
  * (the "License"); you may not use this file except in compliance with
  * the License. You may obtain a copy of the License at
  *
- *      http://www.apache.org/licenses/LICENSE-2.0
+ *      https://www.apache.org/licenses/LICENSE-2.0
  *
  * Unless required by applicable law or agreed to in writing, software
  * distributed under the License is distributed on an "AS IS" BASIS,