Skip to content

Commit

Permalink
Fix unnecessary string concatenations (elastic#90405) (elastic#90410)
Browse files Browse the repository at this point in the history
Co-authored-by: Elastic Machine <[email protected]>
  • Loading branch information
tlrx and elasticmachine authored Sep 27, 2022
1 parent 521bfd0 commit 115e2de
Show file tree
Hide file tree
Showing 64 changed files with 74 additions and 94 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ int getFailedAttempts() {
public int compareTo(DeadHostState other) {
if (timeSupplier != other.timeSupplier) {
throw new IllegalArgumentException(
"can't compare DeadHostStates holding different time suppliers as they may " + "be based on different clocks"
"can't compare DeadHostStates holding different time suppliers as they may be based on different clocks"
);
}
return Long.compare(deadUntilNanos, other.deadUntilNanos);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,6 @@ HttpResponse getHttpResponse() {

@Override
public String toString() {
return "Response{" + "requestLine=" + requestLine + ", host=" + host + ", response=" + response.getStatusLine() + '}';
return "Response{requestLine=" + requestLine + ", host=" + host + ", response=" + response.getStatusLine() + '}';
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ static String buildMessage(Response response) throws IOException {
);

if (response.hasWarnings()) {
message += "\n" + "Warnings: " + response.getWarnings();
message += "\nWarnings: " + response.getWarnings();
}

HttpEntity entity = response.getEntity();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -513,9 +513,7 @@ static Iterable<Node> selectNodes(
return singletonList(Collections.min(selectedDeadNodes).node);
}
}
throw new IOException(
"NodeSelector [" + nodeSelector + "] rejected all nodes, " + "living " + livingNodes + " and dead " + deadNodes
);
throw new IOException("NodeSelector [" + nodeSelector + "] rejected all nodes, living " + livingNodes + " and dead " + deadNodes);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ public void testCompareToDifferingTimeSupplier() {
fail("expected failure");
} catch (IllegalArgumentException e) {
assertEquals(
"can't compare DeadHostStates holding different time suppliers as they may " + "be based on different clocks",
"can't compare DeadHostStates holding different time suppliers as they may be based on different clocks",
e.getMessage()
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ public void testBuildCloudId() throws IOException {
RestClient.builder(badId + ":");
fail("should have failed");
} catch (IllegalStateException e) {
assertEquals("cloudId " + badId + ":" + " must begin with a human readable identifier followed by a colon", e.getMessage());
assertEquals("cloudId " + badId + ": must begin with a human readable identifier followed by a colon", e.getMessage());
}

RestClient client = RestClient.builder(encodedId).build();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ public void run() {
ScheduledTask previousTask = nextScheduledTask;
nextScheduledTask = new ScheduledTask(task, future);
assert initialized.get() == false || previousTask.task.isSkipped() || previousTask.task.hasStarted()
: "task that we are replacing is neither " + "cancelled nor has it ever started";
: "task that we are replacing is neither cancelled nor has it ever started";
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ static Optional<String> toPackageName(Path file, String separator) {
if (parent == null) {
String name = file.toString();
if (name.endsWith(".class") && name.equals(MODULE_INFO) == false) {
String msg = name + " found in top-level directory" + " (unnamed package not allowed in module)";
String msg = name + " found in top-level directory (unnamed package not allowed in module)";
throw new InvalidModuleDescriptorException(msg);
}
return Optional.empty();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,9 +84,7 @@ protected void checkLongitude(double longitude) {

protected void checkAltitude(double zValue) {
if (ignoreZValue == false && Double.isNaN(zValue) == false) {
throw new IllegalArgumentException(
"found Z value [" + zValue + "] but [ignore_z_value] " + "parameter is [" + ignoreZValue + "]"
);
throw new IllegalArgumentException("found Z value [" + zValue + "] but [ignore_z_value] parameter is [" + ignoreZValue + "]");
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,7 @@ public static GeometryValidator instance(boolean ignoreZValue) {

protected void checkZ(double zValue) {
if (ignoreZValue == false && Double.isNaN(zValue) == false) {
throw new IllegalArgumentException(
"found Z value [" + zValue + "] but [ignore_z_value] " + "parameter is [" + ignoreZValue + "]"
);
throw new IllegalArgumentException("found Z value [" + zValue + "] but [ignore_z_value] parameter is [" + ignoreZValue + "]");
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public void testInitValidation() {
() -> validator.validate(new LinearRing(new double[] { 3, 4, 5 }, new double[] { 1, 2, 3 }))
);
assertEquals(
"first and last points of the linear ring must be the same (it must close itself): x[0]=3.0 x[2]=5.0 y[0]=1.0 " + "y[2]=3.0",
"first and last points of the linear ring must be the same (it must close itself): x[0]=3.0 x[2]=5.0 y[0]=1.0 y[2]=3.0",
ex.getMessage()
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ public void testWKTValidation() {
)
);
assertEquals(
"first and last points of the linear ring must be the same (it must close itself): " + "x[0]=0.5 x[2]=2.0 y[0]=1.5 y[2]=1.0",
"first and last points of the linear ring must be the same (it must close itself): x[0]=0.5 x[2]=2.0 y[0]=1.5 y[2]=1.0",
ex.getMessage()
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -189,9 +189,7 @@ public void onFailure(Exception e) {
assertThat(e, instanceOf(ElasticsearchException.class));
assertThat(
e.getMessage(),
containsString(
"Secure settings cannot be updated cluster wide when TLS for the " + "transport layer is not enabled"
)
containsString("Secure settings cannot be updated cluster wide when TLS for the transport layer is not enabled")
);
} finally {
latch.countDown();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -470,7 +470,7 @@ public void testAllocationFilteringOnIndexCreation() throws Exception {
if (d.label().equals("filter")) {
assertEquals(Decision.Type.NO, d.type());
assertEquals(
"node does not match index setting [index.routing.allocation.include] filters " + "[_name:\"non_existent_node\"]",
"node does not match index setting [index.routing.allocation.include] filters [_name:\"non_existent_node\"]",
d.getExplanation()
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,10 +84,7 @@ public void testCustomDoesNotMatch() throws Exception {
UserException.class,
() -> removeCustoms(environment, false, new String[] { "index-greveyard-with-typos" })
);
assertThat(
ex.getMessage(),
containsString("No custom metadata matching [index-greveyard-with-typos] were " + "found on this node")
);
assertThat(ex.getMessage(), containsString("No custom metadata matching [index-greveyard-with-typos] were found on this node"));
}

private MockTerminal executeCommand(ElasticsearchNodeCommand command, Environment environment, boolean abort, String... args)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ public void testSettingDoesNotMatch() throws Exception {
);
assertThat(
ex.getMessage(),
containsString("No persistent cluster settings matching [cluster.routing.allocation.disk.bla.*] were " + "found on this node")
containsString("No persistent cluster settings matching [cluster.routing.allocation.disk.bla.*] were found on this node")
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -530,7 +530,7 @@ public void testRestartNodeWhileIndexing() throws Exception {
IndexShard shard = indicesService.getShardOrNull(shardRouting.shardId());
Set<String> docs = IndexShardTestCase.getShardDocUIDs(shard);
assertThat(
"shard [" + shard.routingEntry() + "] docIds [" + docs + "] vs " + " acked docIds [" + ackedDocs + "]",
"shard [" + shard.routingEntry() + "] docIds [" + docs + "] vs acked docIds [" + ackedDocs + "]",
ackedDocs,
everyItem(is(in(docs)))
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1062,7 +1062,7 @@ public void testRecoverLocallyUpToGlobalCheckpoint() throws Exception {
.getShard(0)
.getRetentionLeases();
throw new AssertionError(
"expect an operation-based recovery:" + "retention leases" + Strings.toString(retentionLeases) + "]"
"expect an operation-based recovery:retention leases" + Strings.toString(retentionLeases) + "]"
);
}
connection.sendRequest(requestId, action, request, options);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -964,7 +964,7 @@ public void testPartitionedTemplate() throws Exception {
);
assertThat(
eBadSettings.getMessage(),
containsString("partition size [6] should be a positive number " + "less than the number of shards [5]")
containsString("partition size [6] should be a positive number less than the number of shards [5]")
);

// provide an invalid mapping for a partitioned index
Expand Down Expand Up @@ -1003,7 +1003,7 @@ public void testPartitionedTemplate() throws Exception {

assertThat(
eBadIndex.getMessage(),
containsString("partition size [6] should be a positive number " + "less than the number of shards [5]")
containsString("partition size [6] should be a positive number less than the number of shards [5]")
);

// finally, create a valid index
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ public void testFailStartNode() throws Exception {
assertThat(pipeline.getId(), equalTo("_id"));
assertThat(
pipeline.getDescription(),
equalTo("this is a place holder pipeline, " + "because pipeline with id [_id] could not be loaded")
equalTo("this is a place holder pipeline, because pipeline with id [_id] could not be loaded")
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -531,7 +531,7 @@ public void testStoredScript() {
.setId("my_script")
// Script source is not interpreted but it references a pre-defined script from CustomScriptPlugin
.setContent(
new BytesArray("{ \"script\": {\"lang\": \"" + CustomScriptPlugin.NAME + "\"," + " \"source\": \"my_script\" } }"),
new BytesArray("{ \"script\": {\"lang\": \"" + CustomScriptPlugin.NAME + "\", \"source\": \"my_script\" } }"),
XContentType.JSON
)
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -529,7 +529,7 @@ public void testNeitherSortsNorSizeSpecifiedAndFromIsDefault_ShouldThrowValidati
);
assertThat(
e.getMessage(),
containsString("[bucketSort] is configured to perform nothing." + " Please set either of [sort, size, from] to use bucket_sort")
containsString("[bucketSort] is configured to perform nothing. Please set either of [sort, size, from] to use bucket_sort")
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -358,7 +358,7 @@ public void testEnsureNoNegativeOffsets() throws Exception {
"no_long_term",
"This is a test where foo is highlighed and should be highlighted",
"long_term",
"This is a test thisisaverylongwordandmakessurethisfails where foo is highlighed " + "and should be highlighted"
"This is a test thisisaverylongwordandmakessurethisfails where foo is highlighed and should be highlighted"
)
.get();
refresh();
Expand Down Expand Up @@ -1339,14 +1339,7 @@ public void testSameContent() throws Exception {
.get();

for (int i = 0; i < 5; i++) {
assertHighlight(
search,
i,
"title",
0,
1,
equalTo("This is a test on the highlighting <em>bug</em> " + "present in elasticsearch")
);
assertHighlight(search, i, "title", 0, 1, equalTo("This is a test on the highlighting <em>bug</em> present in elasticsearch"));
}
}

Expand Down Expand Up @@ -1624,7 +1617,7 @@ public void testFastVectorHighlighterShouldFailIfNoTermVectors() throws Exceptio
.highlighter(new HighlightBuilder().field("title", 50, 1, 10).highlighterType("fvh")),
RestStatus.BAD_REQUEST,
containsString(
"the field [title] should be indexed with term vector with position offsets to be " + "used with fast vector highlighter"
"the field [title] should be indexed with term vector with position offsets to be used with fast vector highlighter"
)
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -335,7 +335,7 @@ public int compareTo(Version other) {

@Override
public String toString() {
return "{" + "primaryTerm=" + primaryTerm + ", seqNo=" + seqNo + '}';
return "{primaryTerm=" + primaryTerm + ", seqNo=" + seqNo + '}';
}

public Version nextSeqNo(int increment) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -258,9 +258,7 @@ public void testRequireUnitsOnUpdateSettings() throws Exception {
// expected
assertTrue(
iae.getMessage()
.contains(
"failed to parse setting [index.gc_deletes] with value [42] as a time value: unit is " + "missing or unrecognized"
)
.contains("failed to parse setting [index.gc_deletes] with value [42] as a time value: unit is missing or unrecognized")
);
}
}
Expand Down
2 changes: 1 addition & 1 deletion server/src/main/java/org/elasticsearch/env/ShardLock.java
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public void setDetails(String details) {}

@Override
public String toString() {
return "ShardLock{" + "shardId=" + shardId + '}';
return "ShardLock{shardId=" + shardId + '}';
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,7 @@ public IndexWarmer.TerminationHandle warmReader(final IndexShard indexShard, fin
);
}
} catch (Exception e) {
indexShard.warmerService().logger().warn(() -> "failed to load " + "bitset for [" + filterToWarm + "]", e);
indexShard.warmerService().logger().warn(() -> "failed to load bitset for [" + filterToWarm + "]", e);
} finally {
latch.countDown();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public class PerFieldMapperCodec extends Lucene94Codec {

static {
assert Codec.forName(Lucene.LATEST_CODEC).getClass().isAssignableFrom(PerFieldMapperCodec.class)
: "PerFieldMapperCodec must subclass the latest " + "lucene codec: " + Lucene.LATEST_CODEC;
: "PerFieldMapperCodec must subclass the latest lucene codec: " + Lucene.LATEST_CODEC;
}

public PerFieldMapperCodec(Mode compressionMode, MapperService mapperService, BigArrays bigArrays) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,6 @@ public int hashCode() {

@Override
public String toString() {
return "DeleteVersionValue{" + "version=" + version + ", seqNo=" + seqNo + ", term=" + term + ",time=" + time + '}';
return "DeleteVersionValue{version=" + version + ", seqNo=" + seqNo + ", term=" + term + ",time=" + time + '}';
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ protected void doMerge(MergeSource mergeSource, MergePolicy.OneMerge merge) thro

String message = String.format(
Locale.ROOT,
"merge segment [%s] done: took [%s], [%,.1f MB], [%,d docs], [%s stopped], " + "[%s throttled]",
"merge segment [%s] done: took [%s], [%,.1f MB], [%,d docs], [%s stopped], [%s throttled]",
getSegmentName(merge),
TimeValue.timeValueMillis(tookMS),
totalSizeInBytes / 1024f / 1024f,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1156,7 +1156,7 @@ public void failEngine(String reason, @Nullable Exception failure) {
}
} else {
logger.debug(
() -> format("tried to fail engine but could not acquire lock - engine should " + "be failed by now [%s]", reason),
() -> format("tried to fail engine but could not acquire lock - engine should be failed by now [%s]", reason),
failure
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public int hashCode() {

@Override
public String toString() {
return "IndexVersionValue{" + "version=" + version + ", seqNo=" + seqNo + ", term=" + term + ", location=" + translogLocation + '}';
return "IndexVersionValue{version=" + version + ", seqNo=" + seqNo + ", term=" + term + ", location=" + translogLocation + '}';
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ public int hashCode() {

@Override
public String toString() {
return "VersionValue{" + "version=" + version + ", seqNo=" + seqNo + ", term=" + term + '}';
return "VersionValue{version=" + version + ", seqNo=" + seqNo + ", term=" + term + '}';
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ static Map<String, RuntimeField> parseRuntimeFields(
runtimeFields.put(fieldName, null);
} else {
throw new MapperParsingException(
"Runtime field [" + fieldName + "] was set to null but its removal is not supported " + "in this context"
"Runtime field [" + fieldName + "] was set to null but its removal is not supported in this context"
);
}
} else if (entry.getValue() instanceof Map) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ public static boolean parseMultiField(
String multiFieldName = multiFieldEntry.getKey();
if (multiFieldName.contains(".")) {
throw new MapperParsingException(
"Field name [" + multiFieldName + "] which is a multi field of [" + name + "] cannot" + " contain '.'"
"Field name [" + multiFieldName + "] which is a multi field of [" + name + "] cannot contain '.'"
);
}
if ((multiFieldEntry.getValue() instanceof Map) == false) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ private void addField(ContentPath path, String currentName, String value, List<I
String key = path.pathAsText(currentName);
if (key.contains(SEPARATOR)) {
throw new IllegalArgumentException(
"Keys in [flattened] fields cannot contain the reserved character \\0." + " Offending key: [" + key + "]."
"Keys in [flattened] fields cannot contain the reserved character \\0. Offending key: [" + key + "]."
);
}
String keyedValue = createKeyedValue(key, value);
Expand Down Expand Up @@ -165,7 +165,7 @@ private void addField(ContentPath path, String currentName, String value, List<I
private void validateDepthLimit(ContentPath path) {
if (path.length() + 1 > depthLimit) {
throw new IllegalArgumentException(
"The provided [flattened] field [" + rootFieldName + "]" + " exceeds the maximum depth limit of [" + depthLimit + "]."
"The provided [flattened] field [" + rootFieldName + "] exceeds the maximum depth limit of [" + depthLimit + "]."
);
}
}
Expand Down
Loading

0 comments on commit 115e2de

Please sign in to comment.