This is an automated email from the ASF dual-hosted git repository.
claude pushed a commit to branch update-XMLWriter
in repository https://gitbox.apache.org/repos/asf/creadur-rat.git
The following commit(s) were added to refs/heads/update-XMLWriter by this push:
new 1f83345c fixed sonar issues
1f83345c is described below
commit 1f83345ccaca8edba47e8087f12dd7dde5c43bb0
Author: Claude Warren <[email protected]>
AuthorDate: Sun Mar 22 08:41:32 2026 +0000
fixed sonar issues
---
.../apache/rat/report/xml/writer/XmlWriter.java | 5 +-
.../report/xml/writer/impl/base/XmlWriterTest.java | 74 +++++++++++-----------
.../org/apache/rat/tools/xsd/XsdGenerator.java | 4 +-
3 files changed, 42 insertions(+), 41 deletions(-)
diff --git
a/apache-rat-core/src/main/java/org/apache/rat/report/xml/writer/XmlWriter.java
b/apache-rat-core/src/main/java/org/apache/rat/report/xml/writer/XmlWriter.java
index c74e82d9..d2e73d19 100644
---
a/apache-rat-core/src/main/java/org/apache/rat/report/xml/writer/XmlWriter.java
+++
b/apache-rat-core/src/main/java/org/apache/rat/report/xml/writer/XmlWriter.java
@@ -47,7 +47,6 @@ import org.w3c.dom.Document;
*/
@SuppressWarnings({"checkstyle:MagicNumber", "checkstyle:JavadocVariable"})
public final class XmlWriter implements IXmlWriter {
- private static final String XML_INDENT =
"{http://xml.apache.org/xslt}indent-amount";
private final Appendable appendable;
private final ArrayDeque<CharSequence> elementNames;
private final Set<CharSequence> currentAttributes = new HashSet<>();
@@ -312,8 +311,8 @@ public final class XmlWriter implements IXmlWriter {
@Override
public void close() throws IOException {
closeDocument();
- if (appendable instanceof Closeable) {
- ((Closeable) appendable).close();
+ if (appendable instanceof Closeable closeable) {
+ closeable.close();
}
}
diff --git
a/apache-rat-core/src/test/java/org/apache/rat/report/xml/writer/impl/base/XmlWriterTest.java
b/apache-rat-core/src/test/java/org/apache/rat/report/xml/writer/impl/base/XmlWriterTest.java
index 788d7dbb..4f5ea5a0 100644
---
a/apache-rat-core/src/test/java/org/apache/rat/report/xml/writer/impl/base/XmlWriterTest.java
+++
b/apache-rat-core/src/test/java/org/apache/rat/report/xml/writer/impl/base/XmlWriterTest.java
@@ -18,7 +18,7 @@
*/
package org.apache.rat.report.xml.writer.impl.base;
-import jdk.dynalink.Operation;
+import org.apache.rat.report.xml.writer.IXmlWriter;
import org.apache.rat.report.xml.writer.InvalidXmlException;
import org.apache.rat.report.xml.writer.OperationNotAllowedException;
import org.apache.rat.report.xml.writer.XmlWriter;
@@ -28,6 +28,7 @@ import org.junit.jupiter.api.Test;
import org.w3c.dom.Document;
import java.io.ByteArrayInputStream;
+import java.io.IOException;
import java.io.StringWriter;
import java.nio.charset.StandardCharsets;
import java.util.NoSuchElementException;
@@ -38,7 +39,7 @@ import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.assertTrue;
-public class XmlWriterTest {
+class XmlWriterTest {
private XmlWriter writer;
private StringWriter out;
@@ -50,7 +51,7 @@ public class XmlWriterTest {
}
@Test
- public void returnValues() throws Exception {
+ void returnValues() throws Exception {
assertEquals(
writer, writer.openElement("alpha"), "XmlWriters should always
return themselves");
assertEquals(
@@ -62,7 +63,7 @@ public class XmlWriterTest {
}
@Test
- public void openElement() throws Exception {
+ void openElement() throws Exception {
assertEquals(
writer, writer.openElement("alpha"), "XmlWriters should always
return themselves");
assertEquals("<alpha", out.toString(), "Alpha element started");
@@ -78,7 +79,7 @@ public class XmlWriterTest {
}
@Test
- public void invalidElementName() throws Exception {
+ void invalidElementName() throws Exception {
assertTrue( isValidElementName("alpha"), "All strings ok");
assertTrue(isValidElementName("alpha77"), "Strings and digits ok");
assertFalse(isValidElementName("5alpha77"), "Must no start with
digit");
@@ -106,7 +107,7 @@ public class XmlWriterTest {
}
@Test
- public void callOpenElementAfterLastElementClosed() throws Exception {
+ void callOpenElementAfterLastElementClosed() throws Exception {
assertEquals(
writer, writer.openElement("alpha"), "XmlWriters should always
return themselves");
assertEquals("<alpha", out.toString(), "Alpha element started");
@@ -122,7 +123,7 @@ public class XmlWriterTest {
}
@Test
- public void callCloseElementAfterLastElementClosed() throws Exception {
+ void callCloseElementAfterLastElementClosed() throws Exception {
assertEquals(
writer, writer.openElement("alpha"), "XmlWriters should always
return themselves");
assertEquals("<alpha", out.toString(), "Alpha element started");
@@ -138,7 +139,7 @@ public class XmlWriterTest {
}
@Test
- public void closeFirstElement() throws Exception {
+ void closeFirstElement() throws Exception {
assertEquals(
writer, writer.openElement("alpha"), "XmlWriters should always
return themselves");
assertEquals("<alpha", out.toString(), "Alpha element started");
@@ -148,7 +149,7 @@ public class XmlWriterTest {
}
@Test
- public void closeElementWithContent() throws Exception {
+ void closeElementWithContent() throws Exception {
assertEquals(
writer, writer.openElement("alpha"), "XmlWriters should always
return themselves");
assertEquals("<alpha", out.toString(), "Alpha element started");
@@ -170,7 +171,7 @@ public class XmlWriterTest {
}
@Test
- public void closeElementBeforeFirstElement() throws Exception {
+ void closeElementBeforeFirstElement() throws Exception {
try {
writer.closeElement();
fail("Cannot close elements before the first element has been
closed");
@@ -180,7 +181,7 @@ public class XmlWriterTest {
}
@Test
- public void contentAfterElement() throws Exception {
+ void contentAfterElement() throws Exception {
assertEquals(
writer, writer.openElement("alpha"), "XmlWriters should always
return themselves");
assertEquals("<alpha", out.toString(), "Alpha element started");
@@ -208,7 +209,7 @@ public class XmlWriterTest {
}
@Test
- public void contentAfterLastElement() throws Exception {
+ void contentAfterLastElement() throws Exception {
assertEquals(
writer, writer.openElement("alpha"), "XmlWriters should always
return themselves");
assertEquals("<alpha", out.toString(), "Alpha element started");
@@ -224,7 +225,7 @@ public class XmlWriterTest {
}
@Test
- public void writeContentBeforeFirstElement() throws Exception {
+ void writeContentBeforeFirstElement() throws Exception {
try {
writer.content("Too early");
fail("Cannot close elements before the first element has been
closed");
@@ -234,7 +235,7 @@ public class XmlWriterTest {
}
@Test
- public void contentEscaping() throws Exception {
+ void contentEscaping() throws Exception {
assertEquals(
writer, writer.openElement("alpha"), "XmlWriters should always
return themselves");
assertEquals("<alpha", out.toString(), "Alpha element started");
@@ -251,7 +252,7 @@ public class XmlWriterTest {
}
@Test
- public void attributeAfterLastElement() throws Exception {
+ void attributeAfterLastElement() throws Exception {
assertEquals(
writer, writer.openElement("alpha"), "XmlWriters should always
return themselves");
assertEquals("<alpha", out.toString(), "Alpha element started");
@@ -267,7 +268,7 @@ public class XmlWriterTest {
}
@Test
- public void attributeContentBeforeFirstElement() throws Exception {
+ void attributeContentBeforeFirstElement() throws Exception {
try {
writer.attribute("foo", "bar");
fail("Cannot close elements before the first element has been
closed");
@@ -277,7 +278,7 @@ public class XmlWriterTest {
}
@Test
- public void invalidAttributeName() throws Exception {
+ void invalidAttributeName() throws Exception {
writer.openElement("alpha");
assertTrue(isValidAttributeName("alpha"), "All string ok");
assertTrue(isValidAttributeName("alpha77"), "Strings and digits ok");
@@ -299,7 +300,7 @@ public class XmlWriterTest {
}
@Test
- public void escapeAttributeContent() throws Exception {
+ void escapeAttributeContent() throws Exception {
assertEquals(
writer, writer.openElement("alpha"), "XmlWriters should always
return themselves");
assertEquals("<alpha", out.toString(), "Alpha element started");
@@ -322,7 +323,7 @@ public class XmlWriterTest {
}
@Test
- public void attributeInContent() throws Exception {
+ void attributeInContent() throws Exception {
assertEquals(
writer, writer.openElement("alpha"), "XmlWriters should always
return themselves");
assertEquals("<alpha", out.toString(), "Alpha element started");
@@ -337,7 +338,7 @@ public class XmlWriterTest {
}
@Test
- public void outOfRangeCharacter() throws Exception {
+ void outOfRangeCharacter() throws Exception {
assertEquals(
writer, writer.openElement("alpha"), "XmlWriters should always
return themselves");
assertEquals("<alpha", out.toString(), "Alpha element started");
@@ -363,7 +364,7 @@ public class XmlWriterTest {
}
@Test
- public void attributeAfterElementClosed() throws Exception {
+ void attributeAfterElementClosed() throws Exception {
assertEquals(
writer, writer.openElement("alpha"), "XmlWriters should always
return themselves");
assertEquals("<alpha", out.toString(), "Alpha element started");
@@ -382,7 +383,7 @@ public class XmlWriterTest {
}
@Test
- public void closeDocumentBeforeOpen() throws Exception {
+ void closeDocumentBeforeOpen() throws Exception {
try {
writer.closeDocument();
fail("Cannot close document before the first element has been
opened");
@@ -392,7 +393,7 @@ public class XmlWriterTest {
}
@Test
- public void closeDocumentAfterRootElementClosed() throws Exception {
+ void closeDocumentAfterRootElementClosed() throws Exception {
assertEquals(
writer, writer.openElement("alpha"), "XmlWriters should always
return themselves");
assertEquals("<alpha", out.toString(), "Alpha element started");
@@ -407,7 +408,7 @@ public class XmlWriterTest {
}
@Test
- public void closeSimpleDocument() throws Exception {
+ void closeSimpleDocument() throws Exception {
assertEquals(
writer, writer.openElement("alpha"), "XmlWriters should always
return themselves");
assertEquals("<alpha", out.toString(), "Alpha element started");
@@ -420,7 +421,7 @@ public class XmlWriterTest {
}
@Test
- public void closeComplexDocument() throws Exception {
+ void closeComplexDocument() throws Exception {
assertEquals(
writer, writer.openElement("alpha"), "XmlWriters should always
return themselves");
assertEquals("<alpha", out.toString(), "Alpha element started");
@@ -448,14 +449,14 @@ public class XmlWriterTest {
}
@Test
- public void writeProlog() throws Exception {
+ void writeProlog() throws Exception {
assertEquals(
writer, writer.startDocument(), "XmlWriters should always
return themselves");
assertEquals("<?xml version='1.0'?>", out.toString(), "Prolog
written");
}
@Test
- public void writeAfterElement() throws Exception {
+ void writeAfterElement() throws Exception {
assertEquals(
writer, writer.openElement("alpha"), "XmlWriters should always
return themselves");
assertEquals("<alpha", out.toString(), "Alpha element started");
@@ -468,7 +469,7 @@ public class XmlWriterTest {
}
@Test
- public void writePrologTwo() throws Exception {
+ void writePrologTwo() throws Exception {
assertEquals(
writer, writer.startDocument(), "XmlWriters should always
return themselves");
assertEquals("<?xml version='1.0'?>", out.toString(), "Prolog
written");
@@ -481,7 +482,7 @@ public class XmlWriterTest {
}
@Test
- public void duplicateAttributes() throws Exception {
+ void duplicateAttributes() throws Exception {
assertEquals(
writer, writer.openElement("alpha"), "XmlWriters should always
return themselves");
assertEquals("<alpha", out.toString(), "Alpha element started");
@@ -503,35 +504,36 @@ public class XmlWriterTest {
}
@Test
- public void writeCDataBeforeElement() throws Exception {
+ void writeCDataBeforeElement() {
assertThrows(OperationNotAllowedException.class, () ->
writer.startDocument().cdata("Just cdata").closeDocument());
}
@Test
- public void writeCData() throws Exception {
+ void writeCData() throws Exception {
writer.startDocument().openElement("test").cdata("Just
cdata").closeDocument();
assertEquals("<?xml version='1.0'?><test><![CDATA[ Just cdata
]]></test>", out.toString());
}
@Test
- public void writeCDataEmbeddedCData() throws Exception {
+ void writeCDataEmbeddedCData() throws Exception {
writer.startDocument().openElement("test").cdata("Some <![CDATA[ cdata
]]> text").closeDocument();
assertEquals("<?xml version='1.0'?><test><![CDATA[ Some \\u3C![CDATA[
cdata {rat:CDATA close} text ]]></test>", out.toString());
}
@Test
- public void closeElementBeforeOpened() throws Exception {
- assertThrows(NoSuchElementException.class, () ->
writer.startDocument().openElement("test").closeElement("missing"));
+ void closeElementBeforeOpened() throws IOException {
+ IXmlWriter underTest = writer.startDocument().openElement("test");
+ assertThrows(NoSuchElementException.class, () ->
underTest.closeElement("missing"));
}
@Test
- public void closeElement() throws Exception {
+ void closeElement() throws Exception {
writer.startDocument().openElement("root").openElement("hello").openElement("world").content("hello
world").closeElement("hello").openElement("test").closeDocument();
assertEquals("<?xml version='1.0'?><root><hello><world>hello
world</world></hello><test/></root>", out.toString());
}
@Test
- public void append() throws Exception {
+ void append() throws Exception {
// ensure proper line endings
String expected = String.format("<?xml version='1.0'?><base>%n" +
"<root>%n" +
diff --git
a/apache-rat-tools/src/main/java/org/apache/rat/tools/xsd/XsdGenerator.java
b/apache-rat-tools/src/main/java/org/apache/rat/tools/xsd/XsdGenerator.java
index 9fd8f0c0..a3ceb01c 100644
--- a/apache-rat-tools/src/main/java/org/apache/rat/tools/xsd/XsdGenerator.java
+++ b/apache-rat-tools/src/main/java/org/apache/rat/tools/xsd/XsdGenerator.java
@@ -85,8 +85,8 @@ public class XsdGenerator {
*/
public InputStream getInputStream() throws IOException {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
- try (Writer writer = new OutputStreamWriter(baos,
StandardCharsets.UTF_8)) {
- write(writer);
+ try (Writer otherWriter = new OutputStreamWriter(baos,
StandardCharsets.UTF_8)) {
+ write(otherWriter);
}
return new ByteArrayInputStream(baos.toByteArray());
}