summaryrefslogtreecommitdiffstats
path: root/sonar-squid/src
diff options
context:
space:
mode:
authorfmallet <freddy.mallet@gmail.com>2010-09-09 08:59:00 +0000
committerfmallet <freddy.mallet@gmail.com>2010-09-09 08:59:00 +0000
commitb2448a6bc0557803f85ad58e688ea9a0959b2a57 (patch)
tree6625006400c3862a7aa0e7dced5bc5c398a87118 /sonar-squid/src
parent0dd067a3efa7f4821fcc4643850b69ba8ac94137 (diff)
downloadsonarqube-b2448a6bc0557803f85ad58e688ea9a0959b2a57.tar.gz
sonarqube-b2448a6bc0557803f85ad58e688ea9a0959b2a57.zip
The MessageFormat class must not be used to format check message when there isn't any parameter. Indeed, otherwise the message can't contain some patterns like "if(){".
Diffstat (limited to 'sonar-squid/src')
-rw-r--r--sonar-squid/src/main/java/org/sonar/squid/api/CheckMessage.java10
-rw-r--r--sonar-squid/src/test/java/org/sonar/squid/api/CheckMessageTest.java10
2 files changed, 15 insertions, 5 deletions
diff --git a/sonar-squid/src/main/java/org/sonar/squid/api/CheckMessage.java b/sonar-squid/src/main/java/org/sonar/squid/api/CheckMessage.java
index a8ce8ed8c17..425b26af8be 100644
--- a/sonar-squid/src/main/java/org/sonar/squid/api/CheckMessage.java
+++ b/sonar-squid/src/main/java/org/sonar/squid/api/CheckMessage.java
@@ -73,11 +73,15 @@ public class CheckMessage implements Message {
@Override
public String toString() {
- return new ToStringBuilder(this).append("source", sourceCode).append("check", codeCheck).append("msg", defaultMessage).append("line",
- line).toString();
+ return new ToStringBuilder(this).append("source", sourceCode).append("check", codeCheck).append("msg", defaultMessage)
+ .append("line", line).toString();
}
public String formatDefaultMessage() {
- return MessageFormat.format(defaultMessage, messageArguments);
+ if (messageArguments.length == 0) {
+ return defaultMessage;
+ } else {
+ return MessageFormat.format(defaultMessage, messageArguments);
+ }
}
}
diff --git a/sonar-squid/src/test/java/org/sonar/squid/api/CheckMessageTest.java b/sonar-squid/src/test/java/org/sonar/squid/api/CheckMessageTest.java
index d2f59c2ef79..1f7e5734918 100644
--- a/sonar-squid/src/test/java/org/sonar/squid/api/CheckMessageTest.java
+++ b/sonar-squid/src/test/java/org/sonar/squid/api/CheckMessageTest.java
@@ -19,11 +19,11 @@
*/
package org.sonar.squid.api;
-import org.junit.Test;
-
import static org.hamcrest.Matchers.is;
import static org.junit.Assert.assertThat;
+import org.junit.Test;
+
public class CheckMessageTest {
@Test
@@ -32,4 +32,10 @@ public class CheckMessageTest {
assertThat(message.formatDefaultMessage(), is("Value is 3, expected value is 7."));
}
+ @Test
+ public void testNotFormatMessageWithoutParameters() {
+ CheckMessage message = new CheckMessage(null, "public void main(){."); // This message can't be used as a pattern by the MessageFormat
+ // class
+ assertThat(message.formatDefaultMessage(), is("public void main(){."));
+ }
}