Search code examples
javasonarqubesonarqube-web

SonarQube FileSystem.inputFile returns null on indexed file access


I'm developing a plugin for SonarQube 5.6 and having trouble creating the Issuable object because of the InputFile object. At sensor's execution I can see all the files indexed (by iterating) with the call

Iterator<InputFile> files = fileSystem.inputFiles(p.and(p.hasLanguage("java"), p.hasType(InputFile.Type.MAIN))).iterator();

but when I try to access the specific file (indexed and shown before) with

java.io.File file = new java.io.File(path);
// file.exists() returns true
InputFile inputFile = fileSystem.inputFile(fileSystem.predicates().is(file));

"inputFile" is null. Even if I try to compose the path it returns null with this instruction:

InputFile inputFile = fileSystem.inputFile(fileSystem.predicates().hasPath(file.getAbsolutePath()));

This is the logging I get which is really weird:

[INFO] File exists.
[INFO] That file AbsolutePath: C:\Program Files (x86)\Jenkins\workspace\soapui\soapui\src\main\java\com\eviware\soapui\impl\wsdl\support\wsdl\AbstractWsdlDefinitionLoader.java
[ERROR] File "C:\Program Files (x86)\Jenkins\workspace\soapui\soapui\src\main\java\com\eviware\soapui\impl\wsdl\support\wsdl\AbstractWsdlDefinitionLoader.java" is not indexed. Skip it.

The annoying fact is that this used to be working but somehow now isn't, without changing this method (that only has the purpose to return an InputFile object). I admit that the problem may be on the requested FilePredicates. Any help is appreciated. Thanks in advance.

EDIT: forgot to mention the strange fact that, after using this exact same instruction to show all indexed files, if I try to use it again (in order to access the InputFile that I'm looking for), the iterator returned can't advance even once:

Iterator<InputFile> files = fileSystem.inputFiles(p.and(p.hasLanguage("java"), p.hasType(InputFile.Type.MAIN))).iterator();

Solution

  • So it happens that the reason for the plugin stopped working as expected with no change in source code was because that, unlike before, I was trying to run an analysis on a project with some sub-projects (modules on it). Apparently this is an issue (or limitation) of SonarQube itself which I didn't was aware of. This limitation is documented in the followinbg Jira ticket.

    So after I split the root project into individual ones, everything ran smooth as before.

    The really strange fact is the behaviour of the SonarQube's engine because it indexed all the files of all the projects but then could not access them.