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

Use JsonIOException for unchecked exceptions instead of RuntimeException in ConstructorConstructor #2771

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -270,15 +270,13 @@ private static <T> ObjectConstructor<T> newDefaultConstructor(
// Note: InstantiationException should be impossible because check at start of method made
// sure that class is not abstract
catch (InstantiationException e) {
throw new RuntimeException(
throw new JsonIOException(
"Failed to invoke constructor '"
+ ReflectionHelper.constructorToString(constructor)
+ "' with no args",
e);
} catch (InvocationTargetException e) {
// TODO: don't wrap if cause is unchecked?
// TODO: JsonParseException ?
throw new RuntimeException(
throw new JsonIOException(
"Failed to invoke constructor '"
+ ReflectionHelper.constructorToString(constructor)
+ "' with no args",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -727,10 +727,9 @@ static class ClassWithStaticFinalField {

@Test
public void testThrowingDefaultConstructor() {
// TODO: Adjust this once Gson throws more specific exception type
var e =
assertThrows(
RuntimeException.class, () -> gson.fromJson("{}", ClassWithThrowingConstructor.class));
JsonIOException.class, () -> gson.fromJson("{}", ClassWithThrowingConstructor.class));
assertThat(e)
.hasMessageThat()
.isEqualTo(
Expand Down