From 1f52154068f1750bcce6cf41715ac056e12372dc Mon Sep 17 00:00:00 2001 From: Simon Brandhof Date: Thu, 12 Feb 2015 11:22:17 +0100 Subject: [PATCH] Fix quality flaws --- .../db/migrations/v51/FeedFileSourcesBinaryData.java | 6 +++--- .../component/DefaultRubyComponentServiceTest.java | 2 +- .../org/sonar/core/plugins/PluginClassloaders.java | 2 +- .../main/java/org/sonar/core/rule/CacheRuleFinder.java | 2 +- .../java/org/sonar/core/resource/ResourceDaoTest.java | 2 +- .../org/sonar/api/checks/AnnotationCheckFactory.java | 2 +- .../src/main/java/net/sourceforge/pmd/cpd/Tokens.java | 10 +++++----- .../java/org/sonar/api/batch/ProjectClasspath.java | 2 +- .../main/java/org/sonar/api/component/Component.java | 2 +- .../src/main/java/org/sonar/api/component/Module.java | 2 +- .../main/java/org/sonar/api/component/Perspective.java | 2 +- .../main/java/org/sonar/api/component/SourceFile.java | 2 +- .../main/java/org/sonar/api/profiles/RulesProfile.java | 2 +- 13 files changed, 19 insertions(+), 19 deletions(-) diff --git a/server/sonar-server/src/main/java/org/sonar/server/db/migrations/v51/FeedFileSourcesBinaryData.java b/server/sonar-server/src/main/java/org/sonar/server/db/migrations/v51/FeedFileSourcesBinaryData.java index b80abfd3789..ec57d336812 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/db/migrations/v51/FeedFileSourcesBinaryData.java +++ b/server/sonar-server/src/main/java/org/sonar/server/db/migrations/v51/FeedFileSourcesBinaryData.java @@ -36,8 +36,8 @@ import org.sonar.server.db.migrations.Select; import org.sonar.server.db.migrations.SqlStatement; import org.sonar.server.source.db.FileSourceDb; +import javax.annotation.Nonnull; import javax.annotation.Nullable; - import java.sql.SQLException; import java.util.Iterator; @@ -154,9 +154,9 @@ public class FeedFileSourcesBinaryData extends BaseDataChange { } private static Iterable splitIntegers(String s) { - return Iterables.transform(Splitter.on(',').split(s), new Function() { + return Iterables.transform(Splitter.on(',').omitEmptyStrings().trimResults().split(s), new Function() { @Override - public Integer apply(String input) { + public Integer apply(@Nonnull String input) { return Integer.parseInt(input); } }); diff --git a/server/sonar-server/src/test/java/org/sonar/server/component/DefaultRubyComponentServiceTest.java b/server/sonar-server/src/test/java/org/sonar/server/component/DefaultRubyComponentServiceTest.java index c05ad5ac675..12a7625cf80 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/component/DefaultRubyComponentServiceTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/component/DefaultRubyComponentServiceTest.java @@ -57,7 +57,7 @@ public class DefaultRubyComponentServiceTest { @Test public void find_by_key() { - Component component = mock(Component.class); + Component component = mock(Component.class); when(resourceDao.findByKey("struts")).thenReturn(component); assertThat(service.findByKey("struts")).isEqualTo(component); diff --git a/sonar-core/src/main/java/org/sonar/core/plugins/PluginClassloaders.java b/sonar-core/src/main/java/org/sonar/core/plugins/PluginClassloaders.java index 3565ee5639d..829af0cab7c 100644 --- a/sonar-core/src/main/java/org/sonar/core/plugins/PluginClassloaders.java +++ b/sonar-core/src/main/java/org/sonar/core/plugins/PluginClassloaders.java @@ -240,7 +240,7 @@ public class PluginClassloaders { } public void clean() { - for (ClassRealm realm : (Collection) world.getRealms()) { + for (ClassRealm realm : world.getRealms()) { try { world.disposeRealm(realm.getId()); } catch (Exception e) { diff --git a/sonar-core/src/main/java/org/sonar/core/rule/CacheRuleFinder.java b/sonar-core/src/main/java/org/sonar/core/rule/CacheRuleFinder.java index 96aab429ea5..564acb64baa 100644 --- a/sonar-core/src/main/java/org/sonar/core/rule/CacheRuleFinder.java +++ b/sonar-core/src/main/java/org/sonar/core/rule/CacheRuleFinder.java @@ -90,7 +90,7 @@ public final class CacheRuleFinder implements RuleFinder { Hibernate.initialize(rule.getParams()); } - protected final Rule doFindById(int ruleId) { + private Rule doFindById(int ruleId) { DatabaseSession session = sessionFactory.getSession(); return session.getSingleResult( session.createQuery("FROM " + Rule.class.getSimpleName() + " r WHERE r.id=:id and r.status<>:status") diff --git a/sonar-core/src/test/java/org/sonar/core/resource/ResourceDaoTest.java b/sonar-core/src/test/java/org/sonar/core/resource/ResourceDaoTest.java index ef6948a8c21..56b56b5fe15 100644 --- a/sonar-core/src/test/java/org/sonar/core/resource/ResourceDaoTest.java +++ b/sonar-core/src/test/java/org/sonar/core/resource/ResourceDaoTest.java @@ -345,7 +345,7 @@ public class ResourceDaoTest extends AbstractDaoTestCase { setupData("fixture"); assertThat(dao.findByKey("org.struts:struts")).isNotNull(); - Component component = dao.findByKey("org.struts:struts-core:src/org/struts/RequestContext.java"); + Component component = dao.findByKey("org.struts:struts-core:src/org/struts/RequestContext.java"); assertThat(component).isNotNull(); assertThat(component.path()).isEqualTo("src/org/struts/RequestContext.java"); assertThat(dao.findByKey("unknown")).isNull(); diff --git a/sonar-deprecated/src/main/java/org/sonar/api/checks/AnnotationCheckFactory.java b/sonar-deprecated/src/main/java/org/sonar/api/checks/AnnotationCheckFactory.java index 5ea3909e9a4..1629acf498f 100644 --- a/sonar-deprecated/src/main/java/org/sonar/api/checks/AnnotationCheckFactory.java +++ b/sonar-deprecated/src/main/java/org/sonar/api/checks/AnnotationCheckFactory.java @@ -67,7 +67,7 @@ public final class AnnotationCheckFactory extends CheckFactory { } @Override - protected Object createCheck(ActiveRule activeRule) { + public Object createCheck(ActiveRule activeRule) { Object object = checksByKey.get(activeRule.getConfigKey()); if (object != null) { return instantiate(activeRule, object); diff --git a/sonar-duplications/src/main/java/net/sourceforge/pmd/cpd/Tokens.java b/sonar-duplications/src/main/java/net/sourceforge/pmd/cpd/Tokens.java index d7fbe3303d4..7bdf7c64364 100644 --- a/sonar-duplications/src/main/java/net/sourceforge/pmd/cpd/Tokens.java +++ b/sonar-duplications/src/main/java/net/sourceforge/pmd/cpd/Tokens.java @@ -34,22 +34,22 @@ import java.util.List; */ public class Tokens { - private List tokens = new ArrayList(); + private List entries = new ArrayList<>(); public void add(TokenEntry tokenEntry) { - this.tokens.add(tokenEntry); + this.entries.add(tokenEntry); } public Iterator iterator() { - return tokens.iterator(); + return entries.iterator(); } public int size() { - return tokens.size(); + return entries.size(); } public List getTokens() { - return tokens; + return entries; } } diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/batch/ProjectClasspath.java b/sonar-plugin-api/src/main/java/org/sonar/api/batch/ProjectClasspath.java index 6af187f6315..f7d55073bc5 100644 --- a/sonar-plugin-api/src/main/java/org/sonar/api/batch/ProjectClasspath.java +++ b/sonar-plugin-api/src/main/java/org/sonar/api/batch/ProjectClasspath.java @@ -80,7 +80,7 @@ public class ProjectClasspath implements BatchComponent { try { List files = Lists.newArrayList(); if (pom.getCompileClasspathElements() != null) { - for (String classPathString : (List) pom.getCompileClasspathElements()) { + for (String classPathString : pom.getCompileClasspathElements()) { files.add(new File(classPathString)); } } diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/component/Component.java b/sonar-plugin-api/src/main/java/org/sonar/api/component/Component.java index e68ed4cfa42..098b469a172 100644 --- a/sonar-plugin-api/src/main/java/org/sonar/api/component/Component.java +++ b/sonar-plugin-api/src/main/java/org/sonar/api/component/Component.java @@ -21,7 +21,7 @@ package org.sonar.api.component; import javax.annotation.CheckForNull; -public interface Component { +public interface Component { String key(); /** diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/component/Module.java b/sonar-plugin-api/src/main/java/org/sonar/api/component/Module.java index 6fe58004867..c8fa4d4f62b 100644 --- a/sonar-plugin-api/src/main/java/org/sonar/api/component/Module.java +++ b/sonar-plugin-api/src/main/java/org/sonar/api/component/Module.java @@ -19,7 +19,7 @@ */ package org.sonar.api.component; -public interface Module extends Component { +public interface Module extends Component { String getDescription(); String getBranch(); diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/component/Perspective.java b/sonar-plugin-api/src/main/java/org/sonar/api/component/Perspective.java index a1cc5af2bad..9f5395c0a02 100644 --- a/sonar-plugin-api/src/main/java/org/sonar/api/component/Perspective.java +++ b/sonar-plugin-api/src/main/java/org/sonar/api/component/Perspective.java @@ -19,6 +19,6 @@ */ package org.sonar.api.component; -public interface Perspective> { +public interface Perspective { C component(); } diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/component/SourceFile.java b/sonar-plugin-api/src/main/java/org/sonar/api/component/SourceFile.java index 37347d5f29d..702b817084a 100644 --- a/sonar-plugin-api/src/main/java/org/sonar/api/component/SourceFile.java +++ b/sonar-plugin-api/src/main/java/org/sonar/api/component/SourceFile.java @@ -19,5 +19,5 @@ */ package org.sonar.api.component; -public interface SourceFile extends Component { +public interface SourceFile extends Component { } diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/profiles/RulesProfile.java b/sonar-plugin-api/src/main/java/org/sonar/api/profiles/RulesProfile.java index 45b4053dbfe..15f8bd4b4cf 100644 --- a/sonar-plugin-api/src/main/java/org/sonar/api/profiles/RulesProfile.java +++ b/sonar-plugin-api/src/main/java/org/sonar/api/profiles/RulesProfile.java @@ -133,7 +133,7 @@ public class RulesProfile implements Cloneable { } /** - * @deprecated profile versioning is dropped in 4.4. Always returns -1. + * @deprecated profile versioning is dropped in 4.4. Always returns null. */ @CheckForNull @Deprecated -- 2.39.5