[ 
https://issues.apache.org/jira/browse/IGNITE-3263?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15412561#comment-15412561
 ] 

Denis Magda commented on IGNITE-3263:
-------------------------------------

Saikat, thanks for taking care of this issue. I have the following comments:

1) Please use the following error message {{"Null key is passed for a partition 
calculation. Make sure that an affinity key that is used is initialized 
properly."}}. Next, instead of {{IgniteException}} I would suggest using 
{{IllegalArgumentException}}.

2) The issue has to be fixed for all the affinity functions provided out of the 
box: {{RendezvousAffinityFunction}} and {{FairAffinityFunction}}.

3) Add a test to validate the fix into {{AbstractAffinityFunctionSelfTest}} and 
make sure everything works fine for all our affinity functions.

4) According to pull request you've added the following 
{{examples/src/main/java/org/apache/ignite/examples/datagrid/CacheAffinityPutGetExample.java}}.
 I'm not sure why you did this but it looks wrong to me. Please remove these 
changes. 

> Affinity function must check for null keys
> ------------------------------------------
>
>                 Key: IGNITE-3263
>                 URL: https://issues.apache.org/jira/browse/IGNITE-3263
>             Project: Ignite
>          Issue Type: Bug
>    Affects Versions: 1.6
>            Reporter: Denis Magda
>            Assignee: Saikat Maitra
>              Labels: community
>             Fix For: 1.7
>
>
> AffinityFunction implementations must check for {{null}} keys and through 
> meaningful exceptions in such a cases.
> As an example the following code trows NPE since the keys is not validated
> {code}
> Cache<AffinityKey&lt;String>, Person> personCache = ..;
> personCache.get(new AffinityKey<>(key, affKey)); // returns value
> personCache.get(new AffinityKey<>(key)); // throws NPE
> Exception in thread "main" java.lang.NullPointerException
>         at
> org.apache.ignite.cache.affinity.rendezvous.RendezvousAffinityFunction.partition(RendezvousAffinityFunction.java:428)
>         at
> org.apache.ignite.internal.processors.cache.GridCacheAffinityManager.partition(GridCacheAffinityManager.java:206)
>         at
> org.apache.ignite.internal.processors.cache.GridCacheContext.toCacheKeyObject(GridCacheContext.java:1801)
>         at
> org.apache.ignite.internal.processors.cache.distributed.dht.atomic.GridDhtAtomicCache.get(GridDhtAtomicCache.java:339)
>         at
> org.apache.ignite.internal.processors.cache.GridCacheAdapter.get(GridCacheAdapter.java:4650)
>         at
> org.apache.ignite.internal.processors.cache.GridCacheAdapter.get(GridCacheAdapter.java:1391)
>         at
> org.apache.ignite.internal.processors.cache.IgniteCacheProxy.get(IgniteCacheProxy.java:907)
>         at
> my.apache.ignite.examples.collocation.CacheCollocationExample.main(CacheCollocationExample.java:69)
> {code}



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)

Reply via email to