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

Should add null check when put data into concurrenthashmap #526

Closed
jdneo opened this issue Jan 15, 2018 · 9 comments
Closed

Should add null check when put data into concurrenthashmap #526

jdneo opened this issue Jan 15, 2018 · 9 comments
Assignees
Labels
Milestone

Comments

@jdneo
Copy link
Member

jdneo commented Jan 15, 2018

The code here:
https://github.com/Microsoft/ApplicationInsights-Java/blob/v1.0.9/core/src/main/java/com/microsoft/applicationinsights/internal/util/MapUtil.java#L43

put data into a ConCurrentHashMap but does not have null check.

which will casue an NPE error if the entry.getValue() is null.

@dhaval24
Copy link
Contributor

@jdneo thanks for pointing this out. By the way recent master also might have the same issue. Is it possible for you to send out a PR for this. Your contribution would be greatly appreciated. Let me know.

@dhaval24 dhaval24 added the Bug label Jan 15, 2018
@jdneo
Copy link
Member Author

jdneo commented Jan 15, 2018

Hi @dhaval24 Sure, I'll send a PR sooner.

@dhaval24
Copy link
Contributor

@jdneo thank you very much. Just curios have you encountered this issue while SDK is running? Wondering how you caught this up.

@jdneo
Copy link
Member Author

jdneo commented Jan 15, 2018

@dhaval24
Copy link
Contributor

I see. So just was checking the java docs and found that standard maps allow null keys and values but concurrent map doesn't allow them. Since this method is generic for any kind of maps it would make sense to apply check with condition on type too (source instance of ConcurrentHashMap && entry.getValue() != null)

@jdneo
Copy link
Member Author

jdneo commented Jan 15, 2018

Yes, but if entry.getValue() is null, what should we do? Since we have no ide what type is for Value

@dhaval24
Copy link
Contributor

In case of concurrent maps, key with null value doesn't make sense at all so we might skip the key itself. and then log a trace with the help of Internal SDK Logger. (InternalLogger.instance.trace("Skipping key %s while copying because of null value", value)

@jdneo
Copy link
Member Author

jdneo commented Jan 15, 2018

@dhaval24 That's fine!

@dhaval24
Copy link
Contributor

@jdneo please also do add a test case for it :-)

@dhaval24 dhaval24 added this to the 2.0.1 milestone Jan 15, 2018
littleaj added a commit that referenced this issue Jan 29, 2018
@microsoft microsoft locked as resolved and limited conversation to collaborators Jul 21, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

2 participants