Skip to content

Setting charset on an empty XML doc throws and index out of bounds exception #2266

@jhy

Description

@jhy
Document xml = new Document(Parser.NamespaceXml, "https://example.com"); // no child nodes yet
xml.outputSettings().syntax(Syntax.xml);
xml.charset(StandardCharsets.UTF_8);
Caused by: java.lang.IndexOutOfBoundsException: Index 0 out of bounds for length 0
	at java.base/jdk.internal.util.Preconditions.outOfBounds(Preconditions.java:64)
	at java.base/jdk.internal.util.Preconditions.outOfBoundsCheckIndex(Preconditions.java:70)
	at java.base/jdk.internal.util.Preconditions.checkIndex(Preconditions.java:266)
	at java.base/java.util.Objects.checkIndex(Objects.java:361)
	at java.base/java.util.ArrayList.get(ArrayList.java:427)
	at org.jsoup.nodes.Document.ensureMetaCharsetElement(Document.java:366)
	at org.jsoup.nodes.Document.charset(Document.java:274)
	at suds.Feed.generateFeed(Feed.java:35)
	at suds.Suds.processEverything(Suds.java:120)
	... 1 more

Metadata

Metadata

Assignees

Labels

bugA confirmed bug, that we should fixfixedAn {bug|improvement} that has been {fixed|implemented}

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions