Skip to content

Make stack operations use AutoCloseable for safer usage with try-with-resources #1250

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

Open
wants to merge 5 commits into
base: master
Choose a base branch
from

Conversation

jasmith-hs
Copy link
Contributor

Replaced the error-prone CallStack and Stack pop/push pattern with AutoCloseable so that pushing can be done using try-with-resources.

Added method dangerouslyGetWithoutClosing() to allow backward-compatibility with existing public methods.

Migrated all of the prod code, and the test code using CallStack pushing. Many tests using JinjavaInterpreter.pushCurrent() still need/can be migrated.

Using algebra Result for correct/explicit error handling.

New methods like AutoCloseableSupplier<Result<String, TagCycleException>> closeablePush(...), and deprecated the old methods that don't return an AutoCloseableSupplier<T>.

The way that I designed AutoCloseableSupplier and AutoCloseableImpl makes it so that you can use .map to transform what the autocloseable is, and a custom consumer is supplied that tells how to "close" the thing. And in cases where no closing needs to occur (such as error cases where nothing is pushed to a stack), there's AutoCloseableSupplier.of(value)

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

Successfully merging this pull request may close these issues.

1 participant