Skip to content

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

Closed
@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

Activity

added
bugConfirmed bug that we should fix
on Jan 28, 2025
added this to the 1.19.1 milestone on Jan 28, 2025
self-assigned this
on Jan 28, 2025
added a commit that references this issue on Jan 28, 2025
5d31cac
Repository owner deleted a comment from cassiork on Feb 6, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

bugConfirmed bug that we should fixfixed

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions

    Setting `charset` on an empty XML doc throws and index out of bounds exception · Issue #2266 · jhy/jsoup