- Language: Java
- Rule: java:S2637
- SonarQube Server (Developer Edition, v2025.1.5 (119025)) and SonarQube IDE (IntelliJ Version 2025.3 and Plugin 11.11.1.84021)
Reproducer:
Logger is created by Lomboks @Log annotation, issue also occurs with other log annotations.
In this case the return null is not flagged.
import lombok.NonNull;
import lombok.extern.java.Log;
import java.io.IOException;
import java.util.logging.Level;
@Log
public class SonarIssueFP
{
@NonNull
public String hasNoSonarIssue()
{
try
{
int bar = getBar();
return "Bar is " + bar;
}
catch (IOException pE)
{
log.log(Level.SEVERE, "Error occurred while getting bar", pE);
return null; // XXX: Expected to flag here, but nothing given
}
}
public int getBar() throws IOException
{
int bar = (int) System.currentTimeMillis() % 10;
if (bar == 5)
throw new IOException("Bar is 5");
else
return bar;
}
}
Valid example for this case:
Log is now created the normal way. In this case the return null is flagged correctly.
public class SonarIssue
{
private static final java.util.logging.Logger LOGGER = java.util.logging.Logger.getLogger(SonarIssue.class.getName());
@NonNull
public String hasNoSonarIssue()
{
try
{
int bar = getBar();
return "Bar is " + bar;
}
catch (IOException pE)
{
LOGGER.log(Level.SEVERE, "Error occurred while getting bar", pE);
return null; // XXX: Here is an issue correctly flagged
}
}
public int getBar() throws IOException
{
int bar = (int) System.currentTimeMillis() % 10;
if (bar == 5)
throw new IOException("Bar is 5");
else
return bar;
}
}
Used lombok.config
lombok.addLombokGeneratedAnnotation = true
lombok.nonNull.exceptionType = JDK