From 13c17c75b530b5b110304960f24d7896d7b1c73c Mon Sep 17 00:00:00 2001 From: Koen De Groote Date: Sat, 6 May 2017 06:28:53 +0200 Subject: [PATCH] Remove unneeded empty string concatentation This commit removes concatenation by empty string in places where it is simply not needed to obtain a string representation. Relates #24411 --- .../main/java/org/elasticsearch/index/engine/Segment.java | 2 +- .../main/java/org/elasticsearch/index/shard/IndexShard.java | 2 +- .../java/org/elasticsearch/repositories/RepositoryData.java | 2 +- .../java/org/elasticsearch/search/lookup/LeafDocLookup.java | 2 +- .../org/elasticsearch/search/lookup/LeafFieldsLookup.java | 2 +- .../org/elasticsearch/snapshots/SnapshotShardsService.java | 2 +- .../main/java/org/elasticsearch/transport/TcpTransport.java | 2 +- .../src/main/java/org/elasticsearch/painless/DefMath.java | 6 ++++-- .../main/java/org/elasticsearch/painless/node/EBinary.java | 2 +- .../aggregations/metrics/AbstractNumericTestCase.java | 6 +++--- .../elasticsearch/test/disruption/NetworkDisruption.java | 2 +- .../elasticsearch/test/disruption/SingleNodeDisruption.java | 2 +- 12 files changed, 17 insertions(+), 15 deletions(-) diff --git a/core/src/main/java/org/elasticsearch/index/engine/Segment.java b/core/src/main/java/org/elasticsearch/index/engine/Segment.java index 565ed9f1d83..4de85d0020d 100644 --- a/core/src/main/java/org/elasticsearch/index/engine/Segment.java +++ b/core/src/main/java/org/elasticsearch/index/engine/Segment.java @@ -284,7 +284,7 @@ public class Segment implements Streamable { out.writeBoolean(((SortedNumericSortField) field).getSelector() == SortedNumericSelector.Type.MAX); out.writeBoolean(field.getReverse()); } else { - throw new IOException("invalid index sort field:" + field + ""); + throw new IOException("invalid index sort field:" + field); } } } diff --git a/core/src/main/java/org/elasticsearch/index/shard/IndexShard.java b/core/src/main/java/org/elasticsearch/index/shard/IndexShard.java index 5e004a4759c..146900542a0 100644 --- a/core/src/main/java/org/elasticsearch/index/shard/IndexShard.java +++ b/core/src/main/java/org/elasticsearch/index/shard/IndexShard.java @@ -399,7 +399,7 @@ public class IndexShard extends AbstractIndexShardComponent implements IndicesCl currentRouting = this.shardRouting; if (!newRouting.shardId().equals(shardId())) { - throw new IllegalArgumentException("Trying to set a routing entry with shardId " + newRouting.shardId() + " on a shard with shardId " + shardId() + ""); + throw new IllegalArgumentException("Trying to set a routing entry with shardId " + newRouting.shardId() + " on a shard with shardId " + shardId()); } if ((currentRouting == null || newRouting.isSameAllocation(currentRouting)) == false) { throw new IllegalArgumentException("Trying to set a routing entry with a different allocation. Current " + currentRouting + ", new " + newRouting); diff --git a/core/src/main/java/org/elasticsearch/repositories/RepositoryData.java b/core/src/main/java/org/elasticsearch/repositories/RepositoryData.java index f823da0f2e5..ee4a64cac87 100644 --- a/core/src/main/java/org/elasticsearch/repositories/RepositoryData.java +++ b/core/src/main/java/org/elasticsearch/repositories/RepositoryData.java @@ -210,7 +210,7 @@ public final class RepositoryData { public Set getSnapshots(final IndexId indexId) { Set snapshotIds = indexSnapshots.get(indexId); if (snapshotIds == null) { - throw new IllegalArgumentException("unknown snapshot index " + indexId + ""); + throw new IllegalArgumentException("unknown snapshot index " + indexId); } return snapshotIds; } diff --git a/core/src/main/java/org/elasticsearch/search/lookup/LeafDocLookup.java b/core/src/main/java/org/elasticsearch/search/lookup/LeafDocLookup.java index f02cf14f4ba..5c75c4a6b1d 100644 --- a/core/src/main/java/org/elasticsearch/search/lookup/LeafDocLookup.java +++ b/core/src/main/java/org/elasticsearch/search/lookup/LeafDocLookup.java @@ -76,7 +76,7 @@ public class LeafDocLookup implements Map> { if (scriptValues == null) { final MappedFieldType fieldType = mapperService.fullName(fieldName); if (fieldType == null) { - throw new IllegalArgumentException("No field found for [" + fieldName + "] in mapping with types " + Arrays.toString(types) + ""); + throw new IllegalArgumentException("No field found for [" + fieldName + "] in mapping with types " + Arrays.toString(types)); } // load fielddata on behalf of the script: otherwise it would need additional permissions // to deal with pagedbytes/ramusagestimator/etc diff --git a/core/src/main/java/org/elasticsearch/search/lookup/LeafFieldsLookup.java b/core/src/main/java/org/elasticsearch/search/lookup/LeafFieldsLookup.java index 374fe7189a8..2d1c855b7c3 100644 --- a/core/src/main/java/org/elasticsearch/search/lookup/LeafFieldsLookup.java +++ b/core/src/main/java/org/elasticsearch/search/lookup/LeafFieldsLookup.java @@ -135,7 +135,7 @@ public class LeafFieldsLookup implements Map { if (data == null) { MappedFieldType fieldType = mapperService.fullName(name); if (fieldType == null) { - throw new IllegalArgumentException("No field found for [" + name + "] in mapping with types " + Arrays.toString(types) + ""); + throw new IllegalArgumentException("No field found for [" + name + "] in mapping with types " + Arrays.toString(types)); } data = new FieldLookup(fieldType); cachedFieldData.put(name, data); diff --git a/core/src/main/java/org/elasticsearch/snapshots/SnapshotShardsService.java b/core/src/main/java/org/elasticsearch/snapshots/SnapshotShardsService.java index 6b42d178694..7cbe10fad3b 100644 --- a/core/src/main/java/org/elasticsearch/snapshots/SnapshotShardsService.java +++ b/core/src/main/java/org/elasticsearch/snapshots/SnapshotShardsService.java @@ -497,7 +497,7 @@ public class SnapshotShardsService extends AbstractLifecycleComponent implements @Override public String toString() { - return "" + snapshot + ", shardId [" + shardId + "], status [" + status.state() + "]"; + return snapshot + ", shardId [" + shardId + "], status [" + status.state() + "]"; } } diff --git a/core/src/main/java/org/elasticsearch/transport/TcpTransport.java b/core/src/main/java/org/elasticsearch/transport/TcpTransport.java index cbdc0dfa178..30a18e05611 100644 --- a/core/src/main/java/org/elasticsearch/transport/TcpTransport.java +++ b/core/src/main/java/org/elasticsearch/transport/TcpTransport.java @@ -684,7 +684,7 @@ public abstract class TcpTransport extends AbstractLifecycleComponent i try { hostAddresses = networkService.resolveBindHostAddresses(bindHosts); } catch (IOException e) { - throw new BindTransportException("Failed to resolve host " + Arrays.toString(bindHosts) + "", e); + throw new BindTransportException("Failed to resolve host " + Arrays.toString(bindHosts), e); } if (logger.isDebugEnabled()) { String[] addresses = new String[hostAddresses.length]; diff --git a/modules/lang-painless/src/main/java/org/elasticsearch/painless/DefMath.java b/modules/lang-painless/src/main/java/org/elasticsearch/painless/DefMath.java index f89b1429f38..66284846606 100644 --- a/modules/lang-painless/src/main/java/org/elasticsearch/painless/DefMath.java +++ b/modules/lang-painless/src/main/java/org/elasticsearch/painless/DefMath.java @@ -379,8 +379,10 @@ public class DefMath { } private static Object add(Object left, Object right) { - if (left instanceof String || right instanceof String) { - return "" + left + right; + if (left instanceof String) { + return (String) left + right; + } else if (right instanceof String) { + return left + (String) right; } else if (left instanceof Number) { if (right instanceof Number) { if (left instanceof Double || right instanceof Double) { diff --git a/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/EBinary.java b/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/EBinary.java index b762a1e114b..72748d7069e 100644 --- a/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/EBinary.java +++ b/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/EBinary.java @@ -291,7 +291,7 @@ public final class EBinary extends AExpression { } else if (sort == Sort.DOUBLE) { constant = (double)left.constant + (double)right.constant; } else if (sort == Sort.STRING) { - constant = "" + left.constant + right.constant; + constant = left.constant.toString() + right.constant.toString(); } else { throw createError(new IllegalStateException("Illegal tree structure.")); } diff --git a/test/framework/src/main/java/org/elasticsearch/search/aggregations/metrics/AbstractNumericTestCase.java b/test/framework/src/main/java/org/elasticsearch/search/aggregations/metrics/AbstractNumericTestCase.java index 29457603c1c..5ce4de82c2a 100644 --- a/test/framework/src/main/java/org/elasticsearch/search/aggregations/metrics/AbstractNumericTestCase.java +++ b/test/framework/src/main/java/org/elasticsearch/search/aggregations/metrics/AbstractNumericTestCase.java @@ -39,7 +39,7 @@ public abstract class AbstractNumericTestCase extends ESIntegTestCase { final int numDocs = 10; for (int i = 0; i < numDocs; i++) { // TODO randomize the size and the params in here? - builders.add(client().prepareIndex("idx", "type", ""+i).setSource(jsonBuilder() + builders.add(client().prepareIndex("idx", "type", String.valueOf(i)).setSource(jsonBuilder() .startObject() .field("value", i+1) .startArray("values").value(i+2).value(i+3).endArray() @@ -58,7 +58,7 @@ public abstract class AbstractNumericTestCase extends ESIntegTestCase { prepareCreate("empty_bucket_idx").addMapping("type", "value", "type=integer").execute().actionGet(); builders = new ArrayList<>(); for (int i = 0; i < 2; i++) { - builders.add(client().prepareIndex("empty_bucket_idx", "type", ""+i).setSource(jsonBuilder() + builders.add(client().prepareIndex("empty_bucket_idx", "type", String.valueOf(i)).setSource(jsonBuilder() .startObject() .field("value", i*2) .endObject())); @@ -96,4 +96,4 @@ public abstract class AbstractNumericTestCase extends ESIntegTestCase { public abstract void testScriptMultiValuedWithParams() throws Exception; public abstract void testOrderByEmptyAggregation() throws Exception; -} \ No newline at end of file +} diff --git a/test/framework/src/main/java/org/elasticsearch/test/disruption/NetworkDisruption.java b/test/framework/src/main/java/org/elasticsearch/test/disruption/NetworkDisruption.java index f3168b94a94..5d731b094d1 100644 --- a/test/framework/src/main/java/org/elasticsearch/test/disruption/NetworkDisruption.java +++ b/test/framework/src/main/java/org/elasticsearch/test/disruption/NetworkDisruption.java @@ -110,7 +110,7 @@ public class NetworkDisruption implements ServiceDisruptionScheme { protected void ensureNodeCount(InternalTestCluster cluster) { assertFalse("cluster failed to form after disruption was healed", cluster.client().admin().cluster().prepareHealth() - .setWaitForNodes("" + cluster.size()) + .setWaitForNodes(String.valueOf(cluster.size())) .setWaitForNoRelocatingShards(true) .get().isTimedOut()); } diff --git a/test/framework/src/main/java/org/elasticsearch/test/disruption/SingleNodeDisruption.java b/test/framework/src/main/java/org/elasticsearch/test/disruption/SingleNodeDisruption.java index 862e18d7aca..a22994cfa9b 100644 --- a/test/framework/src/main/java/org/elasticsearch/test/disruption/SingleNodeDisruption.java +++ b/test/framework/src/main/java/org/elasticsearch/test/disruption/SingleNodeDisruption.java @@ -84,7 +84,7 @@ public abstract class SingleNodeDisruption implements ServiceDisruptionScheme { protected void ensureNodeCount(InternalTestCluster cluster) { assertFalse("cluster failed to form after disruption was healed", cluster.client().admin().cluster().prepareHealth() - .setWaitForNodes("" + cluster.size()) + .setWaitForNodes(String.valueOf(cluster.size())) .setWaitForNoRelocatingShards(true) .get().isTimedOut()); }