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

bug fix for updating jdk version. #4463

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

forrest20
Copy link

@forrest20 forrest20 commented Nov 18, 2023

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.

@forrest20 forrest20 marked this pull request as ready for review November 18, 2023 11:57
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.

None yet

1 participant