Skip to content

Commit

Permalink
eliminate unchecked suppressions for randomFrom by adding safevarargs
Browse files Browse the repository at this point in the history
  • Loading branch information
vamuzumd committed Mar 11, 2021
1 parent 08c9bbc commit ac39aae
Show file tree
Hide file tree
Showing 12 changed files with 5 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -713,11 +713,15 @@ public static int randomInt(int max) {
}

/** Pick a random object from the given array. The array must not be empty. */
@SafeVarargs
@SuppressWarnings("varargs")
public static <T> T randomFrom(T... array) {
return randomFrom(random(), array);
}

/** Pick a random object from the given array. The array must not be empty. */
@SafeVarargs
@SuppressWarnings("varargs")
public static <T> T randomFrom(Random random, T... array) {
return RandomPicks.randomFrom(random, array);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,6 @@ protected NamedWriteableRegistry getNamedWriteableRegistry() {
return new NamedWriteableRegistry(entries);
}

@SuppressWarnings({"unchecked"})
public static Classification createRandom() {
String dependentVariableName = randomAlphaOfLength(10);
BoostedTreeParams boostedTreeParams = BoostedTreeParamsTests.createRandom();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,6 @@ public static Regression createRandom() {
return createRandom(BoostedTreeParamsTests.createRandom());
}

@SuppressWarnings({"unchecked"})
private static Regression createRandom(BoostedTreeParams boostedTreeParams) {
String dependentVariableName = randomAlphaOfLength(10);
String predictionFieldName = randomBoolean() ? null : randomAlphaOfLength(10);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@

import static org.hamcrest.Matchers.equalTo;

@SuppressWarnings({"unchecked"})
public class InferenceToXContentCompressorTests extends ESTestCase {

public void testInflateAndDeflate() throws IOException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,6 @@ public void chooseStrictOrLenient() {
lenient = randomBoolean();
}

@SuppressWarnings({"unchecked"})
@Override
public NamedObjectContainer createTestInstance() {
int max = randomIntBetween(1, 10);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ public class TrainedModelConfigTests extends AbstractBWCSerializationTestCase<Tr

private boolean lenient;

@SuppressWarnings({"unchecked"})
public static TrainedModelConfig.Builder createTestInstance(String modelId) {
List<String> tags = Arrays.asList(generateRandomStringArray(randomIntBetween(0, 5), 15, false));
return TrainedModelConfig.builder()
Expand Down Expand Up @@ -130,7 +129,6 @@ protected boolean assertToXContentEquivalence() {
return false;
}

@SuppressWarnings({"unchecked"})
public void testToXContentWithParams() throws IOException {
TrainedModelConfig.LazyModelDefinition lazyModelDefinition = TrainedModelConfig.LazyModelDefinition
.fromParsedDefinition(TrainedModelDefinitionTests.createRandomBuilder().build());
Expand Down Expand Up @@ -170,8 +168,7 @@ public void testToXContentWithParams() throws IOException {
assertThat(reference.utf8ToString(), containsString("\"definition\""));
assertThat(reference.utf8ToString(), not(containsString("compressed_definition")));
}

@SuppressWarnings({"unchecked"})

public void testParseWithBothDefinitionAndCompressedSupplied() throws IOException {
TrainedModelConfig.LazyModelDefinition lazyModelDefinition = TrainedModelConfig.LazyModelDefinition
.fromParsedDefinition(TrainedModelDefinitionTests.createRandomBuilder().build());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@ protected boolean assertToXContentEquivalence() {
return false;
}

@SuppressWarnings({"unchecked"})
public static TrainedModelDefinition.Builder createRandomBuilder(TargetType targetType) {
int numberOfProcessors = randomIntBetween(1, 10);
return new TrainedModelDefinition.Builder()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ public static Multi createRandom() {
return createRandom(randomBoolean() ? null : randomBoolean());
}

@SuppressWarnings("unchecked")
public static Multi createRandom(Boolean isCustom) {
final PreProcessor[] processors;
if (isCustom == null || isCustom == false) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,6 @@ public static Ensemble createRandom(TargetType targetType) {
return createRandom(targetType, featureNames);
}

@SuppressWarnings({"unchecked"})
public static Ensemble createRandom(TargetType targetType, List<String> featureNames) {
int numberOfModels = randomIntBetween(1, 10);
List<String> treeFeatureNames = featureNames.isEmpty() ?
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,6 @@ private PutRoleRequest buildRequestWithApplicationPrivilege(String appName, Stri
return request;
}

@SuppressWarnings("unchecked")
private PutRoleRequest buildRandomRequest() {

final PutRoleRequest request = new PutRoleRequest();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@

public class ApplicationPrivilegeDescriptorTests extends ESTestCase {

@SuppressWarnings("unchecked")
public void testEqualsAndHashCode() {
final ApplicationPrivilegeDescriptor privilege = randomPrivilege();
final EqualsHashCodeTestUtils.MutateFunction<ApplicationPrivilegeDescriptor> mutate = randomFrom(
Expand Down Expand Up @@ -121,7 +120,6 @@ public void testParseXContentWithoutUsingDefaultNames() throws IOException {
}
}

@SuppressWarnings("unchecked")
private ApplicationPrivilegeDescriptor randomPrivilege() {
final String applicationName;
if (randomBoolean()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,6 @@ private ApplicationPrivilegeDescriptor descriptor(String application, String nam
return new ApplicationPrivilegeDescriptor(application, name, Sets.newHashSet(actions), Collections.emptyMap());
}

@SuppressWarnings("unchecked")
public void testEqualsAndHashCode() {
final ApplicationPrivilege privilege = randomPrivilege();
final EqualsHashCodeTestUtils.MutateFunction<ApplicationPrivilege> mutate = randomFrom(
Expand Down Expand Up @@ -196,7 +195,6 @@ private void assertNoException(String reason, ThrowingRunnable body) {
}
}

@SuppressWarnings("unchecked")
private ApplicationPrivilege randomPrivilege() {
final String applicationName;
if (randomBoolean()) {
Expand Down

0 comments on commit ac39aae

Please sign in to comment.