`DOMWrappingReader.getDepth()` is one too low at `START_ELEMENT`, and typed array reads lose a level
まだ誰も着手していません。
評価
調査の方向性
Start in DOMWrappingReader, where getDepth() returns _depth as is and readElementAsArray() moves into children or the virtual END_ELEMENT without the ++_depth that next() applies. Compare with Stax2ReaderAdapter.getDepth(), which is the reference for the expected values, and reproduce the two tables in the issue with a DOMSource. Done when getDepth() matches the expected values at START_ELEMENT, END_ELEMENT and after array reads, and the existing tests still pass. The compatibility impact on WstxDOMWrappingReader users needs a maintainer decision.
索引モデルが issue の本文から書いたものです。
説明
Bug found when fixing #60, I'm afraid Claude is right here, too.
I can provide the PR if you wish.
XMLStreamReader2.getDepth() is documented as 1 at the root element itself, and the same for a start element and its matching end element. DOMWrappingReader breaks this in two ways:
- At every
START_ELEMENT,getDepth()returns one less than it should._depthis only incremented whennext()moves past the start element, andgetDepth()returns it as is. Values atEND_ELEMENTand inside elements are correct. readElementAsArray()(and soreadElementAsIntArray()etc.) permanently lowers the depth by one. Starting atSTART_ELEMENT, it moves into the children (or to the virtualEND_ELEMENTof an empty element) without the++_depththatnext()does there, but leaving theEND_ELEMENTstill does--_depth. This happens for every array read, whether partial, complete or of an empty element. Each one lowers all later depths by one more.
This affects Woodstox too: WstxDOMWrappingReader, returned for any DOMSource, inherits both methods without overriding them. So its depths differ from Woodstox's own stream reader for the same document (TestXMLStreamReader2 in Woodstox checks the stream reader only; no DOM test checks getDepth()). Stax2ReaderAdapter reports the correct values in all cases below.
Repro (depth after each event):
| Document, action | Expected | DOMWrappingReader |
|---|---|---|
<root><a><b/></a>x<c/></root>, plain next() loop |
<root>1 <a>2 <b>3 </b>3 </a>2 x:1 <c>2 </c>2 </root>1 |
<root>0 <a>1 <b>2 </b>3 </a>2 x:1 <c>1 </c>2 </root>1 |
<root><a>1 2 3</a><b/></root>, <a> read with readElementAsIntArray() to the end |
<root>1 <a>2 </a>2 <b>2 </b>2 </root>1 |
<root>0 <a>1 </a>1 <b>0 </b>1 </root>0 |
Coalescing or not makes no difference. Same results for a partial read followed by next(), and for an empty <a/>.
Fix:
getDepth(): return_depth+1when the current event isSTART_ELEMENT. This mirrors theEND_ELEMENTadjustment inStax2ReaderAdapter.getDepth().readElementAsArray():++_depthwhen starting atSTART_ELEMENT, before either branch (children or empty element).
Checked with a temporary patch: all cases above then match Stax2ReaderAdapter, and the existing tests pass.
Compatibility: fix 1 changes the value callers get at every START_ELEMENT from a DOM reader, including Woodstox users with a DOMSource. Callers that adjusted for the old value will be off by one in the other direction. Fix 2 only changes behaviour after array reads, where the old values were wrong in any case.
- 主要言語
- Java
- スター
- 42
- フォーク
- 21
- 平均マージ
- 3時間 50分
- マージ済み PR(30日)
- 2
環境構築
このプロジェクトには開発コンテナ、Dockerfile、コントリビューションガイドがありません。まず README を読み、一般的な手順ははじめてのコントリビューションガイドを参照してください。
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
FasterXML/stax2-api のほかの issue
-
難易度 4/5 3〜5日 初心者へのやさしさ 45/100
-
`Stax2ReaderAdapter.nextTag()` skips the adapter's own state handling対応中かも @winfriedgerlach が 35 日前に担当しました。 オープン
難易度 3/5 半日 初心者へのやさしさ 70/100
-
難易度 2/5 1〜3時間 初心者へのやさしさ 35/100
FasterXML/stax2-api の issue をすべて見る
似ている issue
-
Cleanup: restore the interrupt flag in AiFailureAnalyzer対応中かも @Rishankgupta08 が今日担当しました。 オープンgood first issue
難易度 2/5 1〜3時間 初心者へのやさしさ 82/100
seleniumboot/selenium-boot#258 · コメント 1 件 ·
メンテナーはふだん 1 日以内に返信
-
bug
難易度 2/5 1〜3時間 初心者へのやさしさ 70/100
dense-analysis/ale#5181 ·
-
bug subsystem:agent-harness triage
難易度 2/5 1〜3時間 初心者へのやさしさ 76/100
ShaftHQ/SHAFT_ENGINE#8043 ·
メンテナーはふだん 1 日以内に返信
-
難易度 1/5 1時間未満 初心者へのやさしさ 88/100
johanhaleby/occurrent#1505 ·
メンテナーはふだん 1 日以内に返信
-
bug
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
メンテナーはふだん 1 日以内に返信