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

Improve error message when abstract class cannot be constructed #1814


Copy link

@Marcono1234 Marcono1234 commented Nov 5, 2020

Previously Gson tried to invoke the no-arg constructor of abstract classes. This lead to rather unhelpful exception messages, e.g.:

java.lang.RuntimeException: Failed to invoke public test.AbstractClass() with no args

Now Gson will not try to invoke constructors of abstract classes anymore, which generates more helpful exception messages:

java.lang.RuntimeException: Unable to invoke no-args constructor for class test.AbstractClass. Registering an InstanceCreator with Gson for this type may fix this problem.
Caused by: java.lang.UnsupportedOperationException: Abstract class can't be instantiated! Class name: test.AbstractClass

@google-cla google-cla bot added the cla: yes label Nov 5, 2020
@Marcono1234 Marcono1234 force-pushed the marcono1234/abstract-class-constructor branch from d2ec571 to 2bc8b69 Compare Nov 5, 2020
Copy link

eamonnmcmanus commented Feb 4, 2022

Thanks, I actually ran into a user issue with this earlier this week.

@eamonnmcmanus eamonnmcmanus merged commit 47dea2e into google:master Feb 4, 2022
3 checks passed
@Marcono1234 Marcono1234 deleted the marcono1234/abstract-class-constructor branch Feb 4, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
None yet

Successfully merging this pull request may close these issues.

None yet

2 participants