aboutsummaryrefslogtreecommitdiffstats
path: root/sonar-core
diff options
context:
space:
mode:
authorMatteo Mara <matteo.mara@sonarsource.com>2023-12-04 12:50:58 +0100
committersonartech <sonartech@sonarsource.com>2023-12-04 20:03:22 +0000
commitd62a56ecfd4cf2f183873900fd32cffc4743c7fb (patch)
tree552481ceb8b8cab34f74b59563b58278ffa62f69 /sonar-core
parentcdda3dbcdd4e4b5f4a2e7471a37fa66877e26aad (diff)
downloadsonarqube-d62a56ecfd4cf2f183873900fd32cffc4743c7fb.tar.gz
sonarqube-d62a56ecfd4cf2f183873900fd32cffc4743c7fb.zip
SONAR-21174 Fix code smells raised after dropping JDK11 support
Diffstat (limited to 'sonar-core')
-rw-r--r--sonar-core/src/main/java/org/sonar/core/config/CorePropertyDefinitions.java3
-rw-r--r--sonar-core/src/main/java/org/sonar/core/extension/PlatformLevelPredicates.java4
-rw-r--r--sonar-core/src/main/java/org/sonar/core/i18n/DefaultI18n.java8
-rw-r--r--sonar-core/src/main/java/org/sonar/core/issue/status/IssueStatus.java6
-rw-r--r--sonar-core/src/main/java/org/sonar/core/issue/tracking/FilteringBaseInputWrapper.java3
-rw-r--r--sonar-core/src/main/java/org/sonar/core/issue/tracking/Tracker.java3
-rw-r--r--sonar-core/src/main/java/org/sonar/core/platform/ListContainer.java4
-rw-r--r--sonar-core/src/main/java/org/sonar/core/platform/PluginClassLoader.java6
-rw-r--r--sonar-core/src/main/java/org/sonar/core/platform/PriorityBeanFactory.java3
-rw-r--r--sonar-core/src/main/java/org/sonar/core/platform/SpringComponentContainer.java4
-rw-r--r--sonar-core/src/main/java/org/sonar/core/platform/StartableBeanPostProcessor.java10
-rw-r--r--sonar-core/src/main/java/org/sonar/core/util/ContextException.java8
-rw-r--r--sonar-core/src/main/java/org/sonar/core/util/LineReaderIterator.java4
13 files changed, 30 insertions, 36 deletions
diff --git a/sonar-core/src/main/java/org/sonar/core/config/CorePropertyDefinitions.java b/sonar-core/src/main/java/org/sonar/core/config/CorePropertyDefinitions.java
index 1cd570ee65b..70115cc0e27 100644
--- a/sonar-core/src/main/java/org/sonar/core/config/CorePropertyDefinitions.java
+++ b/sonar-core/src/main/java/org/sonar/core/config/CorePropertyDefinitions.java
@@ -22,7 +22,6 @@ package org.sonar.core.config;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
-import java.util.stream.Collectors;
import org.sonar.api.CoreProperties;
import org.sonar.api.PropertyType;
import org.sonar.api.config.EmailSettings;
@@ -130,7 +129,7 @@ public class CorePropertyDefinitions {
.name("State of user plugins risk consent")
.description("Determine whether user is required to accept plugins risk consent")
.defaultValue(NOT_ACCEPTED.name())
- .options(Arrays.stream(PluginRiskConsent.values()).map(Enum::name).collect(Collectors.toList()))
+ .options(Arrays.stream(PluginRiskConsent.values()).map(Enum::name).toList())
.hidden()
.type(SINGLE_SELECT_LIST)
.build(),
diff --git a/sonar-core/src/main/java/org/sonar/core/extension/PlatformLevelPredicates.java b/sonar-core/src/main/java/org/sonar/core/extension/PlatformLevelPredicates.java
index e9b43c76b08..02e117fa6f6 100644
--- a/sonar-core/src/main/java/org/sonar/core/extension/PlatformLevelPredicates.java
+++ b/sonar-core/src/main/java/org/sonar/core/extension/PlatformLevelPredicates.java
@@ -49,9 +49,9 @@ public final class PlatformLevelPredicates {
String baseErrorMsg = "Only level 1, 2, 3 and 4 are supported";
if (annotatedObject == null) {
return baseErrorMsg;
- } else if (annotatedObject instanceof Class) {
+ } else if (annotatedObject instanceof Class classAnnotatedObject) {
return String.format("Invalid value for annotation %s on class '%s'. %s",
- PlatformLevel.class.getName(), ((Class) annotatedObject).getName(),
+ PlatformLevel.class.getName(), classAnnotatedObject.getName(),
baseErrorMsg);
} else {
return String.format("Invalid value for annotation %s on object of type %s. %s",
diff --git a/sonar-core/src/main/java/org/sonar/core/i18n/DefaultI18n.java b/sonar-core/src/main/java/org/sonar/core/i18n/DefaultI18n.java
index d4acff8aef9..1bc2ab0fc30 100644
--- a/sonar-core/src/main/java/org/sonar/core/i18n/DefaultI18n.java
+++ b/sonar-core/src/main/java/org/sonar/core/i18n/DefaultI18n.java
@@ -40,11 +40,11 @@ import java.util.Set;
import javax.annotation.CheckForNull;
import javax.annotation.Nullable;
import org.apache.commons.io.IOUtils;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
import org.sonar.api.Startable;
import org.sonar.api.utils.SonarException;
import org.sonar.api.utils.System2;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
import org.sonar.core.platform.PluginInfo;
import org.sonar.core.platform.PluginRepository;
@@ -117,8 +117,8 @@ public class DefaultI18n implements I18n, Startable {
@Override
public void stop() {
- if (classloader instanceof Closeable) {
- IOUtils.closeQuietly((Closeable) classloader);
+ if (classloader instanceof Closeable closeable) {
+ IOUtils.closeQuietly(closeable);
}
classloader = null;
propertyToBundles = null;
diff --git a/sonar-core/src/main/java/org/sonar/core/issue/status/IssueStatus.java b/sonar-core/src/main/java/org/sonar/core/issue/status/IssueStatus.java
index 8967460de51..0a01b9622cf 100644
--- a/sonar-core/src/main/java/org/sonar/core/issue/status/IssueStatus.java
+++ b/sonar-core/src/main/java/org/sonar/core/issue/status/IssueStatus.java
@@ -51,16 +51,14 @@ public enum IssueStatus {
}
switch (status) {
- case Issue.STATUS_OPEN:
- case Issue.STATUS_REOPENED:
+ case Issue.STATUS_OPEN, Issue.STATUS_REOPENED:
return IssueStatus.OPEN;
case Issue.STATUS_CONFIRMED:
return IssueStatus.CONFIRMED;
case Issue.STATUS_CLOSED:
return IssueStatus.FIXED;
// Security hotspot should not return issue status as they are deprecated.
- case Issue.STATUS_REVIEWED:
- case Issue.STATUS_TO_REVIEW:
+ case Issue.STATUS_REVIEWED, Issue.STATUS_TO_REVIEW:
return null;
default:
}
diff --git a/sonar-core/src/main/java/org/sonar/core/issue/tracking/FilteringBaseInputWrapper.java b/sonar-core/src/main/java/org/sonar/core/issue/tracking/FilteringBaseInputWrapper.java
index 9eb0f09ef4b..3351fa86d13 100644
--- a/sonar-core/src/main/java/org/sonar/core/issue/tracking/FilteringBaseInputWrapper.java
+++ b/sonar-core/src/main/java/org/sonar/core/issue/tracking/FilteringBaseInputWrapper.java
@@ -22,7 +22,6 @@ package org.sonar.core.issue.tracking;
import java.util.Collection;
import java.util.List;
import java.util.function.Predicate;
-import java.util.stream.Collectors;
class FilteringBaseInputWrapper<BASE extends Trackable> implements Input<BASE> {
private final Input<BASE> baseInput;
@@ -33,7 +32,7 @@ class FilteringBaseInputWrapper<BASE extends Trackable> implements Input<BASE> {
Collection<BASE> baseIssues = baseInput.getIssues();
this.nonClosedIssues = baseIssues.stream()
.filter(baseInputFilter)
- .collect(Collectors.toList());
+ .toList();
}
@Override
diff --git a/sonar-core/src/main/java/org/sonar/core/issue/tracking/Tracker.java b/sonar-core/src/main/java/org/sonar/core/issue/tracking/Tracker.java
index a525f660fef..964b0d18693 100644
--- a/sonar-core/src/main/java/org/sonar/core/issue/tracking/Tracker.java
+++ b/sonar-core/src/main/java/org/sonar/core/issue/tracking/Tracker.java
@@ -21,7 +21,6 @@ package org.sonar.core.issue.tracking;
import java.util.Collection;
import java.util.List;
-import java.util.stream.Collectors;
import java.util.stream.Stream;
import org.sonar.api.issue.Issue;
import org.sonar.api.scanner.ScannerSide;
@@ -96,6 +95,6 @@ public class Tracker<RAW extends Trackable, BASE extends Trackable> extends Abst
Collection<BASE> nonClosedIssues = nonClosedTracking.getBaseInput().getIssues();
Collection<BASE> closeIssues = closedTracking.getBaseInput().getIssues();
return Stream.concat(nonClosedIssues.stream(), closeIssues.stream())
- .collect(Collectors.toList());
+ .toList();
}
}
diff --git a/sonar-core/src/main/java/org/sonar/core/platform/ListContainer.java b/sonar-core/src/main/java/org/sonar/core/platform/ListContainer.java
index cd2f9336997..50d314e7e7b 100644
--- a/sonar-core/src/main/java/org/sonar/core/platform/ListContainer.java
+++ b/sonar-core/src/main/java/org/sonar/core/platform/ListContainer.java
@@ -39,8 +39,8 @@ public class ListContainer implements ExtensionContainer {
@Override
public Container add(Object... objects) {
for (Object o : objects) {
- if (o instanceof Module) {
- ((Module) o).configure(this);
+ if (o instanceof Module module) {
+ module.configure(this);
} else if (o instanceof Iterable) {
add(Iterables.toArray((Iterable<?>) o, Object.class));
} else {
diff --git a/sonar-core/src/main/java/org/sonar/core/platform/PluginClassLoader.java b/sonar-core/src/main/java/org/sonar/core/platform/PluginClassLoader.java
index 0da6c64a26c..8096cd012db 100644
--- a/sonar-core/src/main/java/org/sonar/core/platform/PluginClassLoader.java
+++ b/sonar-core/src/main/java/org/sonar/core/platform/PluginClassLoader.java
@@ -27,8 +27,8 @@ import java.util.HashMap;
import java.util.Map;
import java.util.stream.Collectors;
import org.apache.commons.lang.SystemUtils;
-import org.sonar.api.Plugin;
import org.slf4j.LoggerFactory;
+import org.sonar.api.Plugin;
import org.sonar.updatecenter.common.Version;
import static java.util.Collections.singleton;
@@ -142,9 +142,9 @@ public class PluginClassLoader {
public void unload(Collection<Plugin> plugins) {
for (Plugin plugin : plugins) {
ClassLoader classLoader = plugin.getClass().getClassLoader();
- if (classLoader instanceof Closeable && classLoader != classloaderFactory.baseClassLoader()) {
+ if (classLoader instanceof Closeable closeable && classLoader != classloaderFactory.baseClassLoader()) {
try {
- ((Closeable) classLoader).close();
+ closeable.close();
} catch (Exception e) {
LoggerFactory.getLogger(getClass()).error("Fail to close classloader " + classLoader.toString(), e);
}
diff --git a/sonar-core/src/main/java/org/sonar/core/platform/PriorityBeanFactory.java b/sonar-core/src/main/java/org/sonar/core/platform/PriorityBeanFactory.java
index 37be85d7999..b0e9b61a216 100644
--- a/sonar-core/src/main/java/org/sonar/core/platform/PriorityBeanFactory.java
+++ b/sonar-core/src/main/java/org/sonar/core/platform/PriorityBeanFactory.java
@@ -22,7 +22,6 @@ package org.sonar.core.platform;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
-import java.util.stream.Collectors;
import javax.annotation.CheckForNull;
import javax.annotation.Nullable;
import org.springframework.beans.BeanWrapper;
@@ -45,7 +44,7 @@ public class PriorityBeanFactory extends DefaultListableBeanFactory {
List<Bean> candidateBeans = candidates.entrySet().stream()
.filter(e -> e.getValue() != null)
.map(e -> new Bean(e.getKey(), e.getValue()))
- .collect(Collectors.toList());
+ .toList();
List<Bean> beansAfterPriority = highestPriority(candidateBeans, b -> getPriority(b.getInstance()));
if (beansAfterPriority.isEmpty()) {
diff --git a/sonar-core/src/main/java/org/sonar/core/platform/SpringComponentContainer.java b/sonar-core/src/main/java/org/sonar/core/platform/SpringComponentContainer.java
index 142b5780483..079bc8b19cc 100644
--- a/sonar-core/src/main/java/org/sonar/core/platform/SpringComponentContainer.java
+++ b/sonar-core/src/main/java/org/sonar/core/platform/SpringComponentContainer.java
@@ -98,8 +98,8 @@ public class SpringComponentContainer implements StartableContainer {
}
context.registerBean(componentKeys.ofClass(clazz), clazz);
declareExtension("", o);
- } else if (o instanceof Module) {
- ((Module) o).configure(this);
+ } else if (o instanceof Module module) {
+ module.configure(this);
} else if (o instanceof Iterable) {
add(Iterables.toArray((Iterable<?>) o, Object.class));
} else {
diff --git a/sonar-core/src/main/java/org/sonar/core/platform/StartableBeanPostProcessor.java b/sonar-core/src/main/java/org/sonar/core/platform/StartableBeanPostProcessor.java
index e2d25d8e1ee..81bc632008e 100644
--- a/sonar-core/src/main/java/org/sonar/core/platform/StartableBeanPostProcessor.java
+++ b/sonar-core/src/main/java/org/sonar/core/platform/StartableBeanPostProcessor.java
@@ -19,8 +19,8 @@
*/
package org.sonar.core.platform;
-import org.sonar.api.Startable;
import org.slf4j.LoggerFactory;
+import org.sonar.api.Startable;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.config.DestructionAwareBeanPostProcessor;
import org.springframework.lang.Nullable;
@@ -29,8 +29,8 @@ public class StartableBeanPostProcessor implements DestructionAwareBeanPostProce
@Override
@Nullable
public Object postProcessBeforeInitialization(Object bean, String beanName) throws BeansException {
- if (bean instanceof Startable) {
- ((Startable) bean).start();
+ if (bean instanceof Startable startable) {
+ startable.start();
}
return bean;
}
@@ -44,8 +44,8 @@ public class StartableBeanPostProcessor implements DestructionAwareBeanPostProce
public void postProcessBeforeDestruction(Object bean, String beanName) throws BeansException {
try {
// note: Spring will call close() on AutoCloseable beans.
- if (bean instanceof Startable) {
- ((Startable) bean).stop();
+ if (bean instanceof Startable startable) {
+ startable.stop();
}
} catch (Exception e) {
LoggerFactory.getLogger(StartableBeanPostProcessor.class)
diff --git a/sonar-core/src/main/java/org/sonar/core/util/ContextException.java b/sonar-core/src/main/java/org/sonar/core/util/ContextException.java
index a0dedf8b8d5..379dc0c9032 100644
--- a/sonar-core/src/main/java/org/sonar/core/util/ContextException.java
+++ b/sonar-core/src/main/java/org/sonar/core/util/ContextException.java
@@ -112,15 +112,15 @@ public class ContextException extends RuntimeException {
}
public static ContextException of(Throwable t) {
- if (t instanceof ContextException) {
- return new ContextException(t.getCause()).addContext((ContextException) t);
+ if (t instanceof ContextException contextException) {
+ return new ContextException(t.getCause()).addContext(contextException);
}
return new ContextException(t);
}
public static ContextException of(String message, Throwable t) {
- if (t instanceof ContextException) {
- return new ContextException(message, t.getCause()).addContext((ContextException) t);
+ if (t instanceof ContextException contextException) {
+ return new ContextException(message, t.getCause()).addContext(contextException);
}
return new ContextException(message, t);
}
diff --git a/sonar-core/src/main/java/org/sonar/core/util/LineReaderIterator.java b/sonar-core/src/main/java/org/sonar/core/util/LineReaderIterator.java
index a56f4dddd85..aadb47ad592 100644
--- a/sonar-core/src/main/java/org/sonar/core/util/LineReaderIterator.java
+++ b/sonar-core/src/main/java/org/sonar/core/util/LineReaderIterator.java
@@ -32,8 +32,8 @@ public class LineReaderIterator extends CloseableIterator<String> {
private final BufferedReader reader;
public LineReaderIterator(Reader reader) {
- if (reader instanceof BufferedReader) {
- this.reader = (BufferedReader) reader;
+ if (reader instanceof BufferedReader bufferedReader) {
+ this.reader = bufferedReader;
} else {
this.reader = new BufferedReader(reader);
}