Uploaded image for project: 'SonarJava'
  1. SonarJava
  2. SONARJAVA-4093

S3252 should not raise issues on access to static members that are declared in inaccessible classes

    XMLWordPrintable

    Details

    • Type: False-Positive
    • Status: Open
    • Priority: Major
    • Resolution: Unresolved
    • Affects Version/s: None
    • Fix Version/s: None
    • Component/s: Rules
    • Labels:
      None

      Description

      S3252 correctly identifies that a constant declared in a parent class is referred to through their child class. However, the fix suggested is to change B.CONSTANT to A.CONSTANT which prevents the code from compiling.

      S3252 should not raise an issue when the reference to the constant refers to an inaccessible class.

      package org.example.domain;
      
      class A {
        public static final int CONSTANT = 42;
        public static int square(int factor)  { 
          return factor * factor;
        }
      }
      
      package org.example.domain;
      
      public class B  extends A {
      }
      
      package com.example.business;
      
      import org.example.domain.B;
      
      class Other {
        private static final Logger logger = Logger.getLogger("...");
      
        public void method() {
          logger.fine("Value is {}", B.CONSTANT); // Compliant
          logger.fine("Square of {} is {}", 11, B.square(11)); // Compliant
        }
      }
      

        Attachments

          Activity

            People

            Assignee:
            Unassigned Unassigned
            Reporter:
            dorian.burihabwa Dorian Burihabwa
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Dates

              Created:
              Updated: