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

Serializing custom class Object causes "ConfigObject is immutable, you can't call Map.put" error #265

Open
ailesgrise opened this issue Oct 25, 2016 · 8 comments

Comments

@ailesgrise
Copy link

I was using twitter chill to Serialize my custom class object and got the following error stack

com.esotericsoftware.kryo.KryoException: java.lang.UnsupportedOperationException: ConfigObject is immutable, you can't call Map.put
[error] Serialization trace:
[error] object (com.typesafe.config.impl.SimpleConfig)
[error] config (CpdLogic$CpdLogicCore)
com.esotericsoftware.kryo.KryoException: java.lang.UnsupportedOperationException: ConfigObject is immutable, you can't call Map.put
Serialization trace:
object (com.typesafe.config.impl.SimpleConfig)
config (CpdLogic$CpdLogicCore)
    at com.esotericsoftware.kryo.serializers.ObjectField.read(ObjectField.java:144)
    at com.esotericsoftware.kryo.serializers.FieldSerializer.read(FieldSerializer.java:551)
    at com.esotericsoftware.kryo.Kryo.readObject(Kryo.java:708)
    at com.esotericsoftware.kryo.serializers.ObjectField.read(ObjectField.java:125)
    at com.esotericsoftware.kryo.serializers.FieldSerializer.read(FieldSerializer.java:551)
    at com.esotericsoftware.kryo.Kryo.readClassAndObject(Kryo.java:790)
    at EnhancedCod$$anonfun$6.apply(EnhancedCod.scala:107)
    at EnhancedCod$$anonfun$6.apply(EnhancedCod.scala:98)
    at scala.collection.LinearSeqOptimized$class.foldLeft(LinearSeqOptimized.scala:111)
    at scala.collection.immutable.List.foldLeft(List.scala:84)
    at EnhancedCod$.main(EnhancedCod.scala:97)
    at EnhancedCod.main(EnhancedCod.scala)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
Caused by: java.lang.UnsupportedOperationException: ConfigObject is immutable, you can't call Map.put
    at com.typesafe.config.impl.AbstractConfigObject.weAreImmutable(AbstractConfigObject.java:193)
    at com.typesafe.config.impl.AbstractConfigObject.put(AbstractConfigObject.java:204)
    at com.typesafe.config.impl.AbstractConfigObject.put(AbstractConfigObject.java:20)
    at com.esotericsoftware.kryo.serializers.MapSerializer.read(MapSerializer.java:162)
    at com.esotericsoftware.kryo.serializers.MapSerializer.read(MapSerializer.java:39)
    at com.esotericsoftware.kryo.Kryo.readClassAndObject(Kryo.java:790)
    at com.esotericsoftware.kryo.serializers.MapSerializer.read(MapSerializer.java:161)
    at com.esotericsoftware.kryo.serializers.MapSerializer.read(MapSerializer.java:39)
    at com.esotericsoftware.kryo.Kryo.readClassAndObject(Kryo.java:790)
    at com.esotericsoftware.kryo.serializers.MapSerializer.read(MapSerializer.java:161)
    at com.esotericsoftware.kryo.serializers.MapSerializer.read(MapSerializer.java:39)
    at com.esotericsoftware.kryo.Kryo.readClassAndObject(Kryo.java:790)
    at com.esotericsoftware.kryo.serializers.MapSerializer.read(MapSerializer.java:161)
    at com.esotericsoftware.kryo.serializers.MapSerializer.read(MapSerializer.java:39)
    at com.esotericsoftware.kryo.Kryo.readObject(Kryo.java:708)
    at com.esotericsoftware.kryo.serializers.ObjectField.read(ObjectField.java:125)
    at com.esotericsoftware.kryo.serializers.FieldSerializer.read(FieldSerializer.java:551)
    at com.esotericsoftware.kryo.Kryo.readObject(Kryo.java:708)
    at com.esotericsoftware.kryo.serializers.ObjectField.read(ObjectField.java:125)
    at com.esotericsoftware.kryo.serializers.FieldSerializer.read(FieldSerializer.java:551)
    at com.esotericsoftware.kryo.Kryo.readClassAndObject(Kryo.java:790)
    at EnhancedCod$$anonfun$6.apply(EnhancedCod.scala:107)
    at EnhancedCod$$anonfun$6.apply(EnhancedCod.scala:98)
    at scala.collection.LinearSeqOptimized$class.foldLeft(LinearSeqOptimized.scala:111)
    at scala.collection.immutable.List.foldLeft(List.scala:84)
    at EnhancedCod$.main(EnhancedCod.scala:97)
    at EnhancedCod.main(EnhancedCod.scala)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)

My class object does take a typesafe ConfigObject as an input for construction and the configObject is immutable.

I have no problem writing the object but when I read it again, I get the aforementioned error.

I am using Scala 2.10.5 using com.twitter chill version 0.8.0.

@ailesgrise ailesgrise changed the title ConfigObject immutable causes "ConfigObject is immutable, you can't call Map.put" error Serializing custom class Object causes "ConfigObject is immutable, you can't call Map.put" error Oct 25, 2016
@magro
Copy link

magro commented Oct 25, 2016

Cross post: EsotericSoftware/kryo#472 ;-)

@johnynek
Copy link
Collaborator

johnynek commented Jan 3, 2017

did you try chill 0.8.1:

https://github.com/twitter/chill/releases/tag/v0.8.1

it has support for immutable java maps.

@ailesgrise
Copy link
Author

Chill 0.9.2 still doesn't seem to work. I still get the same error message.

@johnynek
Copy link
Collaborator

I guess the solution is to implement a serializer for Config and register that.

@ailesgrise
Copy link
Author

Right, I'll give that a try thank you.

@agnaldo4j
Copy link

agnaldo4j commented Apr 4, 2018

Hi @ailesgrise and @johnynek
Today I tried upgrading to Akka 2.5.11 and got the same error.

com.esotericsoftware.kryo.KryoException: java.lang.UnsupportedOperationException: ConfigObject is immutable, you can't call Map.put
Serialization trace:
object (com.typesafe.config.impl.SimpleConfig)
configOfJoiningNode (akka.cluster.InternalClusterAction$InitJoin)
	at com.esotericsoftware.kryo.serializers.ObjectField.read(ObjectField.java:144)

@ailesgrise, Have you implemented the Serializer? Doing it solved the problem?

@johnynek Do you think to implement this serializer in the project by default?

@johnynek
Copy link
Collaborator

johnynek commented Apr 4, 2018

I would be happy to accept a PR but I don’t use Akka, nor does Twitter, so I don’t think any of the usual contributors will get to it soon.

I would welcome a PR from you thought! :)

@agnaldo4j
Copy link

Hi @johnynek I found the problem, we configure Akka cluster messages to be serialized by kryo but the correct config is to use the default Akka serialization for it.

thanks

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

4 participants