Skip to content

NPE with XMethod in 4.9.6 #3727

Closed
Closed

Description

@mebigfatguy

Exception analyzing com.acme.common.utils.AnvilUtil
using detector edu.umd.cs.findbugs.detect.MultipleInstantiationsOfSingletons
java.lang.NullPointerException: Cannot invoke "edu.umd.cs.findbugs.ba.XMethod.getClassName()" because "xmethod" is null
At edu.umd.cs.findbugs.MethodAnnotation.fromXMethod(MethodAnnotation.java:264)
At edu.umd.cs.findbugs.BugInstance.addMethod(BugInstance.java:1511)
At edu.umd.cs.findbugs.detect.MultipleInstantiationsOfSingletons.visitAfter(MultipleInstantiationsOfSingletons.java:254)
At edu.umd.cs.findbugs.visitclass.PreorderVisitor.visitJavaClass(PreorderVisitor.java:409)

Activity

  1. gtoison commented on Sep 22, 2025

    @gtoison
    Contributor

    This might be the same issue as #3669
    I suppose you cannot share the class triggering the error but is there something unusual about the method signatures in that class?

  2. mebigfatguy commented on Sep 22, 2025

    @mebigfatguy
    ContributorAuthor

    right... Incredibly bog standard class

    Implements cloneable, has a static inner class... But wrt method signatures, doesn't even use generics anywhere.

    Actually now that i look at it, it declares being Cloneable but relies on Object for implementation.

  3. mebigfatguy commented on Sep 23, 2025

    @mebigfatguy
    ContributorAuthor

    Yeah it's coming from here

                if (isCloneable) {
                    if (implementsCloneableDirectly) { // directly
                        bugReporter.reportBug(new BugInstance(this, "SING_SINGLETON_IMPLEMENTS_CLONEABLE", NORMAL_PRIORITY).addClass(this)
                                .addMethod(cloneMethod));
                    }
    
    

    that cloneMethod is null

  4. JuditKnoll commented on Sep 23, 2025

    @JuditKnoll
    Collaborator

    Can you please check, does this also happen with SpotBugs 4.9.3? Are there other NPEs with other detectors as well?
    If it does not happen with the earlier version, there might be something bigger behind the scenes and the null check would not solve the problem, just hide it.

  5. mebigfatguy commented on Sep 23, 2025

    @mebigfatguy
    ContributorAuthor

    Happens in 4.9.3 as well.

  6. added a commit that references this issue on Dec 10, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions