You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@ignite.apache.org by Cong Guo <co...@huawei.com> on 2018/07/23 17:59:44 UTC

UnsupportedOperationException when updating a field in binary object

Hi,

I use a Set class as a field. When I update the field via the BinaryObjectBuilder, I get an UnsupportedOperationException.

I use QueryEntity to set the field like:

fieldNameTypeMap.put(tags_FieldStr, Set.class.getName());

Then my update function (in my EntryProcessor) is like:

BinaryObjectBuilder boBuilder = bo.toBuilder();
Set<String> tags = boBuilder.getField(tags_FieldStr);
tags.add(tag);
boBuilder.setField(tags_FieldStr, tags, Set.class);

The exception shows:

Caused by: java.lang.UnsupportedOperationException
at java.util.Collections$UnmodifiableCollection.add(Collections.java:1055)
at com.myproject.managers.common.BOHelperImpl$4.process(BOHelperImpl.java:390)
        at org.apache.ignite.internal.processors.cache.EntryProcessorResourceInjectorProxy.process(EntryProcessorResourceInjectorProxy.java:68)
        at org.apache.ignite.internal.processors.cache.GridCacheMapEntry$AtomicCacheUpdateClosure.runEntryProcessor(GridCacheMapEntry.java:5142)
        at org.apache.ignite.internal.processors.cache.GridCacheMapEntry$AtomicCacheUpdateClosure.call(GridCacheMapEntry.java:4550)
        at org.apache.ignite.internal.processors.cache.GridCacheMapEntry$AtomicCacheUpdateClosure.call(GridCacheMapEntry.java:4367)
        at org.apache.ignite.internal.processors.cache.persistence.tree.BPlusTree$Invoke.invokeClosure(BPlusTree.java:3051)
        at org.apache.ignite.internal.processors.cache.persistence.tree.BPlusTree$Invoke.access$6200(BPlusTree.java:2945)
        at org.apache.ignite.internal.processors.cache.persistence.tree.BPlusTree.invokeDown(BPlusTree.java:1717)
        at org.apache.ignite.internal.processors.cache.persistence.tree.BPlusTree.invoke(BPlusTree.java:1600)
        at org.apache.ignite.internal.processors.cache.IgniteCacheOffheapManagerImpl$CacheDataStoreImpl.invoke(IgniteCacheOffheapManagerImpl.java:1199)
        at org.apache.ignite.internal.processors.cache.IgniteCacheOffheapManagerImpl.invoke(IgniteCacheOffheapManagerImpl.java:345)
        at org.apache.ignite.internal.processors.cache.GridCacheMapEntry.innerUpdate(GridCacheMapEntry.java:1767)
        at org.apache.ignite.internal.processors.cache.distributed.dht.atomic.GridDhtAtomicCache.updateSingle(GridDhtAtomicCache.java:2420)
        at org.apache.ignite.internal.processors.cache.distributed.dht.atomic.GridDhtAtomicCache.update(GridDhtAtomicCache.java:1883)
        at org.apache.ignite.internal.processors.cache.distributed.dht.atomic.GridDhtAtomicCache.updateAllAsyncInternal0(GridDhtAtomicCache.java:1736)
        at org.apache.ignite.internal.processors.cache.distributed.dht.atomic.GridDhtAtomicCache.updateAllAsyncInternal(GridDhtAtomicCache.java:1628)
        at org.apache.ignite.internal.processors.cache.distributed.dht.atomic.GridNearAtomicAbstractUpdateFuture.sendSingleRequest(GridNearAtomicAbstractUpdateFuture.java:299)
        at org.apache.ignite.internal.processors.cache.distributed.dht.atomic.GridNearAtomicSingleUpdateFuture.map(GridNearAtomicSingleUpdateFuture.java:483)
        at org.apache.ignite.internal.processors.cache.distributed.dht.atomic.GridNearAtomicSingleUpdateFuture.mapOnTopology(GridNearAtomicSingleUpdateFuture.java:443)
        at org.apache.ignite.internal.processors.cache.distributed.dht.atomic.GridNearAtomicAbstractUpdateFuture.map(GridNearAtomicAbstractUpdateFuture.java:248)
        at org.apache.ignite.internal.processors.cache.distributed.dht.atomic.GridDhtAtomicCache.update0(GridDhtAtomicCache.java:1117)
        at org.apache.ignite.internal.processors.cache.distributed.dht.atomic.GridDhtAtomicCache.invoke0(GridDhtAtomicCache.java:826)
        at org.apache.ignite.internal.processors.cache.distributed.dht.atomic.GridDhtAtomicCache.invoke(GridDhtAtomicCache.java:784)
        at org.apache.ignite.internal.processors.cache.IgniteCacheProxyImpl.invoke(IgniteCacheProxyImpl.java:1359)
        ... 12 more

I check the document:
https://www.gridgain.com/sdk/pe/latest/javadoc/org/apache/ignite/binary/BinaryObjectBuilder.html#getField-java.lang.String-

"Collections and maps returned from this method are modifiable."

Does anyone know how I can update a Set field via the binary object?

Thanks,
Cong




RE: UnsupportedOperationException when updating a field in binary object

Posted by Cong Guo <co...@huawei.com>.
Thank you for the reply. You are right. The function used to initially get the set returns an unmodifiableSet. That is the reason for the error.
However, when we use a Map as a field and initially write an unmodifiableMap, we can still modify the Map using getField. 

The code is like how we use the Set: 

BinaryObjectBuilder boBuilder = bo.toBuilder();
Map<String, String> meta = boBuilder.getField(meta_FieldStr);
meta.put(key, value);
boBuilder.setField(meta_FieldStr, meta, Map.class);

What is the difference between Map and Set here?

Thanks,
Cong

-----Original Message-----
From: vkulichenko [mailto:valentin.kulichenko@gmail.com] 
Sent: 2018年7月23日 17:16
To: user@ignite.apache.org
Subject: Re: UnsupportedOperationException when updating a field in binary object

This test stops working though if you replace line 30 with this:

builder.setField("set", Collections.unmodifiableSet(Sets.newHashSet("a",
"b", "c")));

If unmodifiable set is written, it's then read as unmodifiable set as well, and therefore can't be modified. I believe this is the reason for the error.

-Val



--
Sent from: http://apache-ignite-users.70518.x6.nabble.com/

Re: UnsupportedOperationException when updating a field in binary object

Posted by vkulichenko <va...@gmail.com>.
This test stops working though if you replace line 30 with this:

builder.setField("set", Collections.unmodifiableSet(Sets.newHashSet("a",
"b", "c")));

If unmodifiable set is written, it's then read as unmodifiable set as well,
and therefore can't be modified. I believe this is the reason for the error.

-Val



--
Sent from: http://apache-ignite-users.70518.x6.nabble.com/

Re: UnsupportedOperationException when updating a field in binary object

Posted by akurbanov <an...@gmail.com>.
You should update a Set field exactly the way you do it now. Could you please
share full reproducer, as the attached code works perfectly. 
BinaryObjectSetUpdate.java
<http://apache-ignite-users.70518.x6.nabble.com/file/t1734/BinaryObjectSetUpdate.java>   



--
Sent from: http://apache-ignite-users.70518.x6.nabble.com/