aboutsummaryrefslogtreecommitdiffstats
path: root/server/sonar-server
diff options
context:
space:
mode:
authorJulien Lancelot <julien.lancelot@sonarsource.com>2016-10-27 08:36:50 +0200
committerJulien Lancelot <julien.lancelot@sonarsource.com>2016-10-27 08:36:50 +0200
commit301b38feda255b3059ad9647bc00c1500e0c87c2 (patch)
tree115e9d742e0f0ac682d37d142ab9557cc29117f5 /server/sonar-server
parentae09c8785766d362986fb499f2ea4ae46b9a34c8 (diff)
downloadsonarqube-301b38feda255b3059ad9647bc00c1500e0c87c2.tar.gz
sonarqube-301b38feda255b3059ad9647bc00c1500e0c87c2.zip
Fix quality flaws
Diffstat (limited to 'server/sonar-server')
-rw-r--r--server/sonar-server/src/main/java/org/sonar/server/authentication/UserIdentityAuthenticator.java5
-rw-r--r--server/sonar-server/src/main/java/org/sonar/server/platform/monitoring/EsMonitor.java2
-rw-r--r--server/sonar-server/src/main/java/org/sonar/server/qualityprofile/QProfileProjectOperations.java11
-rw-r--r--server/sonar-server/src/main/java/org/sonar/server/qualityprofile/QProfileValidations.java40
4 files changed, 14 insertions, 44 deletions
diff --git a/server/sonar-server/src/main/java/org/sonar/server/authentication/UserIdentityAuthenticator.java b/server/sonar-server/src/main/java/org/sonar/server/authentication/UserIdentityAuthenticator.java
index 53b9dcd309c..bf2b809bdaa 100644
--- a/server/sonar-server/src/main/java/org/sonar/server/authentication/UserIdentityAuthenticator.java
+++ b/server/sonar-server/src/main/java/org/sonar/server/authentication/UserIdentityAuthenticator.java
@@ -25,6 +25,7 @@ import java.util.ArrayList;
import java.util.Collection;
import java.util.HashSet;
import java.util.Map;
+import java.util.Objects;
import java.util.Set;
import javax.annotation.Nonnull;
import org.sonar.api.server.authentication.IdentityProvider;
@@ -136,7 +137,7 @@ public class UserIdentityAuthenticator {
}
private void addGroups(DbSession dbSession, UserDto userDto, Collection<String> groupsToAdd, Map<String, GroupDto> groupsByName) {
- groupsToAdd.stream().map(groupsByName::get).filter(groupDto -> groupDto != null).forEach(
+ groupsToAdd.stream().map(groupsByName::get).filter(Objects::nonNull).forEach(
groupDto -> {
LOGGER.debug("Adding group '{}' to user '{}'", groupDto.getName(), userDto.getLogin());
dbClient.userGroupDao().insert(dbSession, new UserGroupDto().setGroupId(groupDto.getId()).setUserId(userDto.getId()));
@@ -144,7 +145,7 @@ public class UserIdentityAuthenticator {
}
private void removeGroups(DbSession dbSession, UserDto userDto, Collection<String> groupsToRemove, Map<String, GroupDto> groupsByName) {
- groupsToRemove.stream().map(groupsByName::get).filter(groupDto -> groupDto != null).forEach(
+ groupsToRemove.stream().map(groupsByName::get).filter(Objects::nonNull).forEach(
groupDto -> {
LOGGER.debug("Removing group '{}' from user '{}'", groupDto.getName(), userDto.getLogin());
dbClient.userGroupDao().delete(dbSession, groupDto.getId(), userDto.getId());
diff --git a/server/sonar-server/src/main/java/org/sonar/server/platform/monitoring/EsMonitor.java b/server/sonar-server/src/main/java/org/sonar/server/platform/monitoring/EsMonitor.java
index 11bebb80cca..34b48d6bca4 100644
--- a/server/sonar-server/src/main/java/org/sonar/server/platform/monitoring/EsMonitor.java
+++ b/server/sonar-server/src/main/java/org/sonar/server/platform/monitoring/EsMonitor.java
@@ -78,7 +78,7 @@ public class EsMonitor extends BaseMonitorMBean implements EsMonitorMBean {
} catch (Exception es) {
Loggers.get(EsMonitor.class).warn("Failed to retrieve ES attributes. There will be only a single \"state\" attribute.", es);
Map<String, Object> attributes = new LinkedHashMap<>();
- attributes.put("State", (es.getCause() instanceof ElasticsearchException ? es.getCause().getMessage() : es.getMessage()));
+ attributes.put("State", es.getCause() instanceof ElasticsearchException ? es.getCause().getMessage() : es.getMessage());
return attributes;
}
}
diff --git a/server/sonar-server/src/main/java/org/sonar/server/qualityprofile/QProfileProjectOperations.java b/server/sonar-server/src/main/java/org/sonar/server/qualityprofile/QProfileProjectOperations.java
index ae809fd6cbc..604b094d6a6 100644
--- a/server/sonar-server/src/main/java/org/sonar/server/qualityprofile/QProfileProjectOperations.java
+++ b/server/sonar-server/src/main/java/org/sonar/server/qualityprofile/QProfileProjectOperations.java
@@ -19,6 +19,7 @@
*/
package org.sonar.server.qualityprofile;
+import javax.annotation.Nullable;
import org.sonar.api.ce.ComputeEngineSide;
import org.sonar.api.server.ServerSide;
import org.sonar.api.web.UserRole;
@@ -29,6 +30,7 @@ import org.sonar.db.MyBatis;
import org.sonar.db.component.ComponentDto;
import org.sonar.db.qualityprofile.QualityProfileDto;
import org.sonar.server.exceptions.ForbiddenException;
+import org.sonar.server.exceptions.NotFoundException;
import org.sonar.server.user.UserSession;
/**
@@ -119,7 +121,7 @@ public class QProfileProjectOperations {
private QualityProfileDto findNotNull(String key, DbSession session) {
QualityProfileDto qualityProfile = db.qualityProfileDao().selectByKey(session, key);
- QProfileValidations.checkProfileIsNotNull(qualityProfile);
+ checkProfileIsNotNull(qualityProfile);
return qualityProfile;
}
@@ -133,4 +135,11 @@ public class QProfileProjectOperations {
}
}
+ private static QualityProfileDto checkProfileIsNotNull(@Nullable QualityProfileDto profile) {
+ if (profile == null) {
+ throw new NotFoundException("This quality profile does not exists.");
+ }
+ return profile;
+ }
+
}
diff --git a/server/sonar-server/src/main/java/org/sonar/server/qualityprofile/QProfileValidations.java b/server/sonar-server/src/main/java/org/sonar/server/qualityprofile/QProfileValidations.java
deleted file mode 100644
index 0d4635daa51..00000000000
--- a/server/sonar-server/src/main/java/org/sonar/server/qualityprofile/QProfileValidations.java
+++ /dev/null
@@ -1,40 +0,0 @@
-/*
- * SonarQube
- * Copyright (C) 2009-2016 SonarSource SA
- * mailto:contact AT sonarsource DOT com
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 3 of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this program; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- */
-package org.sonar.server.qualityprofile;
-
-import org.sonar.db.qualityprofile.QualityProfileDto;
-import org.sonar.server.exceptions.NotFoundException;
-
-import javax.annotation.Nullable;
-
-public class QProfileValidations {
-
- private QProfileValidations() {
- // Only static methods
- }
-
- public static QualityProfileDto checkProfileIsNotNull(@Nullable QualityProfileDto profile) {
- if (profile == null) {
- throw new NotFoundException("This quality profile does not exists.");
- }
- return profile;
- }
-
-}