-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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
Fix $Gson$Types equals method for TypeVariable when its generic declaration is not a Class #2599
Conversation
Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA). View this failed invocation of the CLA check for more information. For the most up to date status, view the checks section at the bottom of the pull request. |
Thanks for this pull request, and for fixing this bug! Could you please add a unit test similar to what you have shown in your example code (probably either to Also, out of curiosity, how did you notice this bug? Creating |
I should be able to add the tests you request in a few days :) To answer your question, I am implementing JSON objects representing method signature with the type information of a potentially declaring generic class. class SimpleClass {
public void method1(String str) {...}
} Will give : {
"name" : "method1",
"parameters" : [
{
"name" : "str",
"type" : "java.lang.String"
}
]
} class GenericClass<T> {
public void method2(T value) {...}
}
{
"name" : "method2",
"parameters" : [
{
"name" : "value",
"type" : "java.lang.Number"
}
]
} class OtherClass {
public <T> void method3(T param) {...}
} Will give : {
"name" : "method3",
"parameters" : [
{
"name" : "param",
"type" : { "name" : "T", "declaring" : "package.OtherClass#method3..." }
}
]
} And with POJO of this JSON objects, I am led to check equality between them. |
Thanks for the explanation. I guess Gson's Nonetheless, the bug here with the Gson |
…ration is not a Class
…laration is not a Class
Test added :) |
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.
Thanks a lot! The changes look good to me.
It might take some time though until this is merged because I think the direct members of this project are quite busy currently.
Could you please address the build failures though? It probably suffices to place |
…ration is not a Class (google#2599) * Fix $Gson$Types equals method for TypeVariable when its generic declaration is not a Class * Test $Gson$Types equals method with TypeVariable when its generic declaration is not a Class * Add @SuppressWarnings in GsonTypesTest.java
Purpose
When $Gson$Types equals method check two
TypeVariable
, it can return false whileObjects#equals(Object, Object)
returns true.Description
The root cause is here.
For
Class
generic declaration, reference equality is enough because there is one reference of each class.But for
Method
generic declaration, it is not,Class#getMethod(String, Class<?>...)
returns a new instance of theMethod
per call.Checklist
This is automatically checked by
mvn verify
, but can also be checked on its own usingmvn spotless:check
.Style violations can be fixed using
mvn spotless:apply
; this can be done in a separate commit to verify that it did not cause undesired changes.null
@since $next-version$
(
$next-version$
is a special placeholder which is automatically replaced during release)TestCase
)mvn clean verify javadoc:jar
passes without errors