aboutsummaryrefslogtreecommitdiffstats
path: root/sonar-scanner-engine/src
diff options
context:
space:
mode:
authorJavier García Orduña <javier.garcia@sonarsource.com>2024-12-05 09:44:46 +0100
committersonartech <sonartech@sonarsource.com>2024-12-05 20:03:16 +0000
commit864fba71bc231ef64babee0453a7306d1650210d (patch)
tree541e57d971a697b4b9c6cde44c8d1e7872026064 /sonar-scanner-engine/src
parentb80137d990395bf214dee4c0faf8d1603508ead6 (diff)
downloadsonarqube-864fba71bc231ef64babee0453a7306d1650210d.tar.gz
sonarqube-864fba71bc231ef64babee0453a7306d1650210d.zip
SONAR-22305 Ignore scanner properties with null values
Diffstat (limited to 'sonar-scanner-engine/src')
-rw-r--r--sonar-scanner-engine/src/it/java/org/sonar/scanner/mediumtest/bootstrap/BootstrapMediumIT.java32
-rw-r--r--sonar-scanner-engine/src/main/java/org/sonar/scanner/bootstrap/ScannerMain.java10
2 files changed, 34 insertions, 8 deletions
diff --git a/sonar-scanner-engine/src/it/java/org/sonar/scanner/mediumtest/bootstrap/BootstrapMediumIT.java b/sonar-scanner-engine/src/it/java/org/sonar/scanner/mediumtest/bootstrap/BootstrapMediumIT.java
index ac110567e85..4af42659e6e 100644
--- a/sonar-scanner-engine/src/it/java/org/sonar/scanner/mediumtest/bootstrap/BootstrapMediumIT.java
+++ b/sonar-scanner-engine/src/it/java/org/sonar/scanner/mediumtest/bootstrap/BootstrapMediumIT.java
@@ -126,15 +126,31 @@ class BootstrapMediumIT {
ScannerMain.run(new ByteArrayInputStream("""
{"scannerProperties": [{"value": "aValueWithoutKey"}]}""".getBytes()));
- assertThat(logTester.logs(Level.WARN)).contains("Ignoring property with null key: 'aValueWithoutKey'");
+ assertThat(logTester.logs(Level.WARN)).contains("Ignoring property with null key. Value='aValueWithoutKey'");
+ }
+
+ @Test
+ void should_warn_if_null_property_value() {
+ ScannerMain.run(new ByteArrayInputStream("""
+ {"scannerProperties": [{"key": "aKey", "value": null}]}""".getBytes()));
+
+ assertThat(logTester.logs(Level.WARN)).contains("Ignoring property with null value. Key='aKey'");
+ }
+
+ @Test
+ void should_warn_if_not_provided_property_value() {
+ ScannerMain.run(new ByteArrayInputStream("""
+ {"scannerProperties": [{"key": "aKey"}]}""".getBytes()));
+
+ assertThat(logTester.logs(Level.WARN)).contains("Ignoring property with null value. Key='aKey'");
}
@Test
void should_warn_if_duplicate_property_keys() {
ScannerMain.run(new ByteArrayInputStream("""
- {"scannerProperties": [{"key": "aKey"}, {"key": "aKey"}]}""".getBytes()));
+ {"scannerProperties": [{"key": "aKey", "value": "aValue"}, {"key": "aKey", "value": "aValue"}]}""".getBytes()));
- assertThat(logTester.logs(Level.WARN)).contains("Duplicated properties with key: 'aKey'");
+ assertThat(logTester.logs(Level.WARN)).contains("Duplicated properties. Key='aKey'");
}
@Test
@@ -142,7 +158,15 @@ class BootstrapMediumIT {
ScannerMain.run(new ByteArrayInputStream("""
{"scannerProperties": [{"key": "aKey", "value": "aValue"},]}""".getBytes()));
- assertThat(logTester.logs(Level.WARN)).contains("Ignoring null property");
+ assertThat(logTester.logs(Level.WARN)).contains("Ignoring null or empty property");
+ }
+
+ @Test
+ void should_warn_if_empty_property() {
+ ScannerMain.run(new ByteArrayInputStream("""
+ {"scannerProperties": [{}]}""".getBytes()));
+
+ assertThat(logTester.logs(Level.WARN)).contains("Ignoring null or empty property");
}
/**
diff --git a/sonar-scanner-engine/src/main/java/org/sonar/scanner/bootstrap/ScannerMain.java b/sonar-scanner-engine/src/main/java/org/sonar/scanner/bootstrap/ScannerMain.java
index 887844a1756..3ef1de25629 100644
--- a/sonar-scanner-engine/src/main/java/org/sonar/scanner/bootstrap/ScannerMain.java
+++ b/sonar-scanner-engine/src/main/java/org/sonar/scanner/bootstrap/ScannerMain.java
@@ -118,13 +118,15 @@ public class ScannerMain {
var input = parseJsonInput(in);
if (input != null && input.scannerProperties != null) {
input.scannerProperties.forEach(prop -> {
- if (prop == null) {
- LOG.warn("Ignoring null property");
+ if (prop == null || (prop.key == null && prop.value == null)) {
+ LOG.warn("Ignoring null or empty property");
} else if (prop.key == null) {
- LOG.warn("Ignoring property with null key: '{}'", prop.value);
+ LOG.warn("Ignoring property with null key. Value='{}'", prop.value);
+ } else if (prop.value == null) {
+ LOG.warn("Ignoring property with null value. Key='{}'", prop.key);
} else {
if (properties.containsKey(prop.key)) {
- LOG.warn("Duplicated properties with key: '{}'", prop.key);
+ LOG.warn("Duplicated properties. Key='{}'", prop.key);
}
properties.put(prop.key, prop.value);
}