Skip to content

Commit

Permalink
Fix some Java compiler warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
Simon Brandhof committed Mar 12, 2018
1 parent f81bf3c commit 35749fa
Show file tree
Hide file tree
Showing 219 changed files with 418 additions and 406 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public void describe(SensorDescriptor descriptor) {
@Override
public void execute(SensorContext context) {
Checks<Check> checks = checkFactory.create(XooRulesDefinition.XOO_REPOSITORY);
checks.addAnnotatedChecks(Check.ALL);
checks.addAnnotatedChecks((Object[]) Check.ALL);
FilePredicates p = context.fileSystem().predicates();
for (InputFile file : context.fileSystem().inputFiles(p.and(p.hasLanguages(Xoo.KEY), p.hasType(Type.MAIN)))) {
for (Check check : checks.all()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,9 @@
import java.util.Collection;
import java.util.List;
import java.util.concurrent.Callable;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.Future;
import java.util.concurrent.ScheduledFuture;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;
import java.util.concurrent.locks.Lock;
import org.junit.Test;
import org.sonar.ce.CeDistributedInformation;
Expand All @@ -35,7 +33,7 @@

import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.fail;
import static org.mockito.Matchers.any;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.doThrow;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.times;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@
import org.sonar.db.ce.CeQueueDto;

import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.Matchers.any;
import static org.mockito.Matchers.eq;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@
import static org.apache.commons.lang.RandomStringUtils.randomAlphanumeric;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.fail;
import static org.mockito.Matchers.any;
import static org.mockito.Matchers.same;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.same;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.verifyZeroInteractions;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,8 @@
import static java.util.Collections.emptySet;
import static java.util.concurrent.TimeUnit.MILLISECONDS;
import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.Matchers.any;
import static org.mockito.Matchers.eq;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.times;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@
import org.sonar.server.computation.task.projectanalysis.taskprocessor.ReportTaskProcessor;

import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.Matchers.any;
import static org.mockito.Matchers.anyString;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.Mockito.doThrow;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.reset;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@

import org.junit.Test;

import static org.mockito.Matchers.anyBoolean;
import static org.mockito.ArgumentMatchers.anyBoolean;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.times;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
import static java.lang.Math.abs;
import static org.apache.commons.lang.RandomStringUtils.randomAlphabetic;
import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.Matchers.anyBoolean;
import static org.mockito.ArgumentMatchers.anyBoolean;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.reset;
import static org.mockito.Mockito.times;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
import org.junit.Test;
import org.sonar.api.utils.log.Logger;

import static org.mockito.Matchers.contains;
import static org.mockito.ArgumentMatchers.contains;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@
import org.sonar.db.purge.PurgeProfiler;
import org.sonar.db.purge.PurgeableAnalysisDto;

import static org.mockito.Matchers.anyListOf;
import static org.mockito.Matchers.eq;
import static org.mockito.ArgumentMatchers.anyList;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.when;
Expand Down Expand Up @@ -66,7 +66,7 @@ public void doClean() {

private Filter newFirstSnapshotInListFilter() {
Filter filter1 = mock(Filter.class);
when(filter1.filter(anyListOf(PurgeableAnalysisDto.class))).thenAnswer(invocation -> Collections.singletonList(((List) invocation.getArguments()[0]).iterator().next()));
when(filter1.filter(anyList())).thenAnswer(invocation -> Collections.singletonList(((List) invocation.getArguments()[0]).iterator().next()));
return filter1;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,14 @@ public void close() {
}

@Override
@SuppressWarnings("unchecked")
public CHILD setString(int columnIndex, @Nullable String value) throws SQLException {
pstmt.setString(columnIndex, value);
return (CHILD) this;
}

@Override
@SuppressWarnings("unchecked")
public CHILD setInt(int columnIndex, @Nullable Integer value) throws SQLException {
if (value == null) {
pstmt.setNull(columnIndex, Types.INTEGER);
Expand All @@ -57,6 +59,7 @@ public CHILD setInt(int columnIndex, @Nullable Integer value) throws SQLExceptio
}

@Override
@SuppressWarnings("unchecked")
public CHILD setLong(int columnIndex, @Nullable Long value) throws SQLException {
if (value == null) {
pstmt.setNull(columnIndex, Types.BIGINT);
Expand All @@ -67,6 +70,7 @@ public CHILD setLong(int columnIndex, @Nullable Long value) throws SQLException
}

@Override
@SuppressWarnings("unchecked")
public CHILD setBoolean(int columnIndex, @Nullable Boolean value) throws SQLException {
if (value == null) {
pstmt.setNull(columnIndex, Types.BOOLEAN);
Expand All @@ -77,6 +81,7 @@ public CHILD setBoolean(int columnIndex, @Nullable Boolean value) throws SQLExce
}

@Override
@SuppressWarnings("unchecked")
public CHILD setBytes(int columnIndex, @Nullable byte[] value) throws SQLException {
if (value == null) {
pstmt.setNull(columnIndex, Types.BINARY);
Expand All @@ -87,6 +92,7 @@ public CHILD setBytes(int columnIndex, @Nullable byte[] value) throws SQLExcepti
}

@Override
@SuppressWarnings("unchecked")
public CHILD setDouble(int columnIndex, @Nullable Double value) throws SQLException {
if (value == null) {
pstmt.setNull(columnIndex, Types.DECIMAL);
Expand All @@ -97,6 +103,7 @@ public CHILD setDouble(int columnIndex, @Nullable Double value) throws SQLExcept
}

@Override
@SuppressWarnings("unchecked")
public CHILD setDate(int columnIndex, @Nullable Date value) throws SQLException {
if (value == null) {
pstmt.setNull(columnIndex, Types.TIMESTAMP);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@
import org.sonar.db.dialect.PostgreSql;

import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.Matchers.any;
import static org.mockito.Matchers.eq;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.doThrow;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.spy;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,9 @@

import static java.lang.String.format;
import static java.util.Arrays.asList;
import static org.mockito.Matchers.any;
import static org.mockito.Matchers.anyString;
import static org.mockito.Matchers.same;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.ArgumentMatchers.same;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.verify;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@
import org.junit.Test;

import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.Matchers.any;
import static org.mockito.Matchers.anyString;
import static org.mockito.Matchers.same;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.ArgumentMatchers.same;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@
import org.junit.rules.ExpectedException;

import static java.util.Arrays.asList;
import static org.mockito.Matchers.any;
import static org.mockito.Matchers.anyString;
import static org.mockito.Matchers.eq;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.verifyZeroInteractions;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@
import org.sonar.api.utils.MessageException;

import static java.util.Collections.singletonList;
import static org.mockito.Matchers.any;
import static org.mockito.Matchers.anyString;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verifyZeroInteractions;
import static org.mockito.Mockito.when;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@
import org.sonar.api.utils.MessageException;

import static java.util.Arrays.asList;
import static org.mockito.Matchers.any;
import static org.mockito.Matchers.anyString;
import static org.mockito.Matchers.same;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.ArgumentMatchers.same;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.verifyZeroInteractions;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@
import org.junit.Test;

import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.Matchers.any;
import static org.mockito.Matchers.anyString;
import static org.mockito.Matchers.same;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.ArgumentMatchers.same;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import static org.assertj.core.api.Assertions.assertThat;
import static org.sonar.server.platform.db.migration.def.TimestampColumnDef.newTimestampColumnDefBuilder;

@SuppressWarnings("deprecation")
public class TimestampColumnDefTest {

@Rule
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
import org.sonar.server.platform.db.migration.version.DbVersion;

import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.Matchers.any;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.doNothing;
import static org.mockito.Mockito.inOrder;
import static org.mockito.Mockito.mock;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ private void insertProperty(String key, @Nullable Integer componentId) {

private void verifyPropertyKeys(String... propertyKeys) {
List<Map<String, Object>> rows = db.select("select prop_key from " + TABLE_PROPERTIES);
Set<Object> result = rows.stream().map(cols -> cols.get("PROP_KEY")).collect(Collectors.toSet());
Set<String> result = rows.stream().map(cols -> (String)cols.get("PROP_KEY")).collect(Collectors.toSet());
assertThat(result).containsOnly(propertyKeys);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
package org.sonar.server.platform.db.migration.version.v67;

import java.sql.SQLException;
import java.util.List;
import org.junit.Rule;
import org.junit.Test;
import org.sonar.db.CoreDbTester;
Expand Down Expand Up @@ -76,8 +75,8 @@ private void assertThatTargetKeyHasValue(String expected) {
}

private void assertThatDeprecatedKeyDoesNotExist() {
List rows = db.select("SELECT * FROM PROPERTIES WHERE PROP_KEY = '" + DEPRECATED_KEY + "'");
assertThat(rows).isEmpty();
assertThat(db.select("SELECT * FROM PROPERTIES WHERE PROP_KEY = '" + DEPRECATED_KEY + "'"))
.isEmpty();
}

public void insertProperty(String key, String value) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,9 +83,9 @@ private void assertPropertiesIsEmpty() {
private void assertProperties(String... expectedSettingKeys) {
assertThat(db.select("SELECT PROP_KEY FROM PROPERTIES")
.stream()
.map(map -> map.get("PROP_KEY"))
.map(map -> (String)map.get("PROP_KEY"))
.collect(Collectors.toList()))
.containsExactlyInAnyOrder(expectedSettingKeys);
.containsExactly(expectedSettingKeys);
}

public void insertProperty(String propertyKey) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@

import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.entry;
import static org.mockito.Matchers.anyString;
import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.Mockito.when;

public class CommandFactoryImplTest {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@

import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.tuple;
import static org.mockito.Matchers.any;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;

Expand Down
11 changes: 6 additions & 5 deletions server/sonar-process/src/main/java/org/sonar/process/Jmx.java
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ private Jmx() {
*/
public static void register(String name, Object instance) {
try {
Class mbeanInterface = guessMBeanInterface(instance);
Class<Object> mbeanInterface = guessMBeanInterface(instance);
ManagementFactory.getPlatformMBeanServer().registerMBean(new StandardMBean(instance, mbeanInterface), new ObjectName(name));

} catch (MalformedObjectNameException | NotCompliantMBeanException | InstanceAlreadyExistsException | MBeanRegistrationException e) {
Expand All @@ -58,10 +58,11 @@ public static void register(String name, Object instance) {
* To avoid the last convention, we wrap the mbean within a StandardMBean. That
* requires to find the related interface.
*/
private static Class guessMBeanInterface(Object instance) {
Class mbeanInterface = null;
Class<?>[] interfaces = instance.getClass().getInterfaces();
for (Class<?> anInterface : interfaces) {

private static Class<Object> guessMBeanInterface(Object instance) {
Class<Object> mbeanInterface = null;
Class<Object>[] interfaces = (Class<Object>[])instance.getClass().getInterfaces();
for (Class<Object> anInterface : interfaces) {
if (anInterface.getName().endsWith("MBean")) {
mbeanInterface = anInterface;
break;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
import org.mockito.ArgumentCaptor;

import static org.assertj.core.api.Assertions.fail;
import static org.mockito.Matchers.eq;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.verifyZeroInteractions;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,7 @@ private static boolean isValidRating(@Nullable String value) {
return isNullOrEmpty(value) || RATING_VALID_INT_VALUES.contains(value);
}

@SuppressWarnings("unchecked")
private static boolean check(boolean expression, List<String> errors, String message, String... args) {
if (!expression) {
errors.add(format(message, args));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@

import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.Assert.fail;
import static org.mockito.Matchers.argThat;
import static org.mockito.ArgumentMatchers.argThat;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@
import org.sonar.process.Props;

import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.Matchers.any;
import static org.mockito.Matchers.anyString;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.Mockito.doThrow;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;
Expand Down
Loading

0 comments on commit 35749fa

Please sign in to comment.