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

Extend the FindOverridableMethodCall detector to handle SER09-J #2895

Merged
merged 10 commits into from Mar 27, 2024

Conversation

isuckatcs
Copy link
Contributor

The readObject() method must not call any overridable methods. Invoking overridable methods from the readObject() method can provide the overriding method with access to the object's state before it is fully initialized. This premature access is possible because, in deserialization, readObject plays the role of object constructor and therefore object initialization is not complete until readObject exits.

Please read the SEI CERT rule SER09-J for details.

The rule is similar to MET06-J. Do not invoke overridable methods in clone()), which is detected by the FindOverridableMethodCall, hence the extension of the existing detector instead of introducing a new one with the same functionality.

@isuckatcs
Copy link
Contributor Author

isuckatcs commented Mar 19, 2024

ping Sorry for this, I wasn't aware that this practice is not prefered on this project. I also contribute to LLVM, where this is a common and recommended practice on PR-s, that received no activity for some time.


public class DirectReadObjectStreamMethods {

private void readObject(final ObjectInputStream stream) throws IOException, ClassNotFoundException {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tried it, the checking of the exceptional methods indirectly does work, there is no FP reported when these methods are called indirectly. Can you please add the testcase for it?

@hazendaz hazendaz self-assigned this Mar 27, 2024
@hazendaz hazendaz added this to the SpotBugs 4.8.4 milestone Mar 27, 2024
@hazendaz hazendaz merged commit 6d43261 into spotbugs:master Mar 27, 2024
15 checks passed
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

4 participants