insideapp-oss / sonar-flutter

SonarQube plugin for Flutter / Dart
Other
449 stars 83 forks source link

Analysis fails if any `pubspec.yaml` file does not have a `dependencies` key #205

Closed LPLabrys99 closed 3 months ago

LPLabrys99 commented 10 months ago

Hi there,

I'm trying the sonar-flutter plugin on a project. There is a top-level pubspec.yaml file which is just used for tracking the target dart version.

When the sonar scanner runs it causes a java exception:

java.lang.NullPointerException: Cannot invoke "java.util.Map.containsKey(Object)" because the return value of "java.util.Map.get(Object)" is null
INFO: ------------------------------------------------------------------------
    at fr.insideapp.sonarqube.dart.lang.PubSpecParser.parse(PubSpecParser.java:60)
    at fr.insideapp.sonarqube.dart.lang.issues.dartanalyzer.DartAnalyzerSensor.execute(DartAnalyzerSensor.java:66)
    at org.sonar.scanner.sensor.AbstractSensorWrapper.analyse(AbstractSensorWrapper.java:64)
    at org.sonar.scanner.sensor.ModuleSensorsExecutor.execute(ModuleSensorsExecutor.java:88)
    at org.sonar.scanner.sensor.ModuleSensorsExecutor.lambda$execute$1(ModuleSensorsExecutor.java:61)
    at org.sonar.scanner.sensor.ModuleSensorsExecutor.withModuleStrategy(ModuleSensorsExecutor.java:79)
    at org.sonar.scanner.sensor.ModuleSensorsExecutor.execute(ModuleSensorsExecutor.java:61)
    at org.sonar.scanner.scan.SpringModuleScanContainer.doAfterStart(SpringModuleScanContainer.java:82)
    at org.sonar.core.platform.SpringComponentContainer.startComponents(SpringComponentContainer.java:188)
    at org.sonar.core.platform.SpringComponentContainer.execute(SpringComponentContainer.java:167)
    at org.sonar.scanner.scan.SpringProjectScanContainer.scan(SpringProjectScanContainer.java:398)
    at org.sonar.scanner.scan.SpringProjectScanContainer.scanRecursively(SpringProjectScanContainer.java:394)
    at org.sonar.scanner.scan.SpringProjectScanContainer.doAfterStart(SpringProjectScanContainer.java:363)
    at org.sonar.core.platform.SpringComponentContainer.startComponents(SpringComponentContainer.java:188)
    at org.sonar.core.platform.SpringComponentContainer.execute(SpringComponentContainer.java:167)
    at org.sonar.scanner.bootstrap.SpringGlobalContainer.doAfterStart(SpringGlobalContainer.java:139)
    at org.sonar.core.platform.SpringComponentContainer.startComponents(SpringComponentContainer.java:188)
    at org.sonar.core.platform.SpringComponentContainer.execute(SpringComponentContainer.java:167)
    at org.sonar.batch.bootstrapper.Batch.doExecute(Batch.java:71)
    at org.sonar.batch.bootstrapper.Batch.execute(Batch.java:65)
    at org.sonarsource.scanner.api.internal.batch.BatchIsolatedLauncher.execute(BatchIsolatedLauncher.java:46)
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
    at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
    at java.base/java.lang.reflect.Method.invoke(Unknown Source)
    at org.sonarsource.scanner.api.internal.IsolatedLauncherProxy.invoke(IsolatedLauncherProxy.java:60)
    at jdk.proxy1/jdk.proxy1.$Proxy0.execute(Unknown Source)
    at org.sonarsource.scanner.api.EmbeddedScanner.doExecute(EmbeddedScanner.java:189)
    at org.sonarsource.scanner.api.EmbeddedScanner.execute(EmbeddedScanner.java:138)
    at org.sonarsource.scanner.cli.Main.execute(Main.java:126)
    at org.sonarsource.scanner.cli.Main.execute(Main.java:81)
    at org.sonarsource.scanner.cli.Main.main(Main.java:62)

I had a look through the source code and I believe it's tripped up because one of the pubspec.yaml files does not have a dependencies entry, which this line seems to assume will be present.

https://github.com/insideapp-oss/sonar-flutter/blob/master/dart-lang/src/main/java/fr/insideapp/sonarqube/dart/lang/PubSpecParser.java#L60C23-L60C30

This is what the pubspec.yaml file looks like:

name: project_workspace

environment:
  sdk: '>=2.18.0 <3.0.0'
dev_dependencies:
  melos: ^3.2.0

Thanks

Edit: I found a temporary workaround, add this to the pubspec.yaml file:

dependencies:
  flutter:
    sdk: flutter
github-actions[bot] commented 7 months ago

This issue is stale because it has been open for 90 days with no activity.

santitigaga commented 7 months ago

I think it is more inconvenient to check the pubspec.yaml in version 0.5, in version 0.4 it was not taken into account to analyze the project.

github-actions[bot] commented 3 months ago

This issue is stale because it has been open for 90 days with no activity.

github-actions[bot] commented 3 months ago

This issue was closed because it has been inactive for 14 days since being marked as stale.

stuikomma commented 1 month ago

I just ran into this issue. It appears not to be fixed.

@LPLabrys99 Thanks for providing a simple workaround!