From d5c646f93e57572ad9f94c52bbe33ce1145e7ecd Mon Sep 17 00:00:00 2001 From: Jake Wharton Date: Mon, 6 Jun 2016 01:44:47 -0400 Subject: [PATCH] Propagate adapter method exception cause. --- .../java/com/squareup/moshi/AdapterMethodsFactory.java | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/moshi/src/main/java/com/squareup/moshi/AdapterMethodsFactory.java b/moshi/src/main/java/com/squareup/moshi/AdapterMethodsFactory.java index c3cf28a..cb51422 100644 --- a/moshi/src/main/java/com/squareup/moshi/AdapterMethodsFactory.java +++ b/moshi/src/main/java/com/squareup/moshi/AdapterMethodsFactory.java @@ -64,8 +64,9 @@ final class AdapterMethodsFactory implements JsonAdapter.Factory { } catch (IllegalAccessException e) { throw new AssertionError(); } catch (InvocationTargetException e) { - if (e.getCause() instanceof IOException) throw (IOException) e.getCause(); - throw new JsonDataException(e.getCause() + " at " + writer.getPath()); + Throwable cause = e.getCause(); + if (cause instanceof IOException) throw (IOException) cause; + throw new JsonDataException(cause + " at " + writer.getPath(), cause); } } } @@ -82,8 +83,9 @@ final class AdapterMethodsFactory implements JsonAdapter.Factory { } catch (IllegalAccessException e) { throw new AssertionError(); } catch (InvocationTargetException e) { - if (e.getCause() instanceof IOException) throw (IOException) e.getCause(); - throw new JsonDataException(e.getCause() + " at " + reader.getPath()); + Throwable cause = e.getCause(); + if (cause instanceof IOException) throw (IOException) cause; + throw new JsonDataException(cause + " at " + reader.getPath(), cause); } } }