From 2881c4fa94fb0a4095c63b6f4a5cca76bb932e7c Mon Sep 17 00:00:00 2001 From: Jason Tedor Date: Fri, 2 Oct 2015 15:17:54 -0400 Subject: [PATCH] Remove and forbid use of com.google.common.collect.Iterators This commit removes and now forbids all uses of com.google.common.collect.Iterators across the codebase. This is one of the final steps in the eventual removal of Guava as a dependency. Relates #13224 --- .../indices/segments/IndexShardSegments.java | 4 +- .../admin/indices/stats/IndexShardStats.java | 4 +- .../upgrade/get/IndexShardUpgradeStatus.java | 4 +- .../action/bulk/BulkResponse.java | 4 +- .../action/get/MultiGetRequest.java | 9 +- .../action/get/MultiGetResponse.java | 6 +- .../percolate/MultiPercolateResponse.java | 4 +- .../action/search/MultiSearchResponse.java | 5 +- .../termvectors/MultiTermVectorsRequest.java | 4 +- .../termvectors/MultiTermVectorsResponse.java | 4 +- .../cluster/routing/RoutingNode.java | 9 +- .../cluster/routing/RoutingNodes.java | 4 +- .../common/collect/Iterators.java | 68 ++++++++ .../common/io/FileSystemUtils.java | 14 +- .../common/util/CollectionUtils.java | 12 +- .../Elasticsearch090PostingsFormat.java | 5 - .../elasticsearch/index/engine/Segment.java | 2 - .../index/mapper/MapperService.java | 11 +- .../index/mapper/geo/GeoPointFieldMapper.java | 25 +-- .../org/elasticsearch/monitor/fs/FsInfo.java | 4 +- .../elasticsearch/monitor/jvm/JvmStats.java | 6 +- .../elasticsearch/plugins/PluginManager.java | 6 +- .../search/internal/InternalSearchHits.java | 4 +- .../common/collect/IteratorsTests.java | 162 ++++++++++++++++++ .../gateway/MetaDataStateFormatTests.java | 6 +- .../Elasticsearch090RWPostingsFormat.java | 4 +- .../index/mapper/FieldTypeLookupTests.java | 22 ++- .../mapper/externalvalues/ExternalMapper.java | 2 +- .../test/CompositeTestCluster.java | 9 +- .../resources/forbidden/all-signatures.txt | 1 + 30 files changed, 312 insertions(+), 112 deletions(-) create mode 100644 core/src/main/java/org/elasticsearch/common/collect/Iterators.java create mode 100644 core/src/test/java/org/elasticsearch/common/collect/IteratorsTests.java diff --git a/core/src/main/java/org/elasticsearch/action/admin/indices/segments/IndexShardSegments.java b/core/src/main/java/org/elasticsearch/action/admin/indices/segments/IndexShardSegments.java index 4132c7b6b91..7cbb664958d 100644 --- a/core/src/main/java/org/elasticsearch/action/admin/indices/segments/IndexShardSegments.java +++ b/core/src/main/java/org/elasticsearch/action/admin/indices/segments/IndexShardSegments.java @@ -19,9 +19,9 @@ package org.elasticsearch.action.admin.indices.segments; -import com.google.common.collect.Iterators; import org.elasticsearch.index.shard.ShardId; +import java.util.Arrays; import java.util.Iterator; public class IndexShardSegments implements Iterable { @@ -49,6 +49,6 @@ public class IndexShardSegments implements Iterable { @Override public Iterator iterator() { - return Iterators.forArray(shards); + return Arrays.stream(shards).iterator(); } } \ No newline at end of file diff --git a/core/src/main/java/org/elasticsearch/action/admin/indices/stats/IndexShardStats.java b/core/src/main/java/org/elasticsearch/action/admin/indices/stats/IndexShardStats.java index e59946815d8..dd4cc640a3d 100644 --- a/core/src/main/java/org/elasticsearch/action/admin/indices/stats/IndexShardStats.java +++ b/core/src/main/java/org/elasticsearch/action/admin/indices/stats/IndexShardStats.java @@ -19,13 +19,13 @@ package org.elasticsearch.action.admin.indices.stats; -import com.google.common.collect.Iterators; import org.elasticsearch.common.io.stream.StreamInput; import org.elasticsearch.common.io.stream.StreamOutput; import org.elasticsearch.common.io.stream.Streamable; import org.elasticsearch.index.shard.ShardId; import java.io.IOException; +import java.util.Arrays; import java.util.Iterator; /** @@ -57,7 +57,7 @@ public class IndexShardStats implements Iterable, Streamable { @Override public Iterator iterator() { - return Iterators.forArray(shards); + return Arrays.stream(shards).iterator(); } private CommonStats total = null; diff --git a/core/src/main/java/org/elasticsearch/action/admin/indices/upgrade/get/IndexShardUpgradeStatus.java b/core/src/main/java/org/elasticsearch/action/admin/indices/upgrade/get/IndexShardUpgradeStatus.java index e1cd16370c3..c4b5820e28b 100644 --- a/core/src/main/java/org/elasticsearch/action/admin/indices/upgrade/get/IndexShardUpgradeStatus.java +++ b/core/src/main/java/org/elasticsearch/action/admin/indices/upgrade/get/IndexShardUpgradeStatus.java @@ -19,9 +19,9 @@ package org.elasticsearch.action.admin.indices.upgrade.get; -import com.google.common.collect.Iterators; import org.elasticsearch.index.shard.ShardId; +import java.util.Arrays; import java.util.Iterator; public class IndexShardUpgradeStatus implements Iterable { @@ -49,7 +49,7 @@ public class IndexShardUpgradeStatus implements Iterable { @Override public Iterator iterator() { - return Iterators.forArray(shards); + return Arrays.stream(shards).iterator(); } public long getTotalBytes() { diff --git a/core/src/main/java/org/elasticsearch/action/bulk/BulkResponse.java b/core/src/main/java/org/elasticsearch/action/bulk/BulkResponse.java index 50525fb050c..2076086a8a9 100644 --- a/core/src/main/java/org/elasticsearch/action/bulk/BulkResponse.java +++ b/core/src/main/java/org/elasticsearch/action/bulk/BulkResponse.java @@ -19,13 +19,13 @@ package org.elasticsearch.action.bulk; -import com.google.common.collect.Iterators; import org.elasticsearch.action.ActionResponse; import org.elasticsearch.common.io.stream.StreamInput; import org.elasticsearch.common.io.stream.StreamOutput; import org.elasticsearch.common.unit.TimeValue; import java.io.IOException; +import java.util.Arrays; import java.util.Iterator; /** @@ -95,7 +95,7 @@ public class BulkResponse extends ActionResponse implements Iterable iterator() { - return Iterators.forArray(responses); + return Arrays.stream(responses).iterator(); } @Override diff --git a/core/src/main/java/org/elasticsearch/action/get/MultiGetRequest.java b/core/src/main/java/org/elasticsearch/action/get/MultiGetRequest.java index 0d03bbbbf95..030b0ee5503 100644 --- a/core/src/main/java/org/elasticsearch/action/get/MultiGetRequest.java +++ b/core/src/main/java/org/elasticsearch/action/get/MultiGetRequest.java @@ -19,7 +19,6 @@ package org.elasticsearch.action.get; -import com.google.common.collect.Iterators; import org.elasticsearch.ElasticsearchParseException; import org.elasticsearch.action.*; import org.elasticsearch.action.support.IndicesOptions; @@ -27,6 +26,7 @@ import org.elasticsearch.common.Nullable; import org.elasticsearch.common.Strings; import org.elasticsearch.common.bytes.BytesArray; import org.elasticsearch.common.bytes.BytesReference; +import org.elasticsearch.common.collect.Iterators; import org.elasticsearch.common.io.stream.StreamInput; import org.elasticsearch.common.io.stream.StreamOutput; import org.elasticsearch.common.io.stream.Streamable; @@ -37,10 +37,7 @@ import org.elasticsearch.index.VersionType; import org.elasticsearch.search.fetch.source.FetchSourceContext; import java.io.IOException; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Iterator; -import java.util.List; +import java.util.*; public class MultiGetRequest extends ActionRequest implements Iterable, CompositeIndicesRequest, RealtimeRequest { @@ -498,7 +495,7 @@ public class MultiGetRequest extends ActionRequest implements I @Override public Iterator iterator() { - return Iterators.unmodifiableIterator(items.iterator()); + return Collections.unmodifiableCollection(items).iterator(); } @Override diff --git a/core/src/main/java/org/elasticsearch/action/get/MultiGetResponse.java b/core/src/main/java/org/elasticsearch/action/get/MultiGetResponse.java index 7abfb2b7d61..32e10b82de2 100644 --- a/core/src/main/java/org/elasticsearch/action/get/MultiGetResponse.java +++ b/core/src/main/java/org/elasticsearch/action/get/MultiGetResponse.java @@ -19,10 +19,8 @@ package org.elasticsearch.action.get; -import com.google.common.collect.Iterators; import org.elasticsearch.ElasticsearchException; import org.elasticsearch.action.ActionResponse; -import org.elasticsearch.action.percolate.PercolateResponse; import org.elasticsearch.common.io.stream.StreamInput; import org.elasticsearch.common.io.stream.StreamOutput; import org.elasticsearch.common.io.stream.Streamable; @@ -31,7 +29,7 @@ import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.common.xcontent.XContentBuilderString; import java.io.IOException; -import java.util.Collections; +import java.util.Arrays; import java.util.Iterator; public class MultiGetResponse extends ActionResponse implements Iterable, ToXContent { @@ -126,7 +124,7 @@ public class MultiGetResponse extends ActionResponse implements Iterable iterator() { - return Iterators.forArray(responses); + return Arrays.stream(responses).iterator(); } @Override diff --git a/core/src/main/java/org/elasticsearch/action/percolate/MultiPercolateResponse.java b/core/src/main/java/org/elasticsearch/action/percolate/MultiPercolateResponse.java index 4a32fc19061..812d525bce2 100644 --- a/core/src/main/java/org/elasticsearch/action/percolate/MultiPercolateResponse.java +++ b/core/src/main/java/org/elasticsearch/action/percolate/MultiPercolateResponse.java @@ -18,7 +18,6 @@ */ package org.elasticsearch.action.percolate; -import com.google.common.collect.Iterators; import org.elasticsearch.ElasticsearchException; import org.elasticsearch.action.ActionResponse; import org.elasticsearch.common.Nullable; @@ -30,6 +29,7 @@ import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.common.xcontent.XContentBuilderString; import java.io.IOException; +import java.util.Arrays; import java.util.Iterator; /** @@ -52,7 +52,7 @@ public class MultiPercolateResponse extends ActionResponse implements Iterable iterator() { - return Iterators.forArray(items); + return Arrays.stream(items).iterator(); } /** diff --git a/core/src/main/java/org/elasticsearch/action/search/MultiSearchResponse.java b/core/src/main/java/org/elasticsearch/action/search/MultiSearchResponse.java index 80745652be3..0a9d6191030 100644 --- a/core/src/main/java/org/elasticsearch/action/search/MultiSearchResponse.java +++ b/core/src/main/java/org/elasticsearch/action/search/MultiSearchResponse.java @@ -19,7 +19,6 @@ package org.elasticsearch.action.search; -import com.google.common.collect.Iterators; import org.elasticsearch.ElasticsearchException; import org.elasticsearch.action.ActionResponse; import org.elasticsearch.common.Nullable; @@ -32,7 +31,7 @@ import org.elasticsearch.common.xcontent.XContentBuilderString; import org.elasticsearch.common.xcontent.XContentFactory; import java.io.IOException; -import java.util.Collections; +import java.util.Arrays; import java.util.Iterator; /** @@ -122,7 +121,7 @@ public class MultiSearchResponse extends ActionResponse implements Iterable iterator() { - return Iterators.forArray(items); + return Arrays.stream(items).iterator(); } /** diff --git a/core/src/main/java/org/elasticsearch/action/termvectors/MultiTermVectorsRequest.java b/core/src/main/java/org/elasticsearch/action/termvectors/MultiTermVectorsRequest.java index c6db738386f..6d880a7b176 100644 --- a/core/src/main/java/org/elasticsearch/action/termvectors/MultiTermVectorsRequest.java +++ b/core/src/main/java/org/elasticsearch/action/termvectors/MultiTermVectorsRequest.java @@ -19,11 +19,11 @@ package org.elasticsearch.action.termvectors; -import com.google.common.collect.Iterators; import org.elasticsearch.ElasticsearchParseException; import org.elasticsearch.action.*; import org.elasticsearch.common.Nullable; import org.elasticsearch.common.bytes.BytesReference; +import org.elasticsearch.common.collect.Iterators; import org.elasticsearch.common.io.stream.StreamInput; import org.elasticsearch.common.io.stream.StreamOutput; import org.elasticsearch.common.xcontent.XContentFactory; @@ -74,7 +74,7 @@ public class MultiTermVectorsRequest extends ActionRequest iterator() { - return Iterators.unmodifiableIterator(requests.iterator()); + return Collections.unmodifiableCollection(requests).iterator(); } public boolean isEmpty() { diff --git a/core/src/main/java/org/elasticsearch/action/termvectors/MultiTermVectorsResponse.java b/core/src/main/java/org/elasticsearch/action/termvectors/MultiTermVectorsResponse.java index fe013d540d2..6eb3b3277e6 100644 --- a/core/src/main/java/org/elasticsearch/action/termvectors/MultiTermVectorsResponse.java +++ b/core/src/main/java/org/elasticsearch/action/termvectors/MultiTermVectorsResponse.java @@ -19,7 +19,6 @@ package org.elasticsearch.action.termvectors; -import com.google.common.collect.Iterators; import org.elasticsearch.ElasticsearchException; import org.elasticsearch.action.ActionResponse; import org.elasticsearch.common.io.stream.StreamInput; @@ -30,6 +29,7 @@ import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.common.xcontent.XContentBuilderString; import java.io.IOException; +import java.util.Arrays; import java.util.Iterator; public class MultiTermVectorsResponse extends ActionResponse implements Iterable, ToXContent { @@ -120,7 +120,7 @@ public class MultiTermVectorsResponse extends ActionResponse implements Iterable @Override public Iterator iterator() { - return Iterators.forArray(responses); + return Arrays.stream(responses).iterator(); } @Override diff --git a/core/src/main/java/org/elasticsearch/cluster/routing/RoutingNode.java b/core/src/main/java/org/elasticsearch/cluster/routing/RoutingNode.java index 43ad6aff1ec..596bb97887c 100644 --- a/core/src/main/java/org/elasticsearch/cluster/routing/RoutingNode.java +++ b/core/src/main/java/org/elasticsearch/cluster/routing/RoutingNode.java @@ -19,13 +19,10 @@ package org.elasticsearch.cluster.routing; -import com.google.common.collect.Iterators; import org.elasticsearch.cluster.node.DiscoveryNode; +import org.elasticsearch.common.collect.Iterators; -import java.util.ArrayList; -import java.util.Collection; -import java.util.Iterator; -import java.util.List; +import java.util.*; /** * A {@link RoutingNode} represents a cluster node associated with a single {@link DiscoveryNode} including all shards @@ -51,7 +48,7 @@ public class RoutingNode implements Iterable { @Override public Iterator iterator() { - return Iterators.unmodifiableIterator(shards.iterator()); + return Collections.unmodifiableCollection(shards).iterator(); } Iterator mutableIterator() { diff --git a/core/src/main/java/org/elasticsearch/cluster/routing/RoutingNodes.java b/core/src/main/java/org/elasticsearch/cluster/routing/RoutingNodes.java index 227d59f86cd..39c2d030e81 100644 --- a/core/src/main/java/org/elasticsearch/cluster/routing/RoutingNodes.java +++ b/core/src/main/java/org/elasticsearch/cluster/routing/RoutingNodes.java @@ -21,13 +21,13 @@ package org.elasticsearch.cluster.routing; import com.carrotsearch.hppc.ObjectIntHashMap; import com.carrotsearch.hppc.cursors.ObjectCursor; -import com.google.common.collect.Iterators; import org.apache.lucene.util.CollectionUtil; import org.elasticsearch.cluster.ClusterState; import org.elasticsearch.cluster.block.ClusterBlocks; import org.elasticsearch.cluster.metadata.MetaData; import org.elasticsearch.cluster.node.DiscoveryNode; import org.elasticsearch.common.collect.ImmutableOpenMap; +import org.elasticsearch.common.collect.Iterators; import org.elasticsearch.index.shard.ShardId; import java.util.*; @@ -144,7 +144,7 @@ public class RoutingNodes implements Iterable { @Override public Iterator iterator() { - return Iterators.unmodifiableIterator(nodesToShards.values().iterator()); + return Collections.unmodifiableCollection(nodesToShards.values()).iterator(); } public RoutingTable routingTable() { diff --git a/core/src/main/java/org/elasticsearch/common/collect/Iterators.java b/core/src/main/java/org/elasticsearch/common/collect/Iterators.java new file mode 100644 index 00000000000..34546120b0a --- /dev/null +++ b/core/src/main/java/org/elasticsearch/common/collect/Iterators.java @@ -0,0 +1,68 @@ +/* + * Licensed to Elasticsearch under one or more contributor + * license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright + * ownership. Elasticsearch licenses this file to you under + * the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.elasticsearch.common.collect; + +import java.util.Iterator; +import java.util.NoSuchElementException; + +public class Iterators { + public static Iterator concat(Iterator... iterators) { + if (iterators == null) { + throw new NullPointerException("iterators"); + } + + return new ConcatenatedIterator<>(iterators); + } + + static class ConcatenatedIterator implements Iterator { + private final Iterator[] iterators; + private int index = 0; + + public ConcatenatedIterator(Iterator... iterators) { + if (iterators == null) { + throw new NullPointerException("iterators"); + } + for (int i = 0; i < iterators.length; i++) { + if (iterators[i] == null) { + throw new NullPointerException("iterators[" + i + "]"); + } + } + this.iterators = iterators; + } + + @Override + public boolean hasNext() { + boolean hasNext = false; + while (index < iterators.length && !(hasNext = iterators[index].hasNext())) { + index++; + } + + return hasNext; + } + + @Override + public T next() { + if (!hasNext()) { + throw new NoSuchElementException(); + } + return iterators[index].next(); + } + } +} diff --git a/core/src/main/java/org/elasticsearch/common/io/FileSystemUtils.java b/core/src/main/java/org/elasticsearch/common/io/FileSystemUtils.java index cb5ca5fec64..e53e7a73eb7 100644 --- a/core/src/main/java/org/elasticsearch/common/io/FileSystemUtils.java +++ b/core/src/main/java/org/elasticsearch/common/io/FileSystemUtils.java @@ -19,9 +19,8 @@ package org.elasticsearch.common.io; -import com.google.common.collect.Iterators; - import org.apache.lucene.util.IOUtils; +import org.elasticsearch.common.collect.Iterators; import org.elasticsearch.common.logging.ESLogger; import java.io.BufferedReader; @@ -35,6 +34,7 @@ import java.nio.file.*; import java.nio.file.attribute.BasicFileAttributes; import java.util.Arrays; import java.util.concurrent.atomic.AtomicBoolean; +import java.util.stream.StreamSupport; import static java.nio.file.FileVisitResult.CONTINUE; import static java.nio.file.FileVisitResult.SKIP_SUBTREE; @@ -328,7 +328,7 @@ public final class FileSystemUtils { */ public static Path[] files(Path from, DirectoryStream.Filter filter) throws IOException { try (DirectoryStream stream = Files.newDirectoryStream(from, filter)) { - return Iterators.toArray(stream.iterator(), Path.class); + return toArray(stream); } } @@ -337,7 +337,7 @@ public final class FileSystemUtils { */ public static Path[] files(Path directory) throws IOException { try (DirectoryStream stream = Files.newDirectoryStream(directory)) { - return Iterators.toArray(stream.iterator(), Path.class); + return toArray(stream); } } @@ -346,8 +346,12 @@ public final class FileSystemUtils { */ public static Path[] files(Path directory, String glob) throws IOException { try (DirectoryStream stream = Files.newDirectoryStream(directory, glob)) { - return Iterators.toArray(stream.iterator(), Path.class); + return toArray(stream); } } + private static Path[] toArray(DirectoryStream stream) { + return StreamSupport.stream(stream.spliterator(), false).toArray(length -> new Path[length]); + } + } diff --git a/core/src/main/java/org/elasticsearch/common/util/CollectionUtils.java b/core/src/main/java/org/elasticsearch/common/util/CollectionUtils.java index e4a074b3961..fd0f64d7798 100644 --- a/core/src/main/java/org/elasticsearch/common/util/CollectionUtils.java +++ b/core/src/main/java/org/elasticsearch/common/util/CollectionUtils.java @@ -23,15 +23,12 @@ import com.carrotsearch.hppc.DoubleArrayList; import com.carrotsearch.hppc.FloatArrayList; import com.carrotsearch.hppc.LongArrayList; import com.carrotsearch.hppc.ObjectArrayList; -import com.google.common.collect.Iterators; import org.apache.lucene.util.*; import java.util.*; /** Collections-related utility methods. */ -public enum CollectionUtils { - CollectionUtils; - +public class CollectionUtils { public static void sort(LongArrayList list) { sort(list.buffer, list.size()); } @@ -366,13 +363,6 @@ public enum CollectionUtils { } - /** - * Combines multiple iterators into a single iterator. - */ - public static Iterator concat(Iterator... iterators) { - return Iterators.concat(iterators); - } - public static ArrayList iterableAsArrayList(Iterable elements) { if (elements == null) { throw new NullPointerException("elements"); diff --git a/core/src/main/java/org/elasticsearch/index/codec/postingsformat/Elasticsearch090PostingsFormat.java b/core/src/main/java/org/elasticsearch/index/codec/postingsformat/Elasticsearch090PostingsFormat.java index b6ceba8fb8a..f7926c77882 100644 --- a/core/src/main/java/org/elasticsearch/index/codec/postingsformat/Elasticsearch090PostingsFormat.java +++ b/core/src/main/java/org/elasticsearch/index/codec/postingsformat/Elasticsearch090PostingsFormat.java @@ -18,22 +18,17 @@ */ package org.elasticsearch.index.codec.postingsformat; -import com.google.common.collect.Iterators; import org.apache.lucene.codecs.FieldsConsumer; import org.apache.lucene.codecs.FieldsProducer; import org.apache.lucene.codecs.PostingsFormat; import org.apache.lucene.codecs.lucene50.Lucene50PostingsFormat; -import org.apache.lucene.index.Fields; -import org.apache.lucene.index.FilterLeafReader; import org.apache.lucene.index.SegmentReadState; import org.apache.lucene.index.SegmentWriteState; import org.elasticsearch.common.lucene.Lucene; import org.elasticsearch.common.util.BloomFilter; -import org.elasticsearch.index.codec.postingsformat.BloomFilterPostingsFormat.BloomFilteredFieldsConsumer; import org.elasticsearch.index.mapper.internal.UidFieldMapper; import java.io.IOException; -import java.util.Iterator; import java.util.function.Predicate; /** 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 cbccaa1959a..7d3882fd9b6 100644 --- a/core/src/main/java/org/elasticsearch/index/engine/Segment.java +++ b/core/src/main/java/org/elasticsearch/index/engine/Segment.java @@ -19,7 +19,6 @@ package org.elasticsearch.index.engine; -import com.google.common.collect.Iterators; import org.apache.lucene.util.Accountable; import org.apache.lucene.util.Accountables; import org.elasticsearch.common.Nullable; @@ -32,7 +31,6 @@ import org.elasticsearch.common.unit.ByteSizeValue; import java.io.IOException; import java.util.ArrayList; import java.util.Collection; -import java.util.Iterator; import java.util.List; public class Segment implements Streamable { diff --git a/core/src/main/java/org/elasticsearch/index/mapper/MapperService.java b/core/src/main/java/org/elasticsearch/index/mapper/MapperService.java index dd31c6e60be..c205e636b45 100755 --- a/core/src/main/java/org/elasticsearch/index/mapper/MapperService.java +++ b/core/src/main/java/org/elasticsearch/index/mapper/MapperService.java @@ -21,7 +21,6 @@ package org.elasticsearch.index.mapper; import com.carrotsearch.hppc.ObjectHashSet; import com.google.common.collect.ImmutableMap; -import com.google.common.collect.Iterators; import org.apache.lucene.analysis.Analyzer; import org.apache.lucene.analysis.DelegatingAnalyzerWrapper; @@ -39,6 +38,7 @@ import org.elasticsearch.ElasticsearchGenerationException; import org.elasticsearch.Version; import org.elasticsearch.common.Nullable; import org.elasticsearch.common.collect.ImmutableOpenMap; +import org.elasticsearch.common.collect.Iterators; import org.elasticsearch.common.compress.CompressedXContent; import org.elasticsearch.common.inject.Inject; import org.elasticsearch.common.lucene.search.Queries; @@ -72,6 +72,7 @@ import java.util.Set; import java.util.concurrent.CopyOnWriteArrayList; import java.util.concurrent.locks.ReentrantReadWriteLock; import java.util.function.Function; +import java.util.stream.Collectors; import static java.util.Collections.emptySet; import static java.util.Collections.unmodifiableSet; @@ -184,13 +185,13 @@ public class MapperService extends AbstractIndexComponent implements Closeable { */ public Iterable docMappers(final boolean includingDefaultMapping) { return () -> { - final Iterator iterator; + final Collection documentMappers; if (includingDefaultMapping) { - iterator = mappers.values().iterator(); + documentMappers = mappers.values(); } else { - iterator = mappers.values().stream().filter(mapper -> !DEFAULT_MAPPING.equals(mapper.type())).iterator(); + documentMappers = mappers.values().stream().filter(mapper -> !DEFAULT_MAPPING.equals(mapper.type())).collect(Collectors.toList()); } - return Iterators.unmodifiableIterator(iterator); + return Collections.unmodifiableCollection(documentMappers).iterator(); }; } diff --git a/core/src/main/java/org/elasticsearch/index/mapper/geo/GeoPointFieldMapper.java b/core/src/main/java/org/elasticsearch/index/mapper/geo/GeoPointFieldMapper.java index 4111786009e..b264bfa4bc3 100644 --- a/core/src/main/java/org/elasticsearch/index/mapper/geo/GeoPointFieldMapper.java +++ b/core/src/main/java/org/elasticsearch/index/mapper/geo/GeoPointFieldMapper.java @@ -21,7 +21,6 @@ package org.elasticsearch.index.mapper.geo; import com.carrotsearch.hppc.ObjectHashSet; import com.carrotsearch.hppc.cursors.ObjectCursor; -import com.google.common.collect.Iterators; import org.apache.lucene.document.Field; import org.apache.lucene.index.IndexOptions; import org.apache.lucene.util.BytesRef; @@ -30,6 +29,7 @@ import org.apache.lucene.util.XGeoHashUtils; import org.elasticsearch.Version; import org.elasticsearch.common.Explicit; import org.elasticsearch.common.Strings; +import org.elasticsearch.common.collect.Iterators; import org.elasticsearch.common.geo.GeoDistance; import org.elasticsearch.common.geo.GeoPoint; import org.elasticsearch.common.geo.GeoUtils; @@ -39,14 +39,7 @@ import org.elasticsearch.common.util.ByteUtils; import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.common.xcontent.XContentParser; import org.elasticsearch.common.xcontent.support.XContentMapValues; -import org.elasticsearch.index.mapper.ContentPath; -import org.elasticsearch.index.mapper.FieldMapper; -import org.elasticsearch.index.mapper.MappedFieldType; -import org.elasticsearch.index.mapper.Mapper; -import org.elasticsearch.index.mapper.MapperParsingException; -import org.elasticsearch.index.mapper.MergeMappingException; -import org.elasticsearch.index.mapper.MergeResult; -import org.elasticsearch.index.mapper.ParseContext; +import org.elasticsearch.index.mapper.*; import org.elasticsearch.index.mapper.core.DoubleFieldMapper; import org.elasticsearch.index.mapper.core.NumberFieldMapper; import org.elasticsearch.index.mapper.core.NumberFieldMapper.CustomNumericDocValuesField; @@ -54,18 +47,10 @@ import org.elasticsearch.index.mapper.core.StringFieldMapper; import org.elasticsearch.index.mapper.object.ArrayValueMapperParser; import java.io.IOException; -import java.util.ArrayList; -import java.util.Iterator; -import java.util.List; -import java.util.Locale; -import java.util.Map; +import java.util.*; -import static org.elasticsearch.index.mapper.MapperBuilders.doubleField; -import static org.elasticsearch.index.mapper.MapperBuilders.geoPointField; -import static org.elasticsearch.index.mapper.MapperBuilders.stringField; -import static org.elasticsearch.index.mapper.core.TypeParsers.parseField; -import static org.elasticsearch.index.mapper.core.TypeParsers.parseMultiField; -import static org.elasticsearch.index.mapper.core.TypeParsers.parsePathType; +import static org.elasticsearch.index.mapper.MapperBuilders.*; +import static org.elasticsearch.index.mapper.core.TypeParsers.*; /** * Parsing: We handle: diff --git a/core/src/main/java/org/elasticsearch/monitor/fs/FsInfo.java b/core/src/main/java/org/elasticsearch/monitor/fs/FsInfo.java index 6fcbec5ee90..b97457af706 100644 --- a/core/src/main/java/org/elasticsearch/monitor/fs/FsInfo.java +++ b/core/src/main/java/org/elasticsearch/monitor/fs/FsInfo.java @@ -19,7 +19,6 @@ package org.elasticsearch.monitor.fs; -import com.google.common.collect.Iterators; import org.elasticsearch.common.Nullable; import org.elasticsearch.common.io.stream.StreamInput; import org.elasticsearch.common.io.stream.StreamOutput; @@ -30,6 +29,7 @@ import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.common.xcontent.XContentBuilderString; import java.io.IOException; +import java.util.Arrays; import java.util.HashSet; import java.util.Iterator; import java.util.Set; @@ -235,7 +235,7 @@ public class FsInfo implements Iterable, Streamable, ToXContent { @Override public Iterator iterator() { - return Iterators.forArray(paths); + return Arrays.stream(paths).iterator(); } public static FsInfo readFsInfo(StreamInput in) throws IOException { diff --git a/core/src/main/java/org/elasticsearch/monitor/jvm/JvmStats.java b/core/src/main/java/org/elasticsearch/monitor/jvm/JvmStats.java index d2194888dbd..c695e265ac5 100644 --- a/core/src/main/java/org/elasticsearch/monitor/jvm/JvmStats.java +++ b/core/src/main/java/org/elasticsearch/monitor/jvm/JvmStats.java @@ -19,7 +19,6 @@ package org.elasticsearch.monitor.jvm; -import com.google.common.collect.Iterators; import org.elasticsearch.common.io.stream.StreamInput; import org.elasticsearch.common.io.stream.StreamOutput; import org.elasticsearch.common.io.stream.Streamable; @@ -32,6 +31,7 @@ import org.elasticsearch.common.xcontent.XContentBuilderString; import java.io.IOException; import java.lang.management.*; import java.util.ArrayList; +import java.util.Arrays; import java.util.Iterator; import java.util.List; import java.util.concurrent.TimeUnit; @@ -378,7 +378,7 @@ public class JvmStats implements Streamable, ToXContent { @Override public Iterator iterator() { - return Iterators.forArray(collectors); + return Arrays.stream(collectors).iterator(); } } @@ -546,7 +546,7 @@ public class JvmStats implements Streamable, ToXContent { @Override public Iterator iterator() { - return Iterators.forArray(pools); + return Arrays.stream(pools).iterator(); } @Override diff --git a/core/src/main/java/org/elasticsearch/plugins/PluginManager.java b/core/src/main/java/org/elasticsearch/plugins/PluginManager.java index 9e7a6fcb703..01e8e9200e9 100644 --- a/core/src/main/java/org/elasticsearch/plugins/PluginManager.java +++ b/core/src/main/java/org/elasticsearch/plugins/PluginManager.java @@ -19,8 +19,6 @@ package org.elasticsearch.plugins; -import com.google.common.collect.Iterators; - import org.apache.lucene.util.IOUtils; import org.elasticsearch.Build; import org.elasticsearch.ElasticsearchCorruptionException; @@ -30,6 +28,7 @@ import org.elasticsearch.Version; import org.elasticsearch.bootstrap.JarHell; import org.elasticsearch.common.Strings; import org.elasticsearch.common.cli.Terminal; +import org.elasticsearch.common.collect.Iterators; import org.elasticsearch.common.collect.Tuple; import org.elasticsearch.common.http.client.HttpDownloadHelper; import org.elasticsearch.common.io.FileSystemUtils; @@ -56,6 +55,7 @@ import java.util.List; import java.util.Locale; import java.util.Random; import java.util.Set; +import java.util.stream.StreamSupport; import java.util.zip.ZipEntry; import java.util.zip.ZipInputStream; @@ -437,7 +437,7 @@ public class PluginManager { } try (DirectoryStream stream = Files.newDirectoryStream(environment.pluginsFile())) { - return Iterators.toArray(stream.iterator(), Path.class); + return StreamSupport.stream(stream.spliterator(), false).toArray(length -> new Path[length]); } } diff --git a/core/src/main/java/org/elasticsearch/search/internal/InternalSearchHits.java b/core/src/main/java/org/elasticsearch/search/internal/InternalSearchHits.java index 393b7b6ad8c..9e787cf2aa9 100644 --- a/core/src/main/java/org/elasticsearch/search/internal/InternalSearchHits.java +++ b/core/src/main/java/org/elasticsearch/search/internal/InternalSearchHits.java @@ -20,7 +20,6 @@ package org.elasticsearch.search.internal; import com.carrotsearch.hppc.IntObjectHashMap; -import com.google.common.collect.Iterators; import org.elasticsearch.common.io.stream.StreamInput; import org.elasticsearch.common.io.stream.StreamOutput; import org.elasticsearch.common.xcontent.XContentBuilder; @@ -30,6 +29,7 @@ import org.elasticsearch.search.SearchHits; import org.elasticsearch.search.SearchShardTarget; import java.io.IOException; +import java.util.Arrays; import java.util.IdentityHashMap; import java.util.Iterator; import java.util.Map; @@ -156,7 +156,7 @@ public class InternalSearchHits implements SearchHits { @Override public Iterator iterator() { - return Iterators.forArray(hits()); + return Arrays.stream(hits()).iterator(); } public InternalSearchHit[] internalHits() { diff --git a/core/src/test/java/org/elasticsearch/common/collect/IteratorsTests.java b/core/src/test/java/org/elasticsearch/common/collect/IteratorsTests.java new file mode 100644 index 00000000000..90972185e0b --- /dev/null +++ b/core/src/test/java/org/elasticsearch/common/collect/IteratorsTests.java @@ -0,0 +1,162 @@ +/* + * Licensed to Elasticsearch under one or more contributor + * license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright + * ownership. Elasticsearch licenses this file to you under + * the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.elasticsearch.common.collect; + +import org.elasticsearch.test.ESTestCase; + +import java.util.*; + +public class IteratorsTests extends ESTestCase { + public void testConcatentation() { + List threeTwoOne = Arrays.asList(3, 2, 1); + List fourFiveSix = Arrays.asList(4, 5, 6); + Iterator concat = Iterators.concat(threeTwoOne.iterator(), fourFiveSix.iterator()); + assertContainsInOrder(concat, 3, 2, 1, 4, 5, 6); + } + + public void testNoConcatenation() { + Iterator iterator = Iterators.concat(); + assertEmptyIterator(iterator); + } + + public void testEmptyConcatenation() { + Iterator iterator = Iterators.concat(empty()); + assertEmptyIterator(iterator); + } + + public void testMultipleEmptyConcatenation() { + Iterator iterator = Iterators.concat(empty(), empty()); + assertEmptyIterator(iterator); + } + + public void testSingleton() { + int value = randomInt(); + assertSingleton(value, singletonIterator(value)); + } + + public void testEmptyBeforeSingleton() { + int value = randomInt(); + assertSingleton(value, empty(), singletonIterator(value)); + } + + + public void testEmptyAfterSingleton() { + int value = randomInt(); + assertSingleton(value, singletonIterator(value), empty()); + } + + public void testRandomSingleton() { + int numberOfIterators = randomIntBetween(1, 1000); + int singletonIndex = randomIntBetween(0, numberOfIterators - 1); + int value = randomInt(); + Iterator[] iterators = new Iterator[numberOfIterators]; + for (int i = 0; i < numberOfIterators; i++) { + iterators[i] = i != singletonIndex ? empty() : singletonIterator(value); + } + assertSingleton(value, iterators); + } + + public void testRandomIterators() { + int numberOfIterators = randomIntBetween(1, 1000); + Iterator[] iterators = new Iterator[numberOfIterators]; + List values = new ArrayList<>(); + for (int i = 0; i < numberOfIterators; i++) { + int numberOfValues = randomIntBetween(0, 256); + List theseValues = new ArrayList<>(); + for (int j = 0; j < numberOfValues; j++) { + int value = randomInt(); + values.add(value); + theseValues.add(value); + } + iterators[i] = theseValues.iterator(); + } + assertContainsInOrder(Iterators.concat(iterators), values.toArray(new Integer[values.size()])); + } + + public void testTwoEntries() { + int first = randomInt(); + int second = randomInt(); + Iterator concat = Iterators.concat(singletonIterator(first), empty(), empty(), singletonIterator(second)); + assertContainsInOrder(concat, first, second); + } + + public void testNull() { + try { + Iterators.concat((Iterator)null); + fail("expected " + NullPointerException.class.getSimpleName()); + } catch (NullPointerException e) { + + } + } + + public void testNullIterator() { + try { + Iterators.concat(singletonIterator(1), empty(), null, empty(), singletonIterator(2)); + fail("expected " + NullPointerException.class.getSimpleName()); + } catch (NullPointerException e) { + + } + } + + private Iterator singletonIterator(T value) { + return Collections.singleton(value).iterator(); + } + + private void assertSingleton(T value, Iterator... iterators) { + Iterator concat = Iterators.concat(iterators); + assertContainsInOrder(concat, value); + } + + private Iterator empty() { + return new Iterator() { + @Override + public boolean hasNext() { + return false; + } + + @Override + public T next() { + throw new NoSuchElementException(); + } + }; + } + + private void assertContainsInOrder(Iterator iterator, T... values) { + for (T value : values) { + assertTrue(iterator.hasNext()); + assertEquals(value, iterator.next()); + } + assertNoSuchElementException(iterator); + } + + private void assertEmptyIterator(Iterator iterator) { + assertFalse(iterator.hasNext()); + assertNoSuchElementException(iterator); + } + + private void assertNoSuchElementException(Iterator iterator) { + try { + iterator.next(); + fail("expected " + NoSuchElementException.class.getSimpleName()); + } catch (NoSuchElementException e) { + + } + } +} diff --git a/core/src/test/java/org/elasticsearch/gateway/MetaDataStateFormatTests.java b/core/src/test/java/org/elasticsearch/gateway/MetaDataStateFormatTests.java index 98630edd176..1d51c308869 100644 --- a/core/src/test/java/org/elasticsearch/gateway/MetaDataStateFormatTests.java +++ b/core/src/test/java/org/elasticsearch/gateway/MetaDataStateFormatTests.java @@ -18,8 +18,6 @@ */ package org.elasticsearch.gateway; -import com.google.common.collect.Iterators; - import org.apache.lucene.codecs.CodecUtil; import org.apache.lucene.store.ChecksumIndexInput; import org.apache.lucene.store.Directory; @@ -33,6 +31,7 @@ import org.elasticsearch.Version; import org.elasticsearch.cluster.metadata.IndexMetaData; import org.elasticsearch.cluster.metadata.MetaData; import org.elasticsearch.common.collect.ImmutableOpenMap; +import org.elasticsearch.common.collect.Iterators; import org.elasticsearch.common.io.FileSystemUtils; import org.elasticsearch.common.logging.ESLogger; import org.elasticsearch.common.xcontent.ToXContent; @@ -59,6 +58,7 @@ import java.util.Collections; import java.util.HashSet; import java.util.List; import java.util.Set; +import java.util.stream.StreamSupport; import static org.hamcrest.Matchers.equalTo; import static org.hamcrest.Matchers.instanceOf; @@ -535,7 +535,7 @@ public class MetaDataStateFormatTests extends ESTestCase { public Path[] content(String glob, Path dir) throws IOException { try (DirectoryStream stream = Files.newDirectoryStream(dir, glob)) { - return Iterators.toArray(stream.iterator(), Path.class); + return StreamSupport.stream(stream.spliterator(), false).toArray(length -> new Path[length]); } } diff --git a/core/src/test/java/org/elasticsearch/index/codec/postingformat/Elasticsearch090RWPostingsFormat.java b/core/src/test/java/org/elasticsearch/index/codec/postingformat/Elasticsearch090RWPostingsFormat.java index a4285e6f81e..984e151a5e8 100644 --- a/core/src/test/java/org/elasticsearch/index/codec/postingformat/Elasticsearch090RWPostingsFormat.java +++ b/core/src/test/java/org/elasticsearch/index/codec/postingformat/Elasticsearch090RWPostingsFormat.java @@ -19,7 +19,6 @@ package org.elasticsearch.index.codec.postingformat; -import com.google.common.collect.Iterators; import org.apache.lucene.codecs.FieldsConsumer; import org.apache.lucene.codecs.PostingsFormat; import org.apache.lucene.index.Fields; @@ -32,6 +31,7 @@ import org.elasticsearch.index.codec.postingsformat.Elasticsearch090PostingsForm import org.elasticsearch.index.mapper.internal.UidFieldMapper; import java.io.IOException; +import java.util.Collections; import java.util.Iterator; import java.util.stream.StreamSupport; @@ -61,7 +61,7 @@ public class Elasticsearch090RWPostingsFormat extends Elasticsearch090PostingsFo maskedFields = new FilterLeafReader.FilterFields(fields) { @Override public Iterator iterator() { - return Iterators.singletonIterator(UidFieldMapper.NAME); + return Collections.singleton(UidFieldMapper.NAME).iterator(); } }; // only go through bloom for the UID field diff --git a/core/src/test/java/org/elasticsearch/index/mapper/FieldTypeLookupTests.java b/core/src/test/java/org/elasticsearch/index/mapper/FieldTypeLookupTests.java index 5e3b61a7da1..6ab4ca38d40 100644 --- a/core/src/test/java/org/elasticsearch/index/mapper/FieldTypeLookupTests.java +++ b/core/src/test/java/org/elasticsearch/index/mapper/FieldTypeLookupTests.java @@ -19,7 +19,6 @@ package org.elasticsearch.index.mapper; -import com.google.common.collect.Iterators; import org.elasticsearch.Version; import org.elasticsearch.cluster.metadata.IndexMetaData; import org.elasticsearch.common.settings.Settings; @@ -30,7 +29,6 @@ import java.util.Arrays; import java.util.Collection; import java.util.Iterator; import java.util.List; -import java.util.stream.StreamSupport; public class FieldTypeLookupTests extends ESTestCase { @@ -61,7 +59,7 @@ public class FieldTypeLookupTests extends ESTestCase { assertNull(lookup.get("bar")); assertEquals(f.fieldType(), lookup2.getByIndexName("bar")); assertNull(lookup.getByIndexName("foo")); - assertEquals(1, Iterators.size(lookup2.iterator())); + assertEquals(1, size(lookup2.iterator())); } public void testAddExistingField() { @@ -76,7 +74,7 @@ public class FieldTypeLookupTests extends ESTestCase { assertSame(f.fieldType(), f2.fieldType()); assertSame(f.fieldType(), lookup2.get("foo")); assertSame(f.fieldType(), lookup2.getByIndexName("foo")); - assertEquals(1, Iterators.size(lookup2.iterator())); + assertEquals(1, size(lookup2.iterator())); } public void testAddExistingIndexName() { @@ -92,7 +90,7 @@ public class FieldTypeLookupTests extends ESTestCase { assertSame(f.fieldType(), lookup2.get("foo")); assertSame(f.fieldType(), lookup2.get("bar")); assertSame(f.fieldType(), lookup2.getByIndexName("foo")); - assertEquals(2, Iterators.size(lookup2.iterator())); + assertEquals(2, size(lookup2.iterator())); } public void testAddExistingFullName() { @@ -108,7 +106,7 @@ public class FieldTypeLookupTests extends ESTestCase { assertSame(f.fieldType(), lookup2.get("foo")); assertSame(f.fieldType(), lookup2.getByIndexName("foo")); assertSame(f.fieldType(), lookup2.getByIndexName("bar")); - assertEquals(1, Iterators.size(lookup2.iterator())); + assertEquals(1, size(lookup2.iterator())); } public void testAddExistingBridgeName() { @@ -286,4 +284,16 @@ public class FieldTypeLookupTests extends ESTestCase { @Override protected void parseCreateField(ParseContext context, List list) throws IOException {} } + + private int size(Iterator iterator) { + if (iterator == null) { + throw new NullPointerException("iterator"); + } + int count = 0; + while (iterator.hasNext()) { + count++; + iterator.next(); + } + return count; + } } diff --git a/core/src/test/java/org/elasticsearch/index/mapper/externalvalues/ExternalMapper.java b/core/src/test/java/org/elasticsearch/index/mapper/externalvalues/ExternalMapper.java index e0c7a30673a..3d2134f3664 100755 --- a/core/src/test/java/org/elasticsearch/index/mapper/externalvalues/ExternalMapper.java +++ b/core/src/test/java/org/elasticsearch/index/mapper/externalvalues/ExternalMapper.java @@ -19,10 +19,10 @@ package org.elasticsearch.index.mapper.externalvalues; -import com.google.common.collect.Iterators; import com.spatial4j.core.shape.Point; import org.apache.lucene.document.Field; import org.elasticsearch.common.Strings; +import org.elasticsearch.common.collect.Iterators; import org.elasticsearch.common.geo.GeoPoint; import org.elasticsearch.common.geo.builders.ShapeBuilder; import org.elasticsearch.common.settings.Settings; diff --git a/core/src/test/java/org/elasticsearch/test/CompositeTestCluster.java b/core/src/test/java/org/elasticsearch/test/CompositeTestCluster.java index 843fc2e1abd..8b14ef06b06 100644 --- a/core/src/test/java/org/elasticsearch/test/CompositeTestCluster.java +++ b/core/src/test/java/org/elasticsearch/test/CompositeTestCluster.java @@ -19,7 +19,6 @@ package org.elasticsearch.test; import com.carrotsearch.randomizedtesting.generators.RandomPicks; -import com.google.common.collect.Iterators; import org.apache.lucene.util.IOUtils; import org.elasticsearch.action.admin.cluster.node.stats.NodeStats; import org.elasticsearch.action.admin.cluster.node.stats.NodesStatsResponse; @@ -31,11 +30,7 @@ import org.elasticsearch.common.transport.TransportAddress; import java.io.IOException; import java.net.InetSocketAddress; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collection; -import java.util.Iterator; -import java.util.Random; +import java.util.*; import java.util.stream.Collectors; import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertNoTimeout; @@ -247,7 +242,7 @@ public class CompositeTestCluster extends TestCluster { @Override public synchronized Iterator iterator() { - return Iterators.singletonIterator(client()); + return Collections.singleton(client()).iterator(); } /** diff --git a/dev-tools/src/main/resources/forbidden/all-signatures.txt b/dev-tools/src/main/resources/forbidden/all-signatures.txt index e57a86227cd..114d7b4e304 100644 --- a/dev-tools/src/main/resources/forbidden/all-signatures.txt +++ b/dev-tools/src/main/resources/forbidden/all-signatures.txt @@ -133,6 +133,7 @@ com.google.common.io.Resources com.google.common.hash.HashCode com.google.common.hash.HashFunction com.google.common.hash.Hashing +com.google.common.collect.Iterators @defaultMessage Do not violate java's access system java.lang.reflect.AccessibleObject#setAccessible(boolean)