diff options
author | Simon Brandhof <simon.brandhof@gmail.com> | 2012-07-24 00:31:18 +0200 |
---|---|---|
committer | Simon Brandhof <simon.brandhof@gmail.com> | 2012-07-24 00:31:18 +0200 |
commit | 9bc3c0d7d2c5670937e0cd69b8fed640bd5133d2 (patch) | |
tree | ea32c7e4b1feaf4900a46e58b9f7fd9c1ebe395f | |
parent | a0a52ddc782e95c38dfb1221064cbf72a41710f0 (diff) | |
download | sonarqube-9bc3c0d7d2c5670937e0cd69b8fed640bd5133d2.tar.gz sonarqube-9bc3c0d7d2c5670937e0cd69b8fed640bd5133d2.zip |
SONAR-3690 Bad charset when reading measure text data
-rw-r--r-- | sonar-plugin-api/src/main/java/org/sonar/api/database/model/MeasureData.java | 25 |
1 files changed, 19 insertions, 6 deletions
diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/database/model/MeasureData.java b/sonar-plugin-api/src/main/java/org/sonar/api/database/model/MeasureData.java index 9dcfb371b8d..d52e0e58ca0 100644 --- a/sonar-plugin-api/src/main/java/org/sonar/api/database/model/MeasureData.java +++ b/sonar-plugin-api/src/main/java/org/sonar/api/database/model/MeasureData.java @@ -19,11 +19,14 @@ */ package org.sonar.api.database.model; +import com.google.common.base.Charsets; +import com.google.common.base.Throwables; import org.apache.commons.lang.builder.ToStringBuilder; import org.apache.commons.lang.builder.ToStringStyle; import org.sonar.api.database.BaseIdentifiable; import javax.persistence.*; +import java.io.UnsupportedEncodingException; @Entity @Table(name = "measure_data") @@ -50,7 +53,12 @@ public class MeasureData extends BaseIdentifiable { public MeasureData(MeasureModel measure, String dataString) { this.measure = measure; - this.data = dataString.getBytes(); + try { + this.data = dataString.getBytes(Charsets.UTF_8.name()); + } catch (UnsupportedEncodingException e) { + // how is it possible to not support UTF-8 ? + Throwables.propagate(e); + } } public MeasureData() { @@ -70,7 +78,12 @@ public class MeasureData extends BaseIdentifiable { public String getText() { if (data != null) { - return new String(data); + try { + return new String(data, Charsets.UTF_8.name()); + } catch (UnsupportedEncodingException e) { + // how is it possible to not support UTF-8 ? + Throwables.propagate(e); + } } return null; } @@ -90,10 +103,10 @@ public class MeasureData extends BaseIdentifiable { @Override public String toString() { return new ToStringBuilder(this, ToStringStyle.SHORT_PREFIX_STYLE) - .append("snapshotId", snapshotId) - .append("mesasure", measure) - .append("data", data) - .toString(); + .append("snapshotId", snapshotId) + .append("mesasure", measure) + .append("data", data) + .toString(); } } |