-
Notifications
You must be signed in to change notification settings - Fork 579
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
ProtoAdapter and FieldBinding should use rawType's classloader. #2388
Conversation
b7cd295
to
04afa9f
Compare
wire-runtime/src/jvmMain/kotlin/com/squareup/wire/ProtoAdapter.kt
Outdated
Show resolved
Hide resolved
wire-runtime/src/jvmMain/kotlin/com/squareup/wire/internal/reflection.kt
Outdated
Show resolved
Hide resolved
wire-runtime/src/jvmMain/kotlin/com/squareup/wire/internal/reflection.kt
Outdated
Show resolved
Hide resolved
wire-gson-support/src/main/java/com/squareup/wire/WireTypeAdapterFactory.kt
Outdated
Show resolved
Hide resolved
wire-moshi-adapter/src/main/java/com/squareup/wire/WireJsonAdapterFactory.kt
Outdated
Show resolved
Hide resolved
With a test failure like the following, is it literally saying that it doesn't like that I made the declaration take multiple lines?
|
wire-gson-support/src/main/java/com/squareup/wire/WireTypeAdapterFactory.kt
Outdated
Show resolved
Hide resolved
wire-runtime/src/jvmMain/kotlin/com/squareup/wire/ProtoAdapter.kt
Outdated
Show resolved
Hide resolved
wire-runtime/src/jvmMain/kotlin/com/squareup/wire/internal/FieldBinding.kt
Outdated
Show resolved
Hide resolved
@autonomousapps for the build fail, it says "Test files changed. Did you run |
a-ha, I did not! Thanks for the tip. |
Fixed the tests ( |
e8d1296
to
1e21c9c
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's go
It is arguably a bug that
ProtoAdapter
implicitly uses the classLoader from itself when callingClass.forName(String)
. Instead, we should useClass.forName(String, boolean, ClassLoader)
, and theClassLoader
argument should be supplied byrawType
.Original description
This draft PR is intended first for discussion purposes, and to get feedback on what it would take to land something like this on trunk. We need this in our project because the
wire-runtime
library is loaded in a different classloader than the main app classes, leading to serialization errors when wire tries to instantiate a class instance viaClass.forName(String)
. Arguably, best practice in cases like this indicates that an overload ought to be provided such that a library can useClass.forName(String, boolean, ClassLoader)
, because in general libraries cannot guarantee they'll be loaded in the same classloaders as application classes.