From a1a430d2ebb3fcad1c816a57214bb057e5ad1560 Mon Sep 17 00:00:00 2001 From: Evgeny Mandrikov Date: Thu, 2 Jun 2011 12:32:21 +0400 Subject: [PATCH] Fix violations --- .../batch/components/PastSnapshotFinder.java | 4 ++-- .../jpa/session/DriverDatabaseConnector.java | 23 ++++++++----------- .../sonar/jpa/session/JpaDatabaseSession.java | 5 ++-- .../java/org/sonar/server/filters/Filter.java | 11 ++++----- .../org/sonar/server/ui/DefaultPages.java | 5 +++- .../org/sonar/wsclient/services/Review.java | 4 +++- .../sonar/wsclient/services/ReviewQuery.java | 5 ++++ 7 files changed, 30 insertions(+), 27 deletions(-) diff --git a/sonar-batch/src/main/java/org/sonar/batch/components/PastSnapshotFinder.java b/sonar-batch/src/main/java/org/sonar/batch/components/PastSnapshotFinder.java index 4962be2b8e6..dd59bb2009d 100644 --- a/sonar-batch/src/main/java/org/sonar/batch/components/PastSnapshotFinder.java +++ b/sonar-batch/src/main/java/org/sonar/batch/components/PastSnapshotFinder.java @@ -63,8 +63,8 @@ public class PastSnapshotFinder implements BatchExtension { case 1: defaultValue = CoreProperties.TIMEMACHINE_DEFAULT_PERIOD_1; break; case 2: defaultValue = CoreProperties.TIMEMACHINE_DEFAULT_PERIOD_2; break; case 3: defaultValue = CoreProperties.TIMEMACHINE_DEFAULT_PERIOD_3; break; - case 4: defaultValue = CoreProperties.TIMEMACHINE_DEFAULT_PERIOD_4; break; - case 5: defaultValue = CoreProperties.TIMEMACHINE_DEFAULT_PERIOD_5; break;// NOSONAR false-positive: constant 5 is the same than 4 (empty string) + case 4: defaultValue = CoreProperties.TIMEMACHINE_DEFAULT_PERIOD_4; break; // NOSONAR false-positive: constant 4 is the same than 5 (empty string) + case 5: defaultValue = CoreProperties.TIMEMACHINE_DEFAULT_PERIOD_5; break; // NOSONAR false-positive: constant 5 is the same than 4 (empty string) } return conf.getString(CoreProperties.TIMEMACHINE_PERIOD_PREFIX + index, defaultValue); } diff --git a/sonar-core/src/main/java/org/sonar/jpa/session/DriverDatabaseConnector.java b/sonar-core/src/main/java/org/sonar/jpa/session/DriverDatabaseConnector.java index d30892f14b4..0b11068040f 100644 --- a/sonar-core/src/main/java/org/sonar/jpa/session/DriverDatabaseConnector.java +++ b/sonar-core/src/main/java/org/sonar/jpa/session/DriverDatabaseConnector.java @@ -76,18 +76,17 @@ public class DriverDatabaseConnector extends AbstractDatabaseConnector { public Connection getConnection() throws SQLException { try { /* - The sonar batch downloads the JDBC driver in a separated classloader. - This is a well-know problem of java.sql.DriverManager. The workaround - is to use a proxy. - See http://stackoverflow.com/questions/288828/how-to-use-a-jdbc-driver-from-an-arbitrary-location + * The sonar batch downloads the JDBC driver in a separated classloader. + * This is a well-know problem of java.sql.DriverManager. The workaround + * is to use a proxy. + * See http://stackoverflow.com/questions/288828/how-to-use-a-jdbc-driver-from-an-arbitrary-location */ - Driver driver = (Driver)classloader.loadClass(getDriver()).newInstance(); + Driver driver = (Driver) classloader.loadClass(getDriver()).newInstance(); DriverManager.registerDriver(new DriverProxy(driver)); } catch (Exception e) { SQLException ex = new SQLException("SQL driver not found " + getDriver()); - ex.initCause(e); - throw ex; + throw (SQLException) ex.initCause(e); } return DriverManager.getConnection(getUrl(), getUsername(), getPassword()); } @@ -113,7 +112,7 @@ final class DriverProxy implements Driver { DriverProxy(Driver target) { if (target == null) { - throw new NullPointerException(); + throw new IllegalArgumentException(); } this.target = target; } @@ -126,9 +125,7 @@ final class DriverProxy implements Driver { return target.acceptsURL(url); } - public Connection connect( - String url, Properties info - ) throws SQLException { + public Connection connect(String url, Properties info) throws SQLException { return target.connect(url, info); } @@ -140,9 +137,7 @@ final class DriverProxy implements Driver { return target.getMinorVersion(); } - public java.sql.DriverPropertyInfo[] getPropertyInfo( - String url, Properties info - ) throws SQLException { + public java.sql.DriverPropertyInfo[] getPropertyInfo(String url, Properties info) throws SQLException { return target.getPropertyInfo(url, info); } diff --git a/sonar-core/src/main/java/org/sonar/jpa/session/JpaDatabaseSession.java b/sonar-core/src/main/java/org/sonar/jpa/session/JpaDatabaseSession.java index ab3ee2417d0..0ae8a5e516e 100644 --- a/sonar-core/src/main/java/org/sonar/jpa/session/JpaDatabaseSession.java +++ b/sonar-core/src/main/java/org/sonar/jpa/session/JpaDatabaseSession.java @@ -160,7 +160,7 @@ public class JpaDatabaseSession extends DatabaseSession { startTransaction(); return entityManager.createQuery(hql); } - + @Override public Query createNativeQuery(String sql) { startTransaction(); @@ -214,8 +214,7 @@ public class JpaDatabaseSession extends DatabaseSession { } catch (NonUniqueResultException ex) { NonUniqueResultException e = new NonUniqueResultException("Expected single result for entitiy " + entityClass.getSimpleName() + " with criterias : " + StringUtils.join(criterias, ",")); - e.initCause(ex); - throw e; + throw (NonUniqueResultException) e.initCause(ex); } } diff --git a/sonar-server/src/main/java/org/sonar/server/filters/Filter.java b/sonar-server/src/main/java/org/sonar/server/filters/Filter.java index 77dcb54b9ff..542a58b6fa7 100644 --- a/sonar-server/src/main/java/org/sonar/server/filters/Filter.java +++ b/sonar-server/src/main/java/org/sonar/server/filters/Filter.java @@ -60,8 +60,6 @@ public class Filter { private boolean useMeasureValueToSort = true; // only if sortedMetricId is not null private boolean ascendingSort = true; - - public Filter setPath(Integer rootSnapshotId, Integer snapshotId, String snapshotPath, boolean isViewContext) { this.baseSnapshotId = snapshotId; if (rootSnapshotId == null) { @@ -331,7 +329,7 @@ public class Filter { } public boolean isOnPeriod() { - return periodIndex>0; + return periodIndex > 0; } static String getVariationColumn(int periodIndex) { @@ -346,14 +344,15 @@ public class Filter { return "variation_value_4"; case 5: return "variation_value_5"; + default: + return null; } - return null; } String getColumnToSort() { String col = "text_value"; if (useMeasureValueToSort()) { - col = (sortedByMeasureVariation==Boolean.TRUE ? getVariationColumn (periodIndex) : "value"); + col = (sortedByMeasureVariation == Boolean.TRUE ? getVariationColumn(periodIndex) : "value"); } return col; } @@ -361,7 +360,7 @@ public class Filter { public boolean mustReturnEmptyResult() { boolean hasCriterionOnVariation = false; for (MeasureCriterion criterion : measureCriteria) { - if (criterion.isVariation()==Boolean.TRUE) { + if (criterion.isVariation() == Boolean.TRUE) { hasCriterionOnVariation = true; } } diff --git a/sonar-server/src/main/java/org/sonar/server/ui/DefaultPages.java b/sonar-server/src/main/java/org/sonar/server/ui/DefaultPages.java index 59f1219ba17..ed976159312 100644 --- a/sonar-server/src/main/java/org/sonar/server/ui/DefaultPages.java +++ b/sonar-server/src/main/java/org/sonar/server/ui/DefaultPages.java @@ -28,7 +28,10 @@ import org.sonar.api.web.*; */ public final class DefaultPages { - private static final View[] PAGES = {new SourceTab(), new CoverageTab(), new ViolationsTab()}; + private static final View[] PAGES = { new SourceTab(), new CoverageTab(), new ViolationsTab() }; + + private DefaultPages() { + } public static View[] getPages() { return PAGES.clone(); diff --git a/sonar-ws-client/src/main/java/org/sonar/wsclient/services/Review.java b/sonar-ws-client/src/main/java/org/sonar/wsclient/services/Review.java index 596b2763639..646e2b2a7a1 100644 --- a/sonar-ws-client/src/main/java/org/sonar/wsclient/services/Review.java +++ b/sonar-ws-client/src/main/java/org/sonar/wsclient/services/Review.java @@ -143,6 +143,7 @@ public class Review extends Model { * @deprecated since 2.9. Use {@link #getFalsePositive()} instead. * @return the type */ + @Deprecated public String getType() { return type; } @@ -152,6 +153,7 @@ public class Review extends Model { * @param s * the type to set */ + @Deprecated public Review setType(String s) { this.type = s; // the following code is only here to ensure backward compatibility with 2.8 @@ -244,7 +246,7 @@ public class Review extends Model { this.falsePositive = falsePositive; return this; } - + /** * @since 2.9 * @return the violation id diff --git a/sonar-ws-client/src/main/java/org/sonar/wsclient/services/ReviewQuery.java b/sonar-ws-client/src/main/java/org/sonar/wsclient/services/ReviewQuery.java index d1858cd242f..07cc0da834e 100644 --- a/sonar-ws-client/src/main/java/org/sonar/wsclient/services/ReviewQuery.java +++ b/sonar-ws-client/src/main/java/org/sonar/wsclient/services/ReviewQuery.java @@ -29,6 +29,9 @@ public class ReviewQuery extends Query { public static final String OUTPUT_PLAIN = "PLAIN"; public static final String OUTPUT_HTML = "HTML"; + /** + * @deprecated since 2.9, but kept for backward compatibility + */ @Deprecated private String reviewType; private Long id; @@ -49,6 +52,7 @@ public class ReviewQuery extends Query { * @deprecated since 2.9 * @return NULL */ + @Deprecated public String getReviewType() { return reviewType; } @@ -58,6 +62,7 @@ public class ReviewQuery extends Query { * @param reviewType * the reviewType to set */ + @Deprecated public ReviewQuery setReviewType(String reviewType) { this.reviewType = reviewType; return this; -- 2.39.5