sonar-swift icon indicating copy to clipboard operation
sonar-swift copied to clipboard

[Bug] SonarScanner errors out due an exception in sonar-swift plugin when source path has a space

Open Kiran-B opened this issue 5 years ago • 7 comments

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

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.

Kiran-B avatar Mar 15 '19 05:03 Kiran-B

I am facing the same issue. However I do not have the spaces in project path.

gauravr-dev avatar Mar 22 '19 09:03 gauravr-dev

I am facing the same issue. However I do not have the spaces in project path.

So am I

jun-jia avatar Mar 28 '19 05:03 jun-jia

+1

remysanfeliu avatar May 09 '19 17:05 remysanfeliu

+1

Naisisor avatar May 22 '19 05:05 Naisisor

+1

theMike avatar Jun 27 '19 12:06 theMike

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;
            }
        }

hgshdt avatar Jul 23 '19 00:07 hgshdt

Does https://github.com/Backelite/sonar-swift/pull/207 solves your issue? If not please submit a PR.

gaelfoppolo avatar Aug 10 '19 16:08 gaelfoppolo