# False positive: "static" base class members should not be accessed via derived types (java:S3252)

**URL:** <https://community.sonarsource.com/t/false-positive-static-base-class-members-should-not-be-accessed-via-derived-types-java-s3252/53762>\
**Category:** Report False-positive / False-negative...\
**Tags:** java\
**Created:** [November 25, 2021, 10:45am UTC](https://community.sonarsource.com/t/false-positive-static-base-class-members-should-not-be-accessed-via-derived-types-java-s3252/53762 "2021-11-25T10:45:12Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Matteo\_A\_Sorrenti](https://dub1.discourse-cdn.com/sonarsource/user_avatar/community.sonarsource.com/matteo_a_sorrenti/32/27735_2.png) [@Matteo\_A\_Sorrenti](https://community.sonarsource.com/u/Matteo_A_Sorrenti)\
**Post date:** [November 25, 2021, 10:45am UTC](https://community.sonarsource.com/t/false-positive-static-base-class-members-should-not-be-accessed-via-derived-types-java-s3252/53762/1 "2021-11-25T10:45:12Z")

</div>

- versions used SonarLint 7.1
- with different package there is different visbility.
- in class Cb `Sonar` says `Use static access with "a.Ca1" for "V1".`
- but if i do it `Java` says `Ca1 cannot be resolved to a variable`

### package a

```auto
package a;

class Ca1 {
	public static final int V1 = 1;

	public void doSomethingA() {
		// Do something
	}
}

```

```auto
package a;

public class Ca2 extends Ca1 {
	public static final int V2 = 2;
}

```

### package b

```auto
package b;

import a.Ca2;

public class Cb {
	public int doSomethingB() {
		return Ca2.V1;
	}
}

```

---

<div class="post-metadata">

**Author:** ![Dorian\_Burihabwa](https://dub1.discourse-cdn.com/sonarsource/user_avatar/community.sonarsource.com/dorian_burihabwa/32/18750_2.png) [@Dorian\_Burihabwa](https://community.sonarsource.com/u/Dorian_Burihabwa)\
**Post date:** [December 7, 2021, 8:29am UTC](https://community.sonarsource.com/t/false-positive-static-base-class-members-should-not-be-accessed-via-derived-types-java-s3252/53762/4 "2021-12-07T08:29:58Z")

</div>

Hi @Matteo_A_Sorrenti,  
I can confirm the behavior of the rule locally, and the fix suggested is indeed not appropriate.

However, I am not sure this a False Positive. Exposing constants through a child class, without passing through a method, makes the code more difficult to maintain.

I propose that we [change the issue message to suggest exposing the member through a method as an alternative](https://jira.sonarsource.com/browse/SONARJAVA-4093).

---

<div class="post-metadata">

**Author:** ![Matteo\_A\_Sorrenti](https://dub1.discourse-cdn.com/sonarsource/user_avatar/community.sonarsource.com/matteo_a_sorrenti/32/27735_2.png) [@Matteo\_A\_Sorrenti](https://community.sonarsource.com/u/Matteo_A_Sorrenti)\
**Post date:** [December 8, 2021, 9:54am UTC](https://community.sonarsource.com/t/false-positive-static-base-class-members-should-not-be-accessed-via-derived-types-java-s3252/53762/6 "2021-12-08T09:54:42Z")

</div>

Hi @Dorian_Burihabwa,  
I can be agree with you, but it’s possible that package `a` in a library and package `b` is my code.  
If the message appears in the class `Cb` I will not be able to fix it 😉

---

<div class="post-metadata">

**Author:** ![Dorian\_Burihabwa](https://dub1.discourse-cdn.com/sonarsource/user_avatar/community.sonarsource.com/dorian_burihabwa/32/18750_2.png) [@Dorian\_Burihabwa](https://community.sonarsource.com/u/Dorian_Burihabwa)\
**Post date:** [January 14, 2022, 5:05pm UTC](https://community.sonarsource.com/t/false-positive-static-base-class-members-should-not-be-accessed-via-derived-types-java-s3252/53762/9 "2022-01-14T17:05:47Z")

</div>

Hey @Matteo_A_Sorrenti, thanks for having a look again after I created the initial ticket.

I have updated the ticket to an FP report.

Cheers,

Dorian
