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

TypeAdapters assertion looses causing throwable #737

Closed
realdadfish opened this issue Nov 16, 2015 · 5 comments
Closed

TypeAdapters assertion looses causing throwable #737

realdadfish opened this issue Nov 16, 2015 · 5 comments

Comments

@realdadfish
Copy link

In line https://github.com/google/gson/blob/master/gson/src/main/java/com/google/gson/internal/bind/TypeAdapters.java#L799
an AssertionError is thrown in case a NoSuchFieldException is triggered. The assertion however looses all context information what field is missing and makes debugging this issue very hard, especially on proguarded builds.

@swankjesse
Copy link
Collaborator

Seems like disabling proguard will always simplify debugging.

@realdadfish
Copy link
Author

Not this time, though. I usually ran my tests on non-obfuscated proguard builds that share the same proguard configuration like my release builds, but this time the obfuscation was actually the issue that somehow made the field "vanish", because the proguarded debug build did not show the issue.

Figured it out that I had a wrong OkHttp proguard configuration after I could hint myself at the missing field by using a custom gson build. Feel free to take this code over:

diff --git a/gson/src/main/java/com/google/gson/internal/bind/TypeAdapters.java b/gson/src/main/java/com/google/gson/internal/bind/TypeAdapters.java
index d284dd5..6bb4a1f 100644
--- a/gson/src/main/java/com/google/gson/internal/bind/TypeAdapters.java
+++ b/gson/src/main/java/com/google/gson/internal/bind/TypeAdapters.java
@@ -796,7 +796,7 @@ public final class TypeAdapters {
           constantToName.put(constant, name);
         }
       } catch (NoSuchFieldException e) {
-        throw new AssertionError();
+        throw new AssertionError("missing field in " + classOfT, e);
       }
     }
     @Override public T read(JsonReader in) throws IOException {

@gupta-sachin
Copy link

The AssertionError constructor with Throwable is added since Java 1.7 so it will be better to have only a detailed error message here.

@Marcono1234
Copy link
Collaborator

Marcono1234 commented Jul 28, 2022

The detailed error message was added by #738 but because the constructor used in these changes does not exist in Java 6, it was later adjusted by #857 to only set the cause.
However, this code was refactored by #1495 to better handle obfuscated enum constant names, so this issue is probably resolved.

@eamonnmcmanus
Copy link
Member

Given how old this issue is and the summary from @Marcono1234 I'm going to close this now. Feel free to reopen or log a new issue if there is still a genuine issue here.

@eamonnmcmanus eamonnmcmanus closed this as not planned Won't fix, can't repro, duplicate, stale Jul 28, 2022
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

5 participants