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

@hierynomus
Copy link
Contributor

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
Copy link
Contributor Author

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
Copy link
Contributor Author

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

@hierynomus
Copy link
Contributor Author

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

1 participant