sonar-swift
sonar-swift copied to clipboard
[Bug] SonarScanner errors out due an exception in sonar-swift plugin when source path has a space
Describe the bug SonarScanner errors out due an exception in sonar-swift plugin when source path has a space.
To Reproduce Steps to reproduce the behavior: Analyze an Xcode project with a space in its path. An example code structure:
- MyProject.xcodeproj
- My Project
- Project Sources
- AppDelegate.swift
- Project Sources
Expected behavior The analysis should complete and results should be published to Sonarqube.
SonarQube environment:
- OS: MacOS
- sonar-swift: v0.4.4
- SonarQube: 7.6.0.21501
- Lizard: 1.16.3
Additional context Following is the exception:
ERROR: Error during SonarQube Scanner execution
java.lang.StringIndexOutOfBoundsException: String index out of range: -1
at java.lang.String.substring(String.java:1967)
at com.backelite.sonarqube.swift.complexity.LizardReportParser$SwiftFunction.<init>(LizardReportParser.java:181)
at com.backelite.sonarqube.swift.complexity.LizardReportParser.parseMeasure(LizardReportParser.java:120)
at com.backelite.sonarqube.swift.complexity.LizardReportParser.parseFile(LizardReportParser.java:88)
Probable root-cause is the following code, which assumes that there would not be a path in space: https://github.com/Backelite/sonar-swift/blob/42831ead6a8e838fe5db28b0430c77209b72603f/sonar-swift-plugin/src/main/java/com/backelite/sonarqube/swift/complexity/LizardReportParser.java#L178-L181
When the path includes space the name
would include a string similar to :
applicationDidEnterBackground(...) at ./My Project/Project Sources/AppDelegate.swift:27
So at Line 181, val2
would likely have the value ./My
instead of complete path and thus it would not find the :
it is seeking.
I am facing the same issue. However I do not have the spaces in project path.
I am facing the same issue. However I do not have the spaces in project path.
So am I
+1
+1
+1
I am facing the same issue. So my workaround is as follows
sonar-swift/sonar-swift-plugin/src/main/java/com/backelite/sonarqube/swift/complexity/LizardReportParser.java
public SwiftFunction(String name) {
//String[] vals = name.split(" ");
String[] vals = name.split(" at ");
//if(vals.length >= 3){
if(vals.length >= 2){
this.name = vals[0].substring(0,vals[0].indexOf("("));
//this.file = vals[2].substring(0,vals[2].lastIndexOf(":"));
//this.lineNumber = Integer.parseInt(vals[2].substring(vals[2].lastIndexOf(":")+1));
this.file = vals[1].substring(0,vals[1].lastIndexOf(":"));
this.lineNumber = Integer.parseInt(vals[1].substring(vals[1].lastIndexOf(":")+1));
this.key = file.substring(0,file.lastIndexOf('.')+1)+name;
}else{
this.key = name;
}
}
Does https://github.com/Backelite/sonar-swift/pull/207 solves your issue? If not please submit a PR.