Skip to content

Commit

Permalink
Use JsonIOException for unchecked exceptions instead of RuntimeExcept…
Browse files Browse the repository at this point in the history
…ion in ConstructorConstructor
  • Loading branch information
panic08 committed Oct 30, 2024
1 parent 44c9336 commit e4471d0
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 6 deletions.
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

0 comments on commit e4471d0

Please sign in to comment.