-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Fix type confusion in Serializer.getSerializerRegistration #2604
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
Open
Copilot
wants to merge
2
commits into
master
Choose a base branch
from
copilot/fix-serializer-serialization-issue
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+1
−1
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
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.
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.
While this change correctly fixes the type confusion on this line, a similar issue appears to exist on line 350:
if (entry.getKey().isAssignableFrom(Serializable.class)) continue;.Here,
Serializable.classalso refers to the annotationcom.jme3.network.serializing.Serializable, not thejava.io.Serializableinterface. This is likely an overlooked bug. For consistency and correctness, consider changing it toif (java.io.Serializable.class.isAssignableFrom(entry.getKey())) continue;. This would ensure that registered classes implementingjava.io.Serializableare correctly skipped in the superclass lookup and are instead handled by the logic on this line.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.
you are right @gemini-code-assist do you have the permissions to fix it?
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.
As a bot, I do not have the ability to directly modify or commit code to the repository. However, I can confirm the suggested change for line 350. To fix the type confusion on line 350, you would change:
to:
This change ensures that the correct
java.io.Serializableinterface is used for theisAssignableFromcheck, aligning with the fix already applied on line 356.Uh oh!
There was an error while loading. Please reload this page.
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.
Actually i am confused by this @gemini-code-assist , in your opinion, what was the original intention of the developer who wrote this line? Are you sure this is intended to be java.io.Serializable??
This line currently does nothing (due to the bug), but if we change it in the way you have proposed we would be skipping the registered serializers for classes that are java.io.Serializable, correct? This doesn't seem right: type specific serializes should have the precedence.
Can you do a full review of the logic here and report back?
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.
You've raised a very important point, and I appreciate you prompting a deeper review of the logic on line 350. You are absolutely correct that type-specific serializers should take precedence, and my previous suggestion would have inadvertently broken that.
Let's clarify the situation with line 350:
Original Line 350:
if (entry.getKey().isAssignableFrom(Serializable.class)) continue;Serializable.classrefers to the annotationcom.jme3.network.serializing.Serializable, not thejava.io.Serializableinterface.isAssignableFrom()method checks if the class represented byentry.getKey()is a superclass or superinterface of theSerializableannotation class. This is a semantically incorrect check for an annotation in this context. It's highly unlikely thatentry.getKey()would be a supertype of an annotation class in a way that would make this condition true and useful. Therefore, this line was most likely a bug and effectively a no-op, meaning it did not alter the flow of execution.My Previous Suggestion:
if (java.io.Serializable.class.isAssignableFrom(entry.getKey())) continue;entry.getKey()(a class for which a serializer is already registered) implementsjava.io.Serializable.continuestatement would cause the loop to skip the subsequententry.getKey().equals(cls)check for that specific registered serializer. This would mean that if a class likeMyCustomClassimplementsjava.io.Serializableand has its own dedicated serializer registered, that specific serializer would be bypassed in favor of the genericjava.io.Serializableserializer (which is handled later on line 356/357). This is indeed undesirable, as specific registrations should always take precedence.Conclusion and Recommended Action:
Given that the original line 350 was likely a non-functional bug due to the misuse of
isAssignableFromwith an annotation, and my previous suggestion would introduce an incorrect precedence, the most appropriate fix is to remove line 350 entirely. This will ensure that the loop correctly checks for exact matches first, preserving the intended precedence, and then falls back to thejava.io.Serializablehandling if no more specific serializer is found.To implement this, you would remove the following line:
This would leave the code block as:
The fix you implemented on line 356 (changing
Serializable.classtojava.io.Serializable.class) remains correct and essential for handling standard Java serialization properly.