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

UnmodifiableCollectionsSerializer fails to copy values of unmodifiable map #81

Open
johnou opened this issue Nov 30, 2017 · 1 comment

Comments

@johnou
Copy link

johnou commented Nov 30, 2017

I recently found that UnmodifiableCollectionsSerializer fails to copy values of unmodifiable map, as a workaround I am taking a copy of the values before, well, cloning.. 😱

    public static void main(String[] args) {
        Map<Integer, Integer> map = Collections.unmodifiableMap(new HashMap<Integer, Integer>() {{
            put(1, 1);
        }});
        KryoPool kryoPool = new KryoPool.Builder(() -> {
            Kryo kryo = new Kryo();
            kryo.setInstantiatorStrategy(new Kryo.DefaultInstantiatorStrategy(new StdInstantiatorStrategy()));
            UnmodifiableCollectionsSerializer.registerSerializers(kryo);
            return kryo;
        }).softReferences().build();
        kryoPool.run(kryo -> kryo.copy(map.values()));
    }

Fails with..

Exception in thread "main" java.lang.UnsupportedOperationException
	at java.util.AbstractCollection.add(AbstractCollection.java:262)
	at com.esotericsoftware.kryo.serializers.CollectionSerializer.copy(CollectionSerializer.java:149)
	at com.esotericsoftware.kryo.serializers.CollectionSerializer.copy(CollectionSerializer.java:40)
	at com.esotericsoftware.kryo.Kryo.copy(Kryo.java:914)
	at de.javakaffee.kryoserializers.UnmodifiableCollectionsSerializer.copy(UnmodifiableCollectionsSerializer.java:95)
	at com.esotericsoftware.kryo.Kryo.copy(Kryo.java:914)
@magro
Copy link
Owner

magro commented Jan 27, 2018

Thanks for reporting, do you want to submit a pull request?

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