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

Stackoverflow error due to parentScope of Generics being pushed as the same object #341

Closed
hierynomus opened this issue Aug 23, 2015 · 3 comments

Comments

1 participant
@hierynomus
Copy link
Contributor

commented Aug 23, 2015

In our product we're currently using Kryo 2.24.0 to serialize a data structure to another node. However in some specific cases during serialization a StackOverflowError occurs. with the following stacktrace:

java.lang.StackOverflowError
    at com.esotericsoftware.kryo.Generics.getConcreteClass(Generics.java:61)
    at com.esotericsoftware.kryo.Generics.getConcreteClass(Generics.java:62)
    at com.esotericsoftware.kryo.Generics.getConcreteClass(Generics.java:62)
    at com.esotericsoftware.kryo.Generics.getConcreteClass(Generics.java:62)
    at com.esotericsoftware.kryo.Generics.getConcreteClass(Generics.java:62)
    at com.esotericsoftware.kryo.Generics.getConcreteClass(Generics.java:62)
    at com.esotericsoftware.kryo.Generics.getConcreteClass(Generics.java:62)
    at com.esotericsoftware.kryo.Generics.getConcreteClass(Generics.java:62)
    at com.esotericsoftware.kryo.Generics.getConcreteClass(Generics.java:62)
[...]

After much debugging we see that in this case kryo.pushGenericsScope(...) is called with exactly the same Generics instance as that is already set. When this happens, the parentScope points to the same instance as the current scope, so you get a loop while resolving.

I've been able to create an isolated testcase in the following Gist: https://gist.github.com/hierynomus/a2f143a555466f83d9bc

This issue is reproducible with Kryo 3.0.3 when using the Gradle buildfile (Gradle 2.6) that is attached to the Gist.

In order to fix this, my initial thought was returning a boolean from pushGenericsScope whether or not it was pushed, and checking before popping that there was actually a push. And then inside the pushGenericsScope checking whether the same instance was being pushed. However this fails the clirr checks.

You could also do the same check before calling the pushGenericsScope / popGenericsScope combo. This will adhere to the clirr checks.

I'd be happy to send a PR, but thought I'd discuss an approach first.

@hierynomus

This comment has been minimized.

Copy link
Contributor Author

commented Aug 24, 2015

Small update (and further pinpointing)...

Running this on MacOSX with Java7 (1.7.0_71) gives a StackOverflowError
However running on Java8 (1.8.0_25) runs successfully.

So the real question is what is different when switching the Java version?

@hierynomus

This comment has been minimized.

Copy link
Contributor Author

commented Aug 24, 2015

No, scratch that... The testcase contained a Set... Changing that to a List gives reproducible results. Gist updated.

@hierynomus

This comment has been minimized.

Copy link
Contributor Author

commented Sep 2, 2015

PR was merged, so I think this issue can be closed.

@hierynomus hierynomus closed this Sep 2, 2015

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.