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

Make DefaultPrettyPrinter.createInstance() to fail for sub-classes #502

Closed
cowtowncoder opened this issue Dec 12, 2018 · 0 comments
Closed
Milestone

Comments

@cowtowncoder
Copy link
Member

Pattern of "blueprint object" (that is, having an instance not used as-is, but that has factory method for creating actual instance) is used by Jackson in couple of places; often for things that implement Instantiatable. But one problem is that unless method is left abstract, sub-classing can be problematic -- if sub-class does not override method, then calls will result in an instance of wrong type being created.

And this is what can easily happen with DefaultPrettyPrinter.

A simple solution is for base class to make explicit that if base implementation is called, then instance can not be a sub-class (that is, it is only legal to call on DefaultPrettyPrinter, but no sub-class). This is not optimal (ideally check would be done compile-time), but better than getting a mysterious failure.

@cowtowncoder cowtowncoder changed the title Implement DefaultPrettyPrinter.createInstance() to fail for sub-classes Make DefaultPrettyPrinter.createInstance() to fail for sub-classes Dec 12, 2018
@cowtowncoder cowtowncoder added this to the 2.10.0 milestone Dec 12, 2018
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