Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions release-notes/VERSION
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ Project: Stax2 API
(contributed by @winfriedgerlach)
#44: Free memory after `Stax2Util.ByteAggregator.aggregateAll()`
(contributed by @winfriedgerlach)
#45: Fix swapped arguments in `AttributeEventImpl.writeUsing()`
(contributed by @winfriedgerlach)
- Branch "master" renamed as "main"

4.3.0 (31-Mar-2026)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,8 @@ public void writeAsEncodedUnicode(Writer w)
public void writeUsing(XMLStreamWriter2 w) throws XMLStreamException
{
QName n = mName;
w.writeAttribute(n.getPrefix(), n.getLocalPart(),
n.getNamespaceURI(), mValue);
w.writeAttribute(n.getPrefix(), n.getNamespaceURI(),
n.getLocalPart(), mValue);
}

/*
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
package org.codehaus.stax2.ri.evt;

import java.io.StringWriter;

import javax.xml.namespace.QName;
import javax.xml.stream.XMLOutputFactory;
import javax.xml.stream.XMLStreamException;

import org.codehaus.stax2.XMLStreamWriter2;
import org.codehaus.stax2.ri.Stax2WriterAdapter;
import org.junit.jupiter.api.Test;

import static org.junit.jupiter.api.Assertions.*;

/**
* Tests for {@link AttributeEventImpl}, mostly regarding
* [stax2-api#45]: swapped arguments in {@code writeUsing()}.
*/
public class AttributeEventImplTest
{
@Test
public void testWriteUsingWithNamespace() throws Exception
{
AttributeEventImpl attr = new AttributeEventImpl(null,
new QName("urn:test", "attr", "p"), "value", true);
assertEquals("<root xmlns:p=\"urn:test\" p:attr=\"value\"></root>",
writeWithAttribute("p", "urn:test", attr));
}

@Test
public void testWriteUsingWithoutNamespace() throws Exception
{
AttributeEventImpl attr = new AttributeEventImpl(null,
new QName("attr"), "value", true);
assertEquals("<root attr=\"value\"></root>",
writeWithAttribute(null, null, attr));
}

// Writes attribute via writeUsing() on a Stax2-wrapped JDK stream writer
private static String writeWithAttribute(String nsPrefix, String nsURI,
AttributeEventImpl attr)
throws XMLStreamException
{
StringWriter out = new StringWriter();
XMLStreamWriter2 w = Stax2WriterAdapter.wrapIfNecessary(
XMLOutputFactory.newInstance().createXMLStreamWriter(out));
w.writeStartElement("root");
if (nsPrefix != null) {
w.writeNamespace(nsPrefix, nsURI);
}
attr.writeUsing(w);
w.writeEndElement();
w.close();
return out.toString();
}
}
Loading