Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BeanPropertyMap NPE when enable ACCEPT_CASE_INSENSITIVE_PROPERTIES. version: 2.11.0.rc1 #2669

Closed
chowtin opened this issue Mar 28, 2020 · 7 comments
Milestone

Comments

@chowtin
Copy link

chowtin commented Mar 28, 2020

    public BeanPropertyMap(boolean caseInsensitive, Collection<SettableBeanProperty> props,
            Map<String,List<PropertyName>> aliasDefs,
            Locale locale)
    {
        _caseInsensitive = caseInsensitive;
        _propsInOrder = props.toArray(new SettableBeanProperty[props.size()]);
        _aliasDefs = aliasDefs;
        _aliasMapping = _buildAliasMapping(aliasDefs);
        _locale = locale;
        init(props);
    }

....

    private Map<String,String> _buildAliasMapping(Map<String,List<PropertyName>> defs)
    {
        if ((defs == null) || defs.isEmpty()) {
            return Collections.emptyMap();
        }
        Map<String,String> aliases = new HashMap<>();
        for (Map.Entry<String,List<PropertyName>> entry : defs.entrySet()) {
            String key = entry.getKey();
            if (_caseInsensitive) {
                key = key.toLowerCase(_locale);
            }
            for (PropertyName pn : entry.getValue()) {
                String mapped = pn.getSimpleName();
                if (_caseInsensitive) {
                    mapped = mapped.toLowerCase();
                }
                aliases.put(mapped, key);
            }
        }
        return aliases;
    }

Issue is from the order of below two statements.

        _aliasMapping = _buildAliasMapping(aliasDefs);
        _locale = locale;

BeanPropertyMap::_buildAliasMapping used a un-initialized _locale.

stacktrace:

java.lang.NullPointerException
	at java.lang.String.toLowerCase(String.java:2563)
	at com.fasterxml.jackson.databind.deser.impl.BeanPropertyMap._buildAliasMapping(BeanPropertyMap.java:820)
	at com.fasterxml.jackson.databind.deser.impl.BeanPropertyMap.<init>(BeanPropertyMap.java:100)
@cowtowncoder cowtowncoder added 2.11 need-test-case To work on issue, a reproduction (ideally unit test) needed labels Mar 29, 2020
@cowtowncoder
Copy link
Member

Thank you for reporting the issue.

One thing that I'd need, in addition to useful information already included, would be example code that triggers the problem. This because none of existing unit tests hits that so I think there is some specific configuration or usage that causes this.

@chowtin
Copy link
Author

chowtin commented Mar 30, 2020

below is the testcase.
add JsonAlias on one field

    static class Pojo {

        @JsonAlias({"nick", "name"})
        private String name;

        public String getName() {
            return name;
        }

        public void setName(String name) {
            this.name = name;
        }
    }

    @Test
    public void testJackson() throws JsonProcessingException {

        ObjectMapper objectMapper = new ObjectMapper();
        objectMapper.configure(MapperFeature.ACCEPT_CASE_INSENSITIVE_PROPERTIES, true);

        String text = "{\"name\":\"test\"}";
        Pojo pojo = objectMapper.readValue(text, Pojo.class);
        Assert.assertNotNull(pojo);
    }

@cowtowncoder cowtowncoder removed the need-test-case To work on issue, a reproduction (ideally unit test) needed label Mar 30, 2020
@cowtowncoder
Copy link
Member

@chowtin thank you!

@cowtowncoder
Copy link
Member

cowtowncoder commented Mar 30, 2020

@chowtin I can not reproduce the issue: which version are you using? Would it be possible to verify with the latest released version (2.10.3)? There have been some fixes (like #1854) that sound similar.

cowtowncoder added a commit that referenced this issue Mar 30, 2020
@chowtin
Copy link
Author

chowtin commented Mar 31, 2020

2.10.3 works.

2.11.0.rc1 raise error. (I should use a released version)

@cowtowncoder
Copy link
Member

cowtowncoder commented Mar 31, 2020

@chowtin Hmmmh. Ok, thank you for verifying. Testing with 2.11.0.rc1 is perfectly fine; this one was actually my mistake.
I think what happened here was that I tested with 2.10 branch (since if it was failing there, I would want to fix it for 2.10.4 too). But did not yet merge test into 2.11, or run there.

Now I can reproduce it with 2.11 branch. Thank you!

@cowtowncoder cowtowncoder added this to the 2.11.0.rc2 milestone Mar 31, 2020
@cowtowncoder
Copy link
Member

Ok good -- seconds rc1-only bug found, now fixed. Thank you @chowtin for the report!

@cowtowncoder cowtowncoder removed the 2.11 label Apr 12, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants