From: Simon Brandhof Date: Mon, 29 Feb 2016 09:11:27 +0000 (+0100) Subject: Fix quality flaws X-Git-Tag: 5.5-M6~97 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=74e26bd277d246d91a08cd7d51f11bff916ee221;p=sonarqube.git Fix quality flaws --- diff --git a/server/sonar-server/src/main/java/org/sonar/server/computation/issue/commonrule/CommentDensityRule.java b/server/sonar-server/src/main/java/org/sonar/server/computation/issue/commonrule/CommentDensityRule.java index 5097a138b47..c3dcbf831a5 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/computation/issue/commonrule/CommentDensityRule.java +++ b/server/sonar-server/src/main/java/org/sonar/server/computation/issue/commonrule/CommentDensityRule.java @@ -71,7 +71,7 @@ public class CommentDensityRule extends CommonRule { return min; } - private CommonRuleIssue generateIssue(Optional commentDensityMeasure, Optional commentLinesMeasure, Optional nclocMeasure, double minCommentDensity) { + private static CommonRuleIssue generateIssue(Optional commentDensityMeasure, Optional commentLinesMeasure, Optional nclocMeasure, double minCommentDensity) { int commentLines = commentLinesMeasure.isPresent() ? commentLinesMeasure.get().getIntValue() : 0; int ncloc = nclocMeasure.get().getIntValue(); int minExpectedCommentLines = (int) Math.ceil(minCommentDensity * ncloc / (100 - minCommentDensity)); diff --git a/server/sonar-server/src/main/java/org/sonar/server/es/Sorting.java b/server/sonar-server/src/main/java/org/sonar/server/es/Sorting.java index 39c81a6c100..ff035f453e0 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/es/Sorting.java +++ b/server/sonar-server/src/main/java/org/sonar/server/es/Sorting.java @@ -73,12 +73,12 @@ public class Sorting { doFill(request, defaultFields, true); } - private void doFill(SearchRequestBuilder request, List fields, boolean asc) { + private static void doFill(SearchRequestBuilder request, List fields, boolean asc) { for (Field field : fields) { FieldSortBuilder sortBuilder = SortBuilders.fieldSort(field.name); - boolean effectiveAsc = asc ? !field.reverse : field.reverse; + boolean effectiveAsc = asc != field.reverse; sortBuilder.order(effectiveAsc ? SortOrder.ASC : SortOrder.DESC); - boolean effectiveMissingLast = asc ? field.missingLast : !field.missingLast; + boolean effectiveMissingLast = asc == field.missingLast; sortBuilder.missing(effectiveMissingLast ? "_last" : "_first"); request.addSort(sortBuilder); } diff --git a/server/sonar-server/src/main/java/org/sonar/server/es/request/ProxyBulkRequestBuilder.java b/server/sonar-server/src/main/java/org/sonar/server/es/request/ProxyBulkRequestBuilder.java index 34df8a47fc3..108a3c2bf06 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/es/request/ProxyBulkRequestBuilder.java +++ b/server/sonar-server/src/main/java/org/sonar/server/es/request/ProxyBulkRequestBuilder.java @@ -71,7 +71,7 @@ public class ProxyBulkRequestBuilder extends BulkRequestBuilder { throw unsupported(); } - private UnsupportedOperationException unsupported() { + private static UnsupportedOperationException unsupported() { throw new UnsupportedOperationException("See " + ProxyBulkRequestBuilder.class.getName()); } diff --git a/sonar-colorizer/src/main/java/org/sonar/colorizer/JavaConstantTokenizer.java b/sonar-colorizer/src/main/java/org/sonar/colorizer/JavaConstantTokenizer.java index 7e0182b8fc3..4874867743e 100644 --- a/sonar-colorizer/src/main/java/org/sonar/colorizer/JavaConstantTokenizer.java +++ b/sonar-colorizer/src/main/java/org/sonar/colorizer/JavaConstantTokenizer.java @@ -47,7 +47,7 @@ public class JavaConstantTokenizer extends Tokenizer { this.tagAfter = tagAfter; } - private boolean hasNextToken(CodeReader code) { + private static boolean hasNextToken(CodeReader code) { int lastChar = code.lastChar(); if (isJavaConstantStart(code.peek()) && !Character.isJavaIdentifierPart(lastChar) && !Character.isJavaIdentifierStart(lastChar) && lastChar != DOT) { diff --git a/sonar-core/src/main/java/org/sonar/core/issue/IssueType.java b/sonar-core/src/main/java/org/sonar/core/issue/IssueType.java index 32a20a80891..19c1bf35b42 100644 --- a/sonar-core/src/main/java/org/sonar/core/issue/IssueType.java +++ b/sonar-core/src/main/java/org/sonar/core/issue/IssueType.java @@ -51,5 +51,5 @@ public enum IssueType { throw new IllegalArgumentException(format("Unsupported value for db column ISSUES.ISSUE_TYPE: %d", dbConstant)); } - public static List ALL_NAMES = Lists.transform(Lists.newArrayList(values()), Enums.stringConverter(IssueType.class).reverse()); + public static final List ALL_NAMES = Lists.transform(Lists.newArrayList(values()), Enums.stringConverter(IssueType.class).reverse()); } diff --git a/sonar-core/src/main/java/org/sonar/core/util/DefaultHttpDownloader.java b/sonar-core/src/main/java/org/sonar/core/util/DefaultHttpDownloader.java index a1572554d86..13e27f72a43 100644 --- a/sonar-core/src/main/java/org/sonar/core/util/DefaultHttpDownloader.java +++ b/sonar-core/src/main/java/org/sonar/core/util/DefaultHttpDownloader.java @@ -207,7 +207,7 @@ public class DefaultHttpDownloader extends HttpDownloader { return Joiner.on(", ").join(descriptions); } - private void registerProxyCredentials(Map settings) { + private static void registerProxyCredentials(Map settings) { Authenticator.setDefault(new ProxyAuthenticator( settings.get(HTTP_PROXY_USER), settings.get(HTTP_PROXY_PASSWORD))); diff --git a/sonar-core/src/main/java/org/sonar/core/util/HttpsTrust.java b/sonar-core/src/main/java/org/sonar/core/util/HttpsTrust.java index 895ebea175e..4946b0a9874 100644 --- a/sonar-core/src/main/java/org/sonar/core/util/HttpsTrust.java +++ b/sonar-core/src/main/java/org/sonar/core/util/HttpsTrust.java @@ -66,7 +66,7 @@ class HttpsTrust { /** * Trust all certificates */ - private SSLSocketFactory createSocketFactory(Ssl context) { + private static SSLSocketFactory createSocketFactory(Ssl context) { try { return context.newFactory(new AlwaysTrustManager()); } catch (Exception e) { @@ -77,7 +77,7 @@ class HttpsTrust { /** * Trust all hosts */ - private HostnameVerifier createHostnameVerifier() { + private static HostnameVerifier createHostnameVerifier() { return new HostnameVerifier() { @Override public boolean verify(String hostname, SSLSession session) { diff --git a/sonar-core/src/test/java/org/sonar/core/issue/IssueTypeTest.java b/sonar-core/src/test/java/org/sonar/core/issue/IssueTypeTest.java index 57bd07483e6..a02bc77c728 100644 --- a/sonar-core/src/test/java/org/sonar/core/issue/IssueTypeTest.java +++ b/sonar-core/src/test/java/org/sonar/core/issue/IssueTypeTest.java @@ -47,4 +47,10 @@ public class IssueTypeTest { public void test_ALL_NAMES() { assertThat(IssueType.ALL_NAMES).containsOnly("BUG", "VULNERABILITY", "CODE_SMELL"); } + + @Test + public void ALL_NAMES_is_immutable() { + expectedException.expect(UnsupportedOperationException.class); + IssueType.ALL_NAMES.add("foo"); + } } diff --git a/sonar-db/src/main/java/org/sonar/db/ce/CeActivityDao.java b/sonar-db/src/main/java/org/sonar/db/ce/CeActivityDao.java index 6bb9b68aff0..050389c8858 100644 --- a/sonar-db/src/main/java/org/sonar/db/ce/CeActivityDao.java +++ b/sonar-db/src/main/java/org/sonar/db/ce/CeActivityDao.java @@ -79,7 +79,7 @@ public class CeActivityDao implements Dao { return mapper(dbSession).countByQuery(query); } - private CeActivityMapper mapper(DbSession dbSession) { + private static CeActivityMapper mapper(DbSession dbSession) { return dbSession.getMapper(CeActivityMapper.class); } } diff --git a/sonar-db/src/main/java/org/sonar/db/ce/CeQueueDao.java b/sonar-db/src/main/java/org/sonar/db/ce/CeQueueDao.java index 543a8f4956d..c6749602493 100644 --- a/sonar-db/src/main/java/org/sonar/db/ce/CeQueueDao.java +++ b/sonar-db/src/main/java/org/sonar/db/ce/CeQueueDao.java @@ -128,7 +128,7 @@ public class CeQueueDao implements Dao { return Optional.of(result); } - private CeQueueMapper mapper(DbSession session) { + private static CeQueueMapper mapper(DbSession session) { return session.getMapper(CeQueueMapper.class); } } diff --git a/sonar-db/src/main/java/org/sonar/db/dashboard/DashboardDao.java b/sonar-db/src/main/java/org/sonar/db/dashboard/DashboardDao.java index 7dc94a8ecdf..8e2a90ff2ce 100644 --- a/sonar-db/src/main/java/org/sonar/db/dashboard/DashboardDao.java +++ b/sonar-db/src/main/java/org/sonar/db/dashboard/DashboardDao.java @@ -83,7 +83,7 @@ public class DashboardDao implements Dao { return mapper(session).selectAllowedById(key, userId != null ? userId : -1L); } - private DashboardMapper mapper(DbSession session) { + private static DashboardMapper mapper(DbSession session) { return session.getMapper(DashboardMapper.class); } } diff --git a/sonar-db/src/main/java/org/sonar/db/dashboard/WidgetDao.java b/sonar-db/src/main/java/org/sonar/db/dashboard/WidgetDao.java index a6a86b2bb73..0b39fccf929 100644 --- a/sonar-db/src/main/java/org/sonar/db/dashboard/WidgetDao.java +++ b/sonar-db/src/main/java/org/sonar/db/dashboard/WidgetDao.java @@ -67,7 +67,7 @@ public class WidgetDao implements Dao { return mapper(session).selectAll(); } - private WidgetMapper mapper(DbSession session) { + private static WidgetMapper mapper(DbSession session) { return session.getMapper(WidgetMapper.class); } diff --git a/sonar-db/src/main/java/org/sonar/db/issue/IssueChangeDao.java b/sonar-db/src/main/java/org/sonar/db/issue/IssueChangeDao.java index 9ea8f81dfff..8b8b32a1534 100644 --- a/sonar-db/src/main/java/org/sonar/db/issue/IssueChangeDao.java +++ b/sonar-db/src/main/java/org/sonar/db/issue/IssueChangeDao.java @@ -140,7 +140,7 @@ public class IssueChangeDao implements Dao { } } - private IssueChangeMapper mapper(DbSession session) { + private static IssueChangeMapper mapper(DbSession session) { return session.getMapper(IssueChangeMapper.class); } } diff --git a/sonar-db/src/main/java/org/sonar/db/issue/IssueDao.java b/sonar-db/src/main/java/org/sonar/db/issue/IssueDao.java index 7c8105f46c5..6e0f9665589 100644 --- a/sonar-db/src/main/java/org/sonar/db/issue/IssueDao.java +++ b/sonar-db/src/main/java/org/sonar/db/issue/IssueDao.java @@ -143,7 +143,7 @@ public class IssueDao implements Dao { mapper(session).update(dto); } - private IssueMapper mapper(DbSession session) { + private static IssueMapper mapper(DbSession session) { return session.getMapper(IssueMapper.class); } diff --git a/sonar-db/src/main/java/org/sonar/db/permission/PermissionDao.java b/sonar-db/src/main/java/org/sonar/db/permission/PermissionDao.java index b305a01b772..a347da0cf0a 100644 --- a/sonar-db/src/main/java/org/sonar/db/permission/PermissionDao.java +++ b/sonar-db/src/main/java/org/sonar/db/permission/PermissionDao.java @@ -140,7 +140,7 @@ public class PermissionDao implements Dao { return params; } - private PermissionMapper mapper(SqlSession session) { + private static PermissionMapper mapper(SqlSession session) { return session.getMapper(PermissionMapper.class); } } diff --git a/sonar-db/src/main/java/org/sonar/db/permission/PermissionTemplateDao.java b/sonar-db/src/main/java/org/sonar/db/permission/PermissionTemplateDao.java index a5ab612198f..cb9c14a51d8 100644 --- a/sonar-db/src/main/java/org/sonar/db/permission/PermissionTemplateDao.java +++ b/sonar-db/src/main/java/org/sonar/db/permission/PermissionTemplateDao.java @@ -419,7 +419,7 @@ public class PermissionTemplateDao implements Dao { return new Date(system.now()); } - private PermissionTemplateMapper mapper(SqlSession session) { + private static PermissionTemplateMapper mapper(SqlSession session) { return session.getMapper(PermissionTemplateMapper.class); } } diff --git a/sonar-db/src/main/java/org/sonar/db/profiling/ProfilingConnectionHandler.java b/sonar-db/src/main/java/org/sonar/db/profiling/ProfilingConnectionHandler.java index 1f373c8d540..eb1d38327f0 100644 --- a/sonar-db/src/main/java/org/sonar/db/profiling/ProfilingConnectionHandler.java +++ b/sonar-db/src/main/java/org/sonar/db/profiling/ProfilingConnectionHandler.java @@ -49,7 +49,7 @@ class ProfilingConnectionHandler implements InvocationHandler { return result; } - private Object buildStatementProxy(Class stmtClass, InvocationHandler handler) { + private static Object buildStatementProxy(Class stmtClass, InvocationHandler handler) { return Proxy.newProxyInstance(ProfilingConnectionHandler.class.getClassLoader(), new Class[] {stmtClass}, handler); } diff --git a/sonar-db/src/main/java/org/sonar/db/purge/PurgeDao.java b/sonar-db/src/main/java/org/sonar/db/purge/PurgeDao.java index a0d89235131..fb8c66be654 100644 --- a/sonar-db/src/main/java/org/sonar/db/purge/PurgeDao.java +++ b/sonar-db/src/main/java/org/sonar/db/purge/PurgeDao.java @@ -206,7 +206,7 @@ public class PurgeDao implements Dao { return resourceDao.selectWholeTreeForRootId(session, rootId, Scopes.PROJECT); } - private PurgeMapper mapper(DbSession session) { + private static PurgeMapper mapper(DbSession session) { return session.getMapper(PurgeMapper.class); } } diff --git a/sonar-db/src/main/java/org/sonar/db/qualitygate/ProjectQgateAssociationDao.java b/sonar-db/src/main/java/org/sonar/db/qualitygate/ProjectQgateAssociationDao.java index aff52156a24..0d541008b5a 100644 --- a/sonar-db/src/main/java/org/sonar/db/qualitygate/ProjectQgateAssociationDao.java +++ b/sonar-db/src/main/java/org/sonar/db/qualitygate/ProjectQgateAssociationDao.java @@ -51,7 +51,7 @@ public class ProjectQgateAssociationDao implements Dao { return selectProjects(query, gateId, 0, Integer.MAX_VALUE); } - private ProjectQgateAssociationMapper mapper(SqlSession session) { + private static ProjectQgateAssociationMapper mapper(SqlSession session) { return session.getMapper(ProjectQgateAssociationMapper.class); } diff --git a/sonar-db/src/main/java/org/sonar/db/rule/RuleDao.java b/sonar-db/src/main/java/org/sonar/db/rule/RuleDao.java index 4cb73663198..92cabb76426 100644 --- a/sonar-db/src/main/java/org/sonar/db/rule/RuleDao.java +++ b/sonar-db/src/main/java/org/sonar/db/rule/RuleDao.java @@ -105,7 +105,7 @@ public class RuleDao implements Dao { mapper(session).insert(dto); } - private RuleMapper mapper(DbSession session) { + private static RuleMapper mapper(DbSession session) { return session.getMapper(RuleMapper.class); } diff --git a/sonar-db/src/main/java/org/sonar/db/user/GroupMembershipDao.java b/sonar-db/src/main/java/org/sonar/db/user/GroupMembershipDao.java index 11e2119c442..d7a9260565e 100644 --- a/sonar-db/src/main/java/org/sonar/db/user/GroupMembershipDao.java +++ b/sonar-db/src/main/java/org/sonar/db/user/GroupMembershipDao.java @@ -111,7 +111,7 @@ public class GroupMembershipDao implements Dao { return selectGroups(query, userId, 0, Integer.MAX_VALUE); } - private GroupMembershipMapper mapper(SqlSession session) { + private static GroupMembershipMapper mapper(SqlSession session) { return session.getMapper(GroupMembershipMapper.class); } } diff --git a/sonar-db/src/main/java/org/sonar/db/version/v52/MoveProjectProfileAssociation.java b/sonar-db/src/main/java/org/sonar/db/version/v52/MoveProjectProfileAssociation.java index bbfdd267962..a34d319b1f4 100644 --- a/sonar-db/src/main/java/org/sonar/db/version/v52/MoveProjectProfileAssociation.java +++ b/sonar-db/src/main/java/org/sonar/db/version/v52/MoveProjectProfileAssociation.java @@ -116,7 +116,7 @@ public class MoveProjectProfileAssociation extends BaseDataChange { } } - private Table getProfileKeysByLanguageThenName(final Context context) throws SQLException { + private static Table getProfileKeysByLanguageThenName(final Context context) throws SQLException { final Table profilesByLanguageAndName = HashBasedTable.create(); Select selectProfiles = context.prepareSelect("SELECT kee, name, language FROM rules_profiles"); diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/batch/rule/Checks.java b/sonar-plugin-api/src/main/java/org/sonar/api/batch/rule/Checks.java index 09bb71d7f66..2778afe56e9 100644 --- a/sonar-plugin-api/src/main/java/org/sonar/api/batch/rule/Checks.java +++ b/sonar-plugin-api/src/main/java/org/sonar/api/batch/rule/Checks.java @@ -141,7 +141,7 @@ public class Checks { return this; } - private String annotatedEngineKey(Object annotatedClassOrObject) { + private static String annotatedEngineKey(Object annotatedClassOrObject) { String key = null; org.sonar.check.Rule ruleAnnotation = AnnotationUtils.getAnnotation(annotatedClassOrObject, org.sonar.check.Rule.class); if (ruleAnnotation != null) { @@ -185,7 +185,7 @@ public class Checks { } @CheckForNull - private Field getField(Object check, String key) { + private static Field getField(Object check, String key) { List fields = FieldUtils2.getFields(check.getClass(), true); for (Field field : fields) { RuleProperty propertyAnnotation = field.getAnnotation(RuleProperty.class); @@ -196,7 +196,7 @@ public class Checks { return null; } - private void configureField(Object check, Field field, String value) { + private static void configureField(Object check, Field field, String value) { try { field.setAccessible(true); diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/checks/AnnotationCheckFactory.java b/sonar-plugin-api/src/main/java/org/sonar/api/checks/AnnotationCheckFactory.java index c5303b05c86..0bd6997a7dd 100644 --- a/sonar-plugin-api/src/main/java/org/sonar/api/checks/AnnotationCheckFactory.java +++ b/sonar-plugin-api/src/main/java/org/sonar/api/checks/AnnotationCheckFactory.java @@ -102,7 +102,7 @@ public final class AnnotationCheckFactory extends CheckFactory { } - private void configureField(Object check, Field field, String value) { + private static void configureField(Object check, Field field, String value) { try { field.setAccessible(true); @@ -147,7 +147,7 @@ public final class AnnotationCheckFactory extends CheckFactory { } } - private Field getField(Object check, String key) { + private static Field getField(Object check, String key) { List fields = FieldUtils2.getFields(check.getClass(), true); for (Field field : fields) { RuleProperty propertyAnnotation = field.getAnnotation(RuleProperty.class); @@ -158,7 +158,7 @@ public final class AnnotationCheckFactory extends CheckFactory { return null; } - private String getRuleKey(Object annotatedClassOrObject) { + private static String getRuleKey(Object annotatedClassOrObject) { String key = null; Rule ruleAnnotation = AnnotationUtils.getAnnotation(annotatedClassOrObject, Rule.class); if (ruleAnnotation != null) { diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/rules/AnnotationRuleParser.java b/sonar-plugin-api/src/main/java/org/sonar/api/rules/AnnotationRuleParser.java index 8c5dec82e03..404da38046e 100644 --- a/sonar-plugin-api/src/main/java/org/sonar/api/rules/AnnotationRuleParser.java +++ b/sonar-plugin-api/src/main/java/org/sonar/api/rules/AnnotationRuleParser.java @@ -82,7 +82,7 @@ public final class AnnotationRuleParser { return rule; } - private void addRuleProperty(Rule rule, Field field) { + private static void addRuleProperty(Rule rule, Field field) { org.sonar.check.RuleProperty propertyAnnotation = field.getAnnotation(org.sonar.check.RuleProperty.class); if (propertyAnnotation != null) { String fieldKey = StringUtils.defaultIfEmpty(propertyAnnotation.key(), field.getName()); diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/server/rule/RulesDefinitionXmlLoader.java b/sonar-plugin-api/src/main/java/org/sonar/api/server/rule/RulesDefinitionXmlLoader.java index f767cb5e0a1..787c6f935aa 100644 --- a/sonar-plugin-api/src/main/java/org/sonar/api/server/rule/RulesDefinitionXmlLoader.java +++ b/sonar-plugin-api/src/main/java/org/sonar/api/server/rule/RulesDefinitionXmlLoader.java @@ -280,11 +280,8 @@ public class RulesDefinitionXmlLoader { } else if (equalsIgnoreCase("internalKey", nodeName)) { internalKey = nodeValue(cursor); - } else if (equalsIgnoreCase("priority", nodeName)) { - // deprecated field, replaced by severity - severity = nodeValue(cursor); - - } else if (equalsIgnoreCase("severity", nodeName)) { + } else if (equalsIgnoreCase("priority", nodeName) || equalsIgnoreCase("severity", nodeName)) { + // "priority" is deprecated field and has been replaced by "severity" severity = nodeValue(cursor); } else if (equalsIgnoreCase("cardinality", nodeName)) { @@ -380,7 +377,7 @@ public class RulesDefinitionXmlLoader { RuleParamType type = RuleParamType.STRING; } - private ParamStruct processParameter(SMInputCursor ruleC) throws XMLStreamException { + private static ParamStruct processParameter(SMInputCursor ruleC) throws XMLStreamException { ParamStruct param = new ParamStruct(); // BACKWARD COMPATIBILITY WITH DEPRECATED FORMAT