GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — [java] BeanMembersShouldSerialize is extremely noisy · Issue #1668 · pmd/pmd

[java] BeanMembersShouldSerialize is extremely noisy #1668

New issue
Copy link
New issue
Copy link
Closed
#4196
Closed
[java] BeanMembersShouldSerialize is extremely noisy#1668
#4196
Copy link
Assignees
adangel
Labels
a:false-positivePMD flags a piece of code that is not problematic
Milestone
6.52.0

Description

@Vampire
Vampire
opened on Feb 19, 2019
Issue body actions

Rule doc: BeanMembersShouldSerialize

This is more of a question but could be seen as documentation bug.
How does the BeanMembersShouldSerialize rule classify a class as bean or used by a bean?
I have a class that will never be serialized ever or someone did something horribly wrong.
I see that for some cases it makes sense to mark members as transient even if they do not implement Serializable as other serialization mechanisms like Gson could also take that modifier into account.
But from the description I don't see when this rule applies to a class and when not and why it is applied to my class which is actually used by no other code as it is meant to be used by consumers of my library.

Reacted by Cristian Garcia, Daniel Jipa, Christian Hujer, Philip Moore, Anders, jontierno, Joe Lust, DavidGuillen, Kunal Dabir, jochenberger and 6 more

Activity

Next
  1. jsotuyod commented on Feb 19, 2019

    @jsotuyod
    jsotuyod
    on Feb 19, 2019
    Member
    More actions

    @Vampire the rule has no criteria to determine which classes are intended as a bean and which are not; and defaults to treating all classes as beans.

    After all, a Java Bean is just a standard class where:

    • All properties are private (use getters/setters)
    • Has a public no-argument constructor
    • Implements Serializable

    Any rule to enforce these can't rely on them being followed.

    I agree the rule is probably too noisy… but the only way around I can think of, is requiring the user to configure a property with a set of packages where beans are to be found, and disable the rule as misconfigured if not present… I'm not thrilled by this alternative either, but maybe someone else has a better idea.

    Reacted by Luhao and LeonMarino1
  2. jsotuyod
    added
    a:questionRequest for information that doesn't necessarily entail changes to the code base
    on Feb 19, 2019
  3. Vampire commented on Feb 19, 2019

    @Vampire
    Vampire
    on Feb 19, 2019
    ContributorAuthor
    More actions

    If not, maybe at least the name should change. :-)
    I think I just disable it here.

    Reacted by Martin Meeser
  4. wyldbill commented on Oct 16, 2019

    @wyldbill
    wyldbill
    on Oct 16, 2019
    More actions

    @jsotuyod - This:

    • Implements Serializable

    is where the hassle is. PMD seems to assume that classes are beans when they don't implement/aren't Serializable. BeanMembersShouldSerialize is triggered despite the fact that by (the supplied) definition, a class is not a bean.
    Check it out:

    public class NotSerializable {
        private final int myValue;
        public NotSerializable(final int value) {
            myValue = value;
        }
    }
    

    PMD will raise BeanMembersShouldSerialize on the myValue field, despite the fact that the class is not Serializable. As far as being used by another bean, the failure should be in the composing bean for including a field of non-Serializable type. In this case, the composing bean should declare the offending field transient

    Reacted by Christian Hujer, Mark, Martin Meeser, Kunal Dabir and Jan Holthuis
  5. wyldbill commented on Oct 16, 2019

    @wyldbill
    wyldbill
    on Oct 16, 2019
    More actions

    Seems that I'm not alone here, and that this is a long-standing issue with this rule.

    Reacted by Christian Hujer and Joe Lust
  6. jsotuyod
    removed
    a:questionRequest for information that doesn't necessarily entail changes to the code base
    on Oct 17, 2019
  7. jsotuyod commented on Oct 17, 2019

    @jsotuyod
    jsotuyod
    on Oct 17, 2019
    Member
    More actions

    @wyldbill thanks for your comments.

    Unfortunately, as already explained, looking for serializable classes is not a fix. Not all serializable classes are intended to be Java beans, and the same problem would arise with anyone using standard Java serialization and coming across these reports. We would be just shoving this under the carpet.

    The only true fix I can think for this rule, as already stated is requiring the user to configure a property with a set of packages where beans are to be found, and disable the rule as misconfigured if not present.

    Moreover, given the rule name, I would say the rule is actually incomplete, and if something is intended to be a bean, it should check for both, the existence of the no-arg constructor and the implementation of Serializable (none of which are currently performed). This way, when I say "my beans are under this package" the rule can enforce those are actually proper Java beans without assuming I did right any particular requirement.

    Help implementing this is always welcomed.

  8. jsotuyod
    added
    a:false-positivePMD flags a piece of code that is not problematic
    good first issueA great starting point for new contributors
    on Oct 17, 2019
  9. jsotuyod
    changed the title [-][java] BeanMembersShouldSerialize documentation[/-] [+][java] BeanMembersShouldSerialize is extremely noisy[/+] on Oct 17, 2019
  10. CristianGM commented on Oct 23, 2019

    @CristianGM
    CristianGM
    on Oct 23, 2019
    More actions

    This rule is forcing me to stop using ErrorProne ruleset on all the company projects.
    Every single warning I have it's a false positive, and I have hundreds, I would vote to at least remove it from ErrorProne as that's the Gradle plugin default ( I guess it's useful for someone so I don't say removing it )

    Reacted by Christian Hujer, Emac and Martin Meeser
  11. adangel commented on Oct 26, 2019

    @adangel
    adangel
    on Oct 26, 2019
    Member
    More actions

    @CristianGM It seems, that you don't use a custom ruleset.
    Please refer to https://pmd.github.io/latest/pmd_userdocs_making_rulesets.html to customize, which rules you want to have executed and are useful for your project.
    We definitely won't remove the rule from the error prone category, but I'd rather recommend, that you override the default gradle configuration to use your custom ruleset.
    Note: Since gradle provides two ways for configuring rulesets, you need probably to remove the defaults via ruleSets = [] and configure your custom ruleset via ruleSetFiles = files("config/pmd/myRuleSet.xml").
    Hope that helps.

    Reacted by Cihat Imamoglu and rkrisztian
  12. CristianGM commented on Oct 26, 2019

    @CristianGM
    CristianGM
    on Oct 26, 2019
    More actions

    I know how to use a custom ruleset but, don't you think that having a rule in the default ruleset that is known to give false positives is not the right thing to do?
    IMHO for a rule to be a default it should be proven to be useful and correct.

    Reacted by Christian Hujer, DavidGuillen, Martin Meeser and Ting-Lan Wang
  13. jsotuyod commented on Oct 27, 2019

    @jsotuyod
    jsotuyod
    on Oct 27, 2019
    Member
    More actions

    @CristianGM please notice, PMD has no such thing as a "default ruleset", we only group rules into standard categories. Choosing to use a given category as default configuration is actually up to Gradle.

  14. CristianGM commented on Oct 27, 2019

    @CristianGM
    CristianGM
    on Oct 27, 2019
    More actions

    @jsotuyod true, Gradle defaults to ErrorProne and this rule is definitely ErrorProne, but the rule itself, not just what it checks for.

    Reacted by Christian Hujer, DavidGuillen and Martin Meeser
  15. 9 remaining items

  16. oowekyala commented on Feb 6, 2020

    @oowekyala
    oowekyala
    on Feb 6, 2020
    Member
    More actions

    This is probably because the type of the example classes used in the tests are not on the classpath. We should improve this function to look into the ExtendsList and ImplementsList if the parameter is a type declaration.

    Reacted by Christian Hujer
  17. CristianGM commented on Mar 26, 2020

    @CristianGM
    CristianGM
    on Mar 26, 2020
    More actions

    @christianhujer could you try now that TypeHelper has been improved by @oowekyala ?

  18. marcindabrowski commented on Jul 21, 2022

    @marcindabrowski
    marcindabrowski
    on Jul 21, 2022
    Contributor
    More actions

    It is still very noisy :(.

  19. adangel
    added this to the 6.49.0 milestone on Jul 26, 2022
  20. adangel
    modified the milestones: 6.49.0, 6.50.0 on Aug 30, 2022
  21. adangel
    modified the milestones: 6.50.0, 6.51.0 on Sep 30, 2022
  22. adangel
    modified the milestones: 6.51.0, 6.52.0 on Oct 25, 2022
  23. adangel
    removed
    good first issueA great starting point for new contributors
    on Oct 27, 2022
  24. adangel
    self-assigned this
    on Oct 27, 2022
  25. adangel
    added a commit that references this issue on Nov 4, 2022

    [java] Implement rule NonSerializableClass

    This issue will close once commit 51067c2 is merged into the 'main' branch.
    51067c2
  26. adangel
    closed this as completedin 51067c2on Nov 25, 2022
  27. hhu-stups-mirror
    added a commit that references this issue on May 15, 2024

    Remove exclusion of PMD rule BeanMembersShouldSerialize

    3da107e
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

  • @adangel
    adangel

Labels

a:false-positivePMD flags a piece of code that is not problematic

Type

No type

Projects

No projects

    Milestone

    • 6.52.0

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

    You are visitor 01402775 — GeezerVison does not store the pages you look up.
    Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.