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

bug: Crash in SniperJavaPrettyPrinter.calculate if the printer is set after building the model #3693

Closed
slarse opened this issue Nov 13, 2020 · 2 comments · Fixed by #3694
Closed
Labels

Comments

@slarse
Copy link
Collaborator

slarse commented Nov 13, 2020

Hi,

As the title says, SniperJavaPrettyPrinter.calculate crashes if the printer is set with Environment.setPrettyPrinterCreator after one builds the model. The reason for this is that when building the model, this happens:

if (factory.getEnvironment().createPrettyPrinter() instanceof SniperJavaPrettyPrinter) {
//setup a model change collector
new SourceFragmentCreator().attachTo(factory.getEnvironment());
}

And in the call to calculate, the sniper tries to access that change collector (with getChangeCollector():

new ChangeResolver(getChangeCollector(), compilationUnit)),

I have a use case where I need to collect some information from the model to feed to a printer preprocessor, which one typically sets in the supplier passed to setPrettyPrinterCreator. That's how I encountered this problem. It's easy enough to work around (e.g. by setting a "dummy" sniper printer before building the model), but the crash isn't easy to understand if you don't know too much about Spoon.

Any ideas on a solution? The easy solution would of course be to always attach the change collector, but I don't know what kinds of overhead that would impose on non-sniper use cases.

@slarse
Copy link
Collaborator Author

slarse commented Nov 13, 2020

#3694 has a test case that reproduces the issue

@slarse
Copy link
Collaborator Author

slarse commented Nov 13, 2020

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

Successfully merging a pull request may close this issue.

2 participants