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] UnusedPrivateField: Do not flag fields annotated with @Version · Issue #3824 · pmd/pmd

[java] UnusedPrivateField: Do not flag fields annotated with @Version #3824

New issue
Copy link
New issue
Copy link
Closed
#4003
Closed
[java] UnusedPrivateField: Do not flag fields annotated with @Version#3824
#4003
Copy link
Labels
a:false-positivePMD flags a piece of code that is not problematic
Milestone
6.47.0

Description

@numeralnathan
numeralnathan
opened on Mar 5, 2022
Issue body actions

Affects PMD Version: 6.43.0

Rule: UnusedPrivateField

Description:

Optimistic locking for JPA requires a field annotated with @javax.persistence.Version. These fields rarely have a getter or setter. Please fix UnusedPrivateField to ignore fields annotated with @javax.persistence.Version.

Code Sample demonstrating the issue:

@Entity
@Table(name = "my_table")
public class MyTable implements Serializable
{
   private static final long serialVersionUID = 1L;

   @Id
   @Column(name = "id", nullable = false)
   private long m_id;

   // other fields

   @Version
   @Column(name = "optimistic_lock", nullable = false)
   private short m_optimisticLock;    // PMD Violation: UnusedPrivateField

   /*
    * For JPA
    */
   public MyTable()
   {
      // nothing to do
   }

   public long getId()
   {
      return m_id;
   }

   // getters and setters for other fields except m_optimisticLock
}

Expected outcome:

PMD reports a violation at line private short m_optimisticLock; // PMD Violation: UnusedPrivateField, but that's wrong. That's a false positive.

Running PMD through: Eclipse PMD Plugin

Activity

  1. numeralnathan
    added
    a:false-positivePMD flags a piece of code that is not problematic
    on Mar 5, 2022
  2. pzygielo commented on Mar 5, 2022

    @pzygielo
    pzygielo
    on Mar 5, 2022
    Contributor
    More actions
    • [java] UnusedPrivateField: Do not flag fields annotated with @Id or @EmbeddedId #3825 (comment)
  3. adangel
    added this to the 6.47.0 milestone on Jun 24, 2022
  4. adangel
    closed this as completedin #4003on Jun 24, 2022
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

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