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] UnusedPrivateMethod: could not handle javax.annotation · Issue #6627 · pmd/pmd

[java] UnusedPrivateMethod: could not handle javax.annotation #6627

New issue
Copy link
New issue
Copy link
Closed
#6821
Closed
[java] UnusedPrivateMethod: could not handle javax.annotation#6627
#6821
Copy link
Labels
a:false-positivePMD flags a piece of code that is not problematic
Milestone
7.26.0

Description

@Emilyaxe
Emilyaxe
opened on Apr 27, 2026
Issue body actions

Affects PMD Version: 7.23.0

Rule: UnusedPrivateMethod — https://docs.pmd-code.org/latest/pmd_rules_java_bestpractices.html#unusedprivatemethod

Description:

UnusedPrivateMethod incorrectly flags private methods annotated with @javax.annotation.PostConstruct and @javax.annotation.PreDestroy as unused. These methods are invoked reflectively by the container (e.g., CDI / Spring) during the application lifecycle and should therefore not be considered unused.

Code Sample demonstrating the issue:

// (false-positive)
package demo.before;

import javax.annotation.PostConstruct;
import javax.annotation.PreDestroy;

public class LifecycleBean {
    private String message = "initialized";

    @PostConstruct
    private void setup() {              // UnusedPrivateMethod reported here
        this.message = "post-construct done";
    }

    @PreDestroy
    private void cleanup() {            // UnusedPrivateMethod reported here
        this.message = "pre-destroy done";
    }

    public String getMessage() { return message; }
}

Expected outcome: Private methods annotated with @javax.annotation.PostConstruct or @javax.annotation.PreDestroy should be treated as used (invoked reflectively by the container), and UnusedPrivateMethod should not report a violation.

Actual outcome: PMD reports UnusedPrivateMethod on methods annotated with @javax.annotation.PostConstruct and @javax.annotation.PreDestroy, resulting in a false positive.

Running PMD through: CLI

Activity

  1. Emilyaxe
    added
    a:false-positivePMD flags a piece of code that is not problematic
    on Apr 27, 2026
  2. UncleOwen commented on Apr 27, 2026

    @UncleOwen
    UncleOwen
    on Apr 27, 2026
    Member
    More actions

    Have you tried setting the ignoredAnnotations property?

  3. Emilyaxe commented on Apr 28, 2026

    @Emilyaxe
    Emilyaxe
    on Apr 28, 2026
    Author
    More actions

    Have you tried setting the ignoredAnnotations property?

    Thank you, I will carefully study the rule configuration.

  4. adangel
    added this to the 7.26.0 milestone on Jun 29, 2026
  5. adangel
    added a commit that references this issue on Jun 29, 2026

    [java] Fix #6627: UnusedPrivateMethod: add javax to ignored annotatio…

    This issue will close once commit 07bab85 is merged into the 'main' branch.
    07bab85
  6. adangel
    closed this as completedin #6821on Jun 29, 2026
  7. UncleOwen
    added a commit that references this issue on Jun 29, 2026

    Fix pmd#6627: Add javax.annotation.PostConstruct/PreDestroy to defaul…

    This issue will close once commit 50157a5 is merged into the 'main' branch.
    50157a5
  8. UncleOwen
    marked [java] UnusedPrivateMethod: false positive on @javax.annotation.PostConstruct / @PreDestroy while the equivalent jakarta.annotation.* annotations are correctly ignored #7221 as a duplicate of this issue on Oct 24, 2026
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

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

    Type

    No type

    Projects

    No projects

      Milestone

      • 7.26.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.