jackson-core: `FilteringParserDelegate` can go into an infinite loop if underlying parser is non-blocking
Jackson version (BOM): 2.15.2
While experimenting with JsonPointer in Spring Framework, I tried to build up on the existing FilteringParserDelegate and associated JsonPointerBasedTokenFilter. Unfortunately, this doesn’t seem to work with a non-blocking JsonParser delegate, for several reasons:
- it doesn’t delegate method
canParseAsync()(ends up returning the default interface implem =>false) - it doesn’t delegate method
getNonBlockingInputFeeder()(same as above =>null) - it isn’t aware of
JsonToken.NOT_AVAILABLE
While the first two are easily circumvented by extending FilteringParserDelegate, the last one is the truly problematic one. It results in going down the code path of a “scalar value”, and will continuously call delegate.nextToken() which continues to result in NOT_AVAILABLE.
This leads to an infinite loop when attempting to filter based on a JsonPointer on top of a non-blocking parser.
Is there anything fundamentally preventing FilteringParserDelegate from being compatible with non-blocking parsers that I might have overlooked? Otherwise I think it’s pretty close, hopefully that can be fixed 😄
About this issue
- Original URL
- State: closed
- Created 3 years ago
- Comments: 15 (12 by maintainers)
Commits related to this issue
- Add failing test for #1144 — committed to FasterXML/jackson-core by cowtowncoder 3 years ago
- Add failing test for #1144 (#1189) — committed to FasterXML/jackson-core by cowtowncoder 3 years ago
Re-reading what I said earlier, I think that my thinking was that:
JsonToken.NOT_AVAILABLEever returned)JsonToken.NOT_AVAILABLEjust fail (if it doesn’t already).As to test, executor; I’m pretty sure that was just meant to bail out from test when infinite loop occurs.
Does this make more sense?
Not sure what you mean by that. That said I can understand the apprehensiveness of failing the constructor and how to document that.
If you feel the risk is too big in terms of impact on existing users, I guess a big WARN logging would perhaps be the next best thing 🤷♂️ But from my perspective there is currently no point in accepting a non-blocking parser in a constructor nor in a factory method, since that will inevitably lead to infinite looping.
👍
@simonbasle All legit, and also bit challenging to do… esp. since patch release typically should not change behavior minus bug fixes. And while there are tests, I think due to complexity of filtering delegation, there are still gaps.
For patch release, ideally I do think
NOT_AVAILABLEshould be recognized… yet that’s not a small change probably. On refusing constructing for async-parser (there is a method to call to check fortunately) – and maybe having alternate constructor/factory method that would allow it? (since one can, in theory, make it all work as long as all content for a doc is passed immediately) – that’d have to go in a new minor version (2.17).I’d like to improve things here, and maybe I can. But it does need to fight wrt all other priorities.
But I’ll keep this on my ever-expanding todo-list.
hey @cowtowncoder, thanks for the analysis. unfortunately I don’t think I will have the possibility to try to add changes anytime soon 😞
hopefully there is some kind of low hanging fruit where the parsing doesn’t work but fails fast ? (e.g. throwing an exception if the underlying parser is returning
NOT_AVAILABLE? or even if the parser passed in the constructor is async ?) this wouldn’t really help in my case (async parsing of merely a sub-set of a document, pointed at by aJsonPointer), but at least it would avoid tricky livelock situations.