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

correct StackOverflowEerror from rendering java.nio.Path #319

Open
Groostav opened this issue May 15, 2024 · 1 comment
Open

correct StackOverflowEerror from rendering java.nio.Path #319

Groostav opened this issue May 15, 2024 · 1 comment

Comments

@Groostav
Copy link

Groostav commented May 15, 2024

the java.nio.Path interface is recursively iterable on Path. This causes a stack-overflow in ST4's representation as it is never able to find an element that isnt iterable, so it calls convertAnythingIteratableToIterator all-the-way-down.

java.nio.Path implements Iterable<java.nio.Path>,

eg:

var path = Paths.get("some/path");
Path first = path.iterator().next(); //== "some"
Path firstFirst = first.iterator().next(); //== "some"
Path firstFirstFirst = firstFirst.iterator().next(); //== "some"

and so on.

This really does not play nicely with convertAnythingIteratableToIterator: This behavior means, even if you supply a converter for java.nio.path, ST4 never identifies it as a POJO and so never asks for a renderer.


suggestions:

  • could rewrite the convertAnything to keep a stack of elements that it checks against, if it finds that asking for iterable conversions ever produces the same value => we're probably in an infinite loop => take some action
  • could try to restructure to ask if a representation exists for the object before trying to iterate over it.
  • a simple-ish fix would be to look for instances of Collection rather than Iterable; given that Iterable is used in some infinite sequences, this would likely help there too.

I'm swamped, but I need this so I could create a PR if needed. In the mean time I'm going to twiddle my thumbs for a while.

@Groostav
Copy link
Author

the more I think about it, what is the rationale for converting to iterable before checking if the user provided an explicit converter?

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

1 participant