SonarQube Java
  1. SonarQube Java
  2. SONARJAVA-117

Rule "Unused private method" should not log violation on method having the @PostConstruct and @PreDestroy annotations

    Details

    • Type: Improvement Improvement
    • Status: Open Open
    • Priority: Major Major
    • Resolution: Unresolved
    • Affects Version/s: None
    • Fix Version/s: 2.7
    • Component/s: Exclusions, Rules
    • Labels:
      None
    • Number of attachments :
      0

      Description

      The @PostConstruct and @PreDestroy annotations should be taken into account when checking for unused private methods.

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

        Issue Links

          Activity

          Hide
          Freddy Mallet added a comment -

          The rule specification must be updated to support a new exception

          Show
          Freddy Mallet added a comment - The rule specification must be updated to support a new exception
          Hide
          Freddy Mallet added a comment -

          According to Jürgen Zimmermann:

          The rule "Unused private method" should not be applied for Java methods satisfying these annotations ahead of the method?s signature:

          • @Produces is a CDI annotation (javax.enterprise.inject.Produces) so that the return value can be ?@Inject? ed in other classes
          • @PostConstruct" is an annotation of Common Annotations for additional settings that cannot be done in the constructor because dependency injection didn?t occur so far
          • @PostLoad (javax.persistence.PostLoad) is a JPA annotation for additional tweaking after loading data from a relational database
          • @PrePersist (javax.persistence.PrePersist) is a JPA annotation for additional tweaking before storing data in a relational database
          • @PostPersist (javax.persistence.PostPersist) is a JPA annotation for additional tweaking after storing data in a relational database
          • @PreUpdate (javax.persistence.PreUpdate) is a JPA annotation for additional tweaking before updating data in a relational database
          • @PostUpdate (javax.persistence.PostUpdate) is a JPA annotation for additional tweaking after updating data in a relational database
          • @PreRemove (javax.persistence.PreRemove) is a JPA annotation for additional tweaking before removing data from a relational database
          • @PostRemove (javax.persistence.PostRemove) is a JPA annotation for additional tweaking after removing data from a relational database
          • @Remove (javax.ejb.Remove) is an EJB annotation for additional clean up before a stateful Enterprise JavaBean (EJB) is removed

          Additionally the rule "Unused private method" should not be applied when the method as an argument annotated with @Observes (javax.enterprise.event.Observes) which is a CDI annotation to define an observer for a dedicated event.

          It would be fine if you could make these extensions for a better support of Java EE 7 applications. Thank you in advance.

          Show
          Freddy Mallet added a comment - According to Jürgen Zimmermann: The rule "Unused private method" should not be applied for Java methods satisfying these annotations ahead of the method?s signature: @Produces is a CDI annotation (javax.enterprise.inject.Produces) so that the return value can be ?@Inject? ed in other classes @PostConstruct" is an annotation of Common Annotations for additional settings that cannot be done in the constructor because dependency injection didn?t occur so far @PostLoad (javax.persistence.PostLoad) is a JPA annotation for additional tweaking after loading data from a relational database @PrePersist (javax.persistence.PrePersist) is a JPA annotation for additional tweaking before storing data in a relational database @PostPersist (javax.persistence.PostPersist) is a JPA annotation for additional tweaking after storing data in a relational database @PreUpdate (javax.persistence.PreUpdate) is a JPA annotation for additional tweaking before updating data in a relational database @PostUpdate (javax.persistence.PostUpdate) is a JPA annotation for additional tweaking after updating data in a relational database @PreRemove (javax.persistence.PreRemove) is a JPA annotation for additional tweaking before removing data from a relational database @PostRemove (javax.persistence.PostRemove) is a JPA annotation for additional tweaking after removing data from a relational database @Remove (javax.ejb.Remove) is an EJB annotation for additional clean up before a stateful Enterprise JavaBean (EJB) is removed Additionally the rule "Unused private method" should not be applied when the method as an argument annotated with @Observes (javax.enterprise.event.Observes) which is a CDI annotation to define an observer for a dedicated event. It would be fine if you could make these extensions for a better support of Java EE 7 applications. Thank you in advance.

            People

            • Assignee:
              Freddy Mallet
              Reporter:
              François Dumont
            • Votes:
              2 Vote for this issue
              Watchers:
              4 Start watching this issue

              Dates

              • Created:
                Updated: