]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-7680 Fallback to class name when Sensor name is not provided 1076/head
authorDuarte Meneses <duarte.meneses@sonarsource.com>
Fri, 1 Jul 2016 14:04:13 +0000 (16:04 +0200)
committerDuarte Meneses <duarte.meneses@sonarsource.com>
Mon, 4 Jul 2016 07:49:59 +0000 (09:49 +0200)
sonar-scanner-engine/src/main/java/org/sonar/batch/sensor/SensorWrapper.java
sonar-scanner-engine/src/main/java/org/sonar/batch/util/BatchUtils.java
sonar-scanner-engine/src/test/java/org/sonar/batch/util/BatchUtilsTest.java

index 3e82a222546a7b5b33f6178ad116a7f5b506f498..2fb6d98ecdbf9428f1f89615d347647b639200b0 100644 (file)
@@ -59,6 +59,10 @@ public class SensorWrapper implements org.sonar.api.batch.Sensor {
 
   @Override
   public String toString() {
-    return descriptor.name() + (LOG.isDebugEnabled() ? " (wrapped)" : "");
+    if (descriptor.name() != null) {
+      return descriptor.name();
+    } else {
+      return wrappedSensor.getClass().getName();
+    }
   }
 }
index 81eed874378d2e32ce3d9d9f253a80cfd77c1319..5b0a8f854371c681b138d89cd88144ff50d6f09d 100644 (file)
@@ -61,7 +61,10 @@ public class BatchUtils {
   public static String describe(Object o) {
     try {
       if (o.getClass().getMethod("toString").getDeclaringClass() != Object.class) {
-        return o.toString();
+        String str = o.toString();
+        if (str != null) {
+          return str;
+        }
       }
     } catch (Exception e) {
       // fallback
index 8de6036b5e39680dadf9e1d2a3745ffda4260c90..eeab4f402a1fb92de1d3b204e0cc6cc3980b8087 100644 (file)
@@ -33,8 +33,13 @@ public class BatchUtilsTest {
     assertThat(BatchUtils.encodeForUrl("foo&bar")).isEqualTo("foo%26bar");
   }
 
+  private class MyClass {
+    @Override
+    public String toString() {
+      return null;
+    }
+  }
   @Test
-  
   public void testDescribe() {
     Object withToString = new Object() {
       @Override
@@ -47,5 +52,6 @@ public class BatchUtilsTest {
 
     assertThat(BatchUtils.describe(withToString)).isEqualTo(("desc"));
     assertThat(BatchUtils.describe(withoutToString)).isEqualTo("java.lang.Object");
+    assertThat(BatchUtils.describe(new MyClass())).endsWith("MyClass");
   }
 }