Validate annotation based on the attribute class

Hello,

I’m trying to validate if the Test1 class has the correct annotation in the test attribute.

public class Test1{
   @Inject //Corrrect is @EJB
   private Test2 test;
   //code
}

@Stateless
public class Test2{
   //code
}

But typeSymbol.declaration() is always null.

Symbol.VariableSymbol variableSymbol = (VariableSymbol) tree.symbol();

Symbol.TypeSymbol typeSymbol = variableSymbol.type().symbol();

if (typeSymbol != null && typeSymbol.declaration() != null) {
  ClassTree classTree = (ClassTree) typeSymbol.declaration();
  // code
} else {
  LOGGER.info("Declaration is null")
}

What am I doing wrong? How can I do this validation?

Hi,

Welcome to the community!

Can you verify that you’re working against a current version of SonarQube?

 
Thx,
Ann

I’m working with the following version:

<sonarqube.version>10.12.0.2522</sonarqube.version>
<sonarjava.version>8.0.1.36337</sonarjava.version>
<jacoco.version>0.8.10</jacoco.version>

Hi,

The current version of the Java analyzer is 8.7.0.37452. Similarly, the version I see in the manifest of the most recent JaCoCo library is 1.3.0.1538.

Can you make sure you’re working against current versions and see if the problem persists?

 
Thx,
Ann