This repository has been archived by the owner on Oct 23, 2024. It is now read-only.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Issue
Recently, I encountered a problem when upgrading jdk for the company's services. After I upgraded the jdk (jdk corretto-11 -> jdk corretto-15) version of projects, deserializing some fields through fastJson became incorrect.
Root cause
I looked at the logic of this piece carefully. I found that when a class has multiple constructors of which the parameters are greater than 0, and there are no annotations in the class to indicate which class constructor to use, just let fastjson choose. FastJson will select the constructor with the largest number of parameters. If there are multiple constructors with the largest number of parameters, it will select the first constructor with the largest number of parameters. The logic here is: code.
The Java method of obtaining class constructors, java.lang.Class#getDeclaredConstructors, returns constructors in a different order in these two JDK versions. This means that if there are multiple constructors with the most parameters, the final constructor obtained here may be different. This ultimately results in the deserialized object being incorrect.
I think the results here should not differ depending on the jdk version.
This commit may lead to some potential break changes, but it can ensure that the results will not be different due to different jdk versions.I also hope to discuss this issue with you.