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

GSON upgrade and illegal reflective fix #54

Merged
merged 4 commits into from
Apr 26, 2021
Merged

GSON upgrade and illegal reflective fix #54

merged 4 commits into from
Apr 26, 2021

Conversation

mmcdaris
Copy link
Member

In this PR we upgrades the GSON dependency to the most current version and mark the Notice's Throwable exception field as transient to avoid GSON serialization. The exception field isn't used in the notice payload sent to Airbrake and we already extract the type, message, and backtrace from it.

This was the error that was reported and seen in our ci specs previous to this fix commit. we no longer see the illegal reflection warning in the latest ci runs of the tests.

WARNING: Illegal reflective access by com.google.gson.internal.reflect.UnsafeReflectionAccessor (file:/home/runner/.gradle/caches/modules-2/files-2.1/com.google.code.gson/gson/2.8.6/9180733b7df8542621dc12e21e87557e8c99b8cb/gson-2.8.6.jar) to field java.lang.Throwable.detailMessage
WARNING: Please consider reporting this to the maintainers of com.google.gson.internal.reflect.UnsafeReflectionAccessor
WARNING: Use --illegal-access=warn to enable warnings of further illegal reflective access operations
WARNING: All illegal access operations will be denied in a future release

Marking the Throwable being serialized as transient will cause gson to ignore this field during serialization https://github.com/google/gson/blob/master/UserGuide.md#java-modifier-exclusion

Based on what I read about transient, it makes sense that GSON ignores the field:

transient is a Java keyword which marks a member variable not to be serialized when it is persisted to streams of bytes. When an object is transferred through the network, the object needs to be 'serialized'.
source: wikibooks - Java Programming

closes #34

This upgrades the gson dependency to the most current version.
The error thrown has changed since GSON now checks for a BEGIN_OBJECT
`{`. Since there is none to be found this more specific syntax exception is
thrown instead of a parse exception.
Without this custom serializer for java.lang.Throwable our calls to
gson.toJson were raising this warning:

```
WARNING: Illegal reflective access by
com.google.gson.internal.reflect.UnsafeReflectionAccessor
(file:/home/runner/.gradle/caches/modules-2/files-2.1/com.google.code.gson/gson/2.8.6/9180733b7df8542621dc12e21e87557e8c99b8cb/gson-2.8.6.jar)
to field java.lang.Throwable.detailMessage
WARNING: Please consider reporting this to the maintainers of
com.google.gson.internal.reflect.UnsafeReflectionAccessor
WARNING: Use --illegal-access=warn to enable warnings of further illegal
reflective access operations
WARNING: All illegal access operations will be denied in a future
release
```

As viewable in the previous commit's specs:
https://github.com/airbrake/javabrake/runs/2405994493#step:4:156
Trying to serialize a java.lang.Throwable will raise a warning about
illegal reflection. Marking the Throwable being serialized as `transient`
will cause gson to ignore this field during serialization, it's not part
of the notice payload anyway.
https://github.com/google/gson/blob/master/UserGuide.md#java-modifier-exclusion

Note on transient keyword:
> `transient` is a Java keyword which marks a member variable not to be
serialized when it is persisted to streams of bytes. When an object is
transferred through the network, the object needs to be 'serialized'.
source: [wikibooks - Java Programming](https://en.wikibooks.org/wiki/Java_Programming/Keywords/transient)
Copy link
Contributor

@kyrylo kyrylo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice work!

@mmcdaris mmcdaris merged commit 7292919 into master Apr 26, 2021
@mmcdaris mmcdaris deleted the gson-upgrade branch April 26, 2021 17:26
@mmcdaris
Copy link
Member Author

Thanks for the review @kyrylo!

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

Successfully merging this pull request may close these issues.

GSON Illegal Reflective Access
2 participants