Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

source files not found due to hard-coded list of locations (could also find wrong sources actually) #251

Open
Vampire opened this issue Feb 15, 2019 · 0 comments

Comments

@Vampire
Copy link

Vampire commented Feb 15, 2019

Issue Description

When I run the analysis I get messages like The class 'com.foo.Bar' could not be matched to its original source file. It might be a dynamically generated class..
The file is not dynamically generated.
It is generated, but by the build and at the time the analysis is run, it is present on the filesystem.
I thought the problem is, that it is in the gen-src folder and we configured in SQ to exclude gen-src/**, as we are not interested in issues found in generated code.
But even without the exclude it would not find the file, as the ByteCodeResourceLocator has a hard-coded list of possible source locations ("src/main/java","src/main/webapp","src/main/resources", "src", "src/java", "app", "src/main/scala").
Shouldn't this instead use what is configured via sonar.sources property and then also just with full-path, not with ends-with?
Currently the list could be reduced to "src", "app", due to the fix to #51 which introduced an ends-with check. Only due to that it also works for source sets where the code is in src/other/java and so on.
I think it would be much more accurate and reliable if you use the configured source directories and again an exact match algorithm without the ends-with fallback, as with that you could theoretically also find source files that are not related or whatever and that should not be part of the analysis.
You can get the configured list using org.sonar.api.batch.sensor.SensorContext#config().get("sonar.sources") for the currently analyzed module.

Environment

Component Version
SonarQube 7.5
Sonar-FindBugs 3.9.2
Gradle 4.10.3
Java 11.0.1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant