# squid:UselessImportCheck does not consider static imports used in class annotations

**URL:** <https://community.sonarsource.com/t/squid-uselessimportcheck-does-not-consider-static-imports-used-in-class-annotations/12810>\
**Category:** Report False-positive / False-negative...\
**Tags:** java\
**Created:** [August 6, 2019, 12:36pm UTC](https://community.sonarsource.com/t/squid-uselessimportcheck-does-not-consider-static-imports-used-in-class-annotations/12810 "2019-08-06T12:36:19Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![renoth](https://avatars.discourse-cdn.com/v4/letter/r/e9c0ed/32.png) [@renoth](https://community.sonarsource.com/u/renoth)\
**Post date:** [August 6, 2019, 12:36pm UTC](https://community.sonarsource.com/t/squid-uselessimportcheck-does-not-consider-static-imports-used-in-class-annotations/12810/1 "2019-08-06T12:36:19Z")

</div>

This code gives a warning that the rule unnecessary import is violated, the import DEFAULT\_ALIAS is necessary for compilation however.

package com.sonarqube;

import static Entity.DEFAULT\_ALIAS;

[…]

@Entity  
@DefaultAlias(DEFAULT\_ALIAS)  
public class Entity {

```
public static final String DEFAULT_ALIAS = "alias";

```

[…]  
}

---

<div class="post-metadata">

**Author:** ![Quentin](https://dub1.discourse-cdn.com/sonarsource/user_avatar/community.sonarsource.com/quentin/32/74716_2.png) [@Quentin](https://community.sonarsource.com/u/Quentin)\
**Post date:** [August 8, 2019, 11:27am UTC](https://community.sonarsource.com/t/squid-uselessimportcheck-does-not-consider-static-imports-used-in-class-annotations/12810/3 "2019-08-08T11:27:54Z")

</div>

Hello @renoth,

Thanks for the feedback!  
This issue is similar to the one reported here:

> [@squid:UselessImportCheck false positive for constants used in @NamedQuery annotation](https://community.sonarsource.com/t/squid-uselessimportcheck-false-positive-for-constants-used-in-namedquery-annotation/12675):
>
> The following code: import static SomeEntity.FIND\_BY\_NAME; import javax.persistence.Entity; import javax.persistence.NamedQuery; @NamedQuery( name = FIND\_BY\_NAME, query = "select se from SomeEntity where name = :name" ) @Entity public class SomeEntity { public static final String FIND\_BY\_NAME = "SomeEntity.findByName"; private String name; } triggers squid:UselessImportCheck rule for import static SomeEntity.FIND\_BY\_NAME although the import is used in @NamedQuery annotation. SonarQu…

There is now a [ticket](https://jira.sonarsource.com/browse/SONARJAVA-3177) to track it!

Best,  
Quentin

---

<div class="post-metadata">

**Author:** ![system](https://dub1.discourse-cdn.com/sonarsource/user_avatar/community.sonarsource.com/system/32/31083_2.png) [@system](https://community.sonarsource.com/u/system)\
**Post date:** [April 8, 2021, 9:23am UTC](https://community.sonarsource.com/t/squid-uselessimportcheck-does-not-consider-static-imports-used-in-class-annotations/12810/5 "2021-04-08T09:23:56Z")

</div>

Closed on April 8, 2021, 9:23am UTC

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.
