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

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

Open
Kiran-B opened this issue Mar 15, 2019 · 7 comments

Comments

@Kiran-B
Copy link

Kiran-B commented Mar 15, 2019

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.

@gauravr-dev
Copy link

gauravr-dev commented Mar 22, 2019

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

@jun-jia
Copy link

jun-jia commented Mar 28, 2019

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

So am I

@remysanfeliu
Copy link

+1

2 similar comments
@Naisisor
Copy link

+1

@theMike
Copy link

theMike commented Jun 27, 2019

+1

@hgshdt
Copy link

hgshdt commented Jul 23, 2019

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

@gaelfoppolo
Copy link
Collaborator

Does #207 solves your issue?
If not please submit a PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

8 participants