Sonarqube gives me issues of deleted codes and can't filter issues

I’m using SonarQube version: 6.7.1
I’m trying to use sonarqube api to analyze archives on a folder and then give the issues of a specific filename but I’ve found two problems

First one is that this is retrieving issues from filenames of source folder that were deleted long time ago and I don’t understand why, because if I enter to sonarqube local web api on localhost/9000 that code is not there

and second and most important, I’m trying to get Issues from a filename but sonarqube is giving me issues from all the project(even projects when I had more than one), including deleted codes from the first problem I said above.

this is how I implemented it

public class SonarqubeServiceImpl implements SonarqubeService {

private final String SONAR_URL = "http://localhost:9000/";
private final String PROJECT_KEY = "refactor2";
private final String SRC_FOLDER = "src/main/java/com/uca/refactor2/activities";
private String EXECUTE_SONAR;
private String GET_ISSUES_URL = SONAR_URL + "api/issues/search?q=";
private static String POM_PATH = "pom.xml";
private RestTemplate restTemplate = new RestTemplate();

private InvocationRequest request;
private Invoker invoker;

private void init() {

public void runAnalysis() throws MavenInvocationException {
    // Assuming everything is set up (done in init)


public IssuesResponse getIssuesFromFileName(String fileName) {
    String URL = GET_ISSUES_URL + fileName;
    return restTemplate.getForObject(URL, IssuesResponse.class);

private void configureMavenWithSonar() {
    request = new DefaultInvocationRequest();
    request.setPomFile(new File(POM_PATH));

    invoker = new DefaultInvoker();
    // Set maven home in case env variables are not set
    // (and using own installation)
    invoker.setMavenHome(new File("apache-maven-3.5.2"));

private void buildSonarCommand() {
    StringBuilder builder = new StringBuilder();
    builder.append("sonar:sonar ");
    builder.append(String.format(" ", SONAR_URL));
    builder.append(String.format("-Dsonar.projectKey=%s ", PROJECT_KEY));
    builder.append(String.format("-Dsonar.sources=%s ", SRC_FOLDER));
    EXECUTE_SONAR = builder.toString();

I’m fetching issues with this URL

http://localhost:9000/api/issues/search?q=" + fileName;

but I get a mix of both errors I said above, I get issues from all files without the filter by fileName and I get issues from archives that doesn’t exist anymore on the folder

this is my first time with Sonarqube, Am I missing something?

edit: I don’t know how to format code, I’ve post the code more readable also at

Hi there,

I’m surprised by this:

Last I checked, there is no q parameter for api/issues/search , so your query might effectively just return all issues on the server :confused:

I suggest you spend some time on the WebAPI documentation first (embedded in your own webserver). For example componentKeys can help you filter on specific files, and you can use api/components to better components and their keys in your project.

Note: code formatting is standard markdown (in this case, ``` helps a lot). I’m putting a note on the SO thread to avoid double-investigations.

1 Like

Thanks for your answer and for the code formatting

it worked perfectly fine with componentKeys now.

1 Like