Skip to content

Bug in FilteringParserDelegate #649

@jhaber

Description

@jhaber

There seems to be a bug in FilteringParserDelegate that specifically manifests when trying to filter out arrays. Here's a test that reproduces the behavior (can be added to BasicParserFilteringTest):

    public void testExcludeArrays() throws Exception
    {
        class NoArraysFilter extends TokenFilter
        {
            @Override
            public TokenFilter filterStartArray() {
                return null;
            }
        }

        String jsonString = aposToQuotes("{'a':123,'array':[1,2]}");
        JsonParser p0 = JSON_F.createParser(jsonString);
        FilteringParserDelegate p = new FilteringParserDelegate(p0,
            new NoArraysFilter(),
            true, // includePath
            true // multipleMatches
        );
        String result = readAndWrite(JSON_F, p);
        assertEquals(aposToQuotes("{'a':123}"), result);
        assertEquals(1, p.getMatchCount());
    }

This test fails with:

junit.framework.ComparisonFailure: 
Expected :{"a":123}
Actual   :{"a"}

I discovered this bug while adding test coverage for #573. However, I confirmed that the bug exists in jackson-core versions 2.8.9, 2.9.10, 2.10.5, and 2.11.3 (and therefore wasn't introduced in #573).

No one has complained yet, and a quick GitHub search suggests there isn't much code in the wild (if any) doing filterStartArray() { return null; } so I don't think it's a high priority to fix this. I mainly just wanted to log this issue so that I can link to it (above the commented out unit test)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions