Skip to content

Commit c65f9eb

Browse files
committed
2 parents 6724043 + c328c18 commit c65f9eb

File tree

297 files changed

+17547
-2693
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

297 files changed

+17547
-2693
lines changed

.ci/bwcVersions

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,3 +32,4 @@ BWC_VERSION:
3232
- "2.13.0"
3333
- "2.13.1"
3434
- "2.14.0"
35+
- "2.15.0"

.github/pull_request_template.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ Resolves #[Issue number to be closed when this PR is merged]
1717
- [ ] All tests pass
1818
- [ ] New functionality has been documented.
1919
- [ ] New functionality has javadoc added
20+
- [ ] API changes companion pull request [created](https://github.com/opensearch-project/opensearch-api-specification/blob/main/DEVELOPER_GUIDE.md).
2021
- [ ] Failing checks are inspected and point to the corresponding known issue(s) (See: [Troubleshooting Failing Builds](../blob/main/CONTRIBUTING.md#troubleshooting-failing-builds))
2122
- [ ] Commits are signed per the DCO using --signoff
2223
- [ ] Commit changes are listed out in CHANGELOG.md file (See: [Changelog](../blob/main/CONTRIBUTING.md#changelog))

.github/workflows/assemble.yml

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ jobs:
88
strategy:
99
matrix:
1010
java: [ 11, 17, 21 ]
11-
os: [ubuntu-latest, windows-latest, macos-latest]
11+
os: [ubuntu-latest, windows-latest, macos-13]
1212
steps:
1313
- uses: actions/checkout@v4
1414
- name: Set up JDK ${{ matrix.java }}
@@ -18,10 +18,7 @@ jobs:
1818
distribution: temurin
1919
- name: Setup docker (missing on MacOS)
2020
if: runner.os == 'macos'
21-
run: |
22-
brew install docker
23-
colima start
24-
sudo ln -sf $HOME/.colima/default/docker.sock /var/run/docker.sock
21+
uses: douglascamata/setup-docker-macos-action@main
2522
- name: Run Gradle (assemble)
2623
run: |
2724
./gradlew assemble --parallel --no-build-cache -PDISABLE_BUILD_CACHE

.github/workflows/links.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ jobs:
1313
- uses: actions/checkout@v4
1414
- name: lychee Link Checker
1515
id: lychee
16-
uses: lycheeverse/lychee-action@v1.9.3
16+
uses: lycheeverse/lychee-action@v1.10.0
1717
with:
1818
args: --accept=200,403,429 --exclude-mail **/*.html **/*.md **/*.txt **/*.json --exclude-file .lychee.excludes
1919
fail: true

.github/workflows/precommit.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ jobs:
88
strategy:
99
matrix:
1010
java: [ 11, 17, 21 ]
11-
os: [ubuntu-latest, windows-latest, macos-latest]
11+
os: [ubuntu-latest, windows-latest, macos-13]
1212
steps:
1313
- uses: actions/checkout@v4
1414
- name: Set up JDK ${{ matrix.java }}

CHANGELOG.md

Lines changed: 9 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -5,61 +5,26 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
55

66
## [Unreleased 2.x]
77
### Added
8-
- Constant Keyword Field ([#12285](https://github.com/opensearch-project/OpenSearch/pull/12285))
9-
- Convert ingest processor supports ip type ([#12818](https://github.com/opensearch-project/OpenSearch/pull/12818))
10-
- Add a counter to node stat api to track shard going from idle to non-idle ([#12768](https://github.com/opensearch-project/OpenSearch/pull/12768))
11-
- Allow setting KEYSTORE_PASSWORD through env variable ([#12865](https://github.com/opensearch-project/OpenSearch/pull/12865))
12-
- [Concurrent Segment Search] Perform buildAggregation concurrently and support Composite Aggregations ([#12697](https://github.com/opensearch-project/OpenSearch/pull/12697))
13-
- [Concurrent Segment Search] Disable concurrent segment search for system indices and throttled requests ([#12954](https://github.com/opensearch-project/OpenSearch/pull/12954))
14-
- [Tiered Caching] Make took time caching policy setting dynamic ([#13063](https://github.com/opensearch-project/OpenSearch/pull/13063))
15-
- Derived fields support to derive field values at query time without indexing ([#12569](https://github.com/opensearch-project/OpenSearch/pull/12569))
16-
- Detect breaking changes on pull requests ([#9044](https://github.com/opensearch-project/OpenSearch/pull/9044))
17-
- Add cluster primary balance contraint for rebalancing with buffer ([#12656](https://github.com/opensearch-project/OpenSearch/pull/12656))
18-
- [Remote Store] Make translog transfer timeout configurable ([#12704](https://github.com/opensearch-project/OpenSearch/pull/12704))
19-
- Reject Resize index requests (i.e, split, shrink and clone), While DocRep to SegRep migration is in progress.([#12686](https://github.com/opensearch-project/OpenSearch/pull/12686))
20-
- Add support for more than one protocol for transport ([#12967](https://github.com/opensearch-project/OpenSearch/pull/12967))
21-
- [Tiered Caching] Add dimension-based stats to ICache implementations. ([#12531](https://github.com/opensearch-project/OpenSearch/pull/12531))
22-
- Add changes for overriding remote store and replication settings during snapshot restore. ([#11868](https://github.com/opensearch-project/OpenSearch/pull/11868))
23-
- Add an individual setting of rate limiter for segment replication ([#12959](https://github.com/opensearch-project/OpenSearch/pull/12959))
24-
- [Streaming Indexing] Ensure support of the new transport by security plugin ([#13174](https://github.com/opensearch-project/OpenSearch/pull/13174))
25-
- Add cluster setting to dynamically configure the buckets for filter rewrite optimization. ([#13179](https://github.com/opensearch-project/OpenSearch/pull/13179))
8+
- Add useCompoundFile index setting ([#13478](https://github.com/opensearch-project/OpenSearch/pull/13478))
269

2710
### Dependencies
28-
- Bump `org.apache.commons:commons-configuration2` from 2.10.0 to 2.10.1 ([#12896](https://github.com/opensearch-project/OpenSearch/pull/12896))
29-
- Bump `asm` from 9.6 to 9.7 ([#12908](https://github.com/opensearch-project/OpenSearch/pull/12908))
30-
- Bump `net.minidev:json-smart` from 2.5.0 to 2.5.1 ([#12893](https://github.com/opensearch-project/OpenSearch/pull/12893), [#13117](https://github.com/opensearch-project/OpenSearch/pull/13117))
31-
- Bump `netty` from 4.1.107.Final to 4.1.109.Final ([#12924](https://github.com/opensearch-project/OpenSearch/pull/12924), [#13233](https://github.com/opensearch-project/OpenSearch/pull/13233))
32-
- Bump `commons-io:commons-io` from 2.15.1 to 2.16.0 ([#12996](https://github.com/opensearch-project/OpenSearch/pull/12996), [#12998](https://github.com/opensearch-project/OpenSearch/pull/12998), [#12999](https://github.com/opensearch-project/OpenSearch/pull/12999))
33-
- Bump `org.apache.commons:commons-compress` from 1.24.0 to 1.26.1 ([#12627](https://github.com/opensearch-project/OpenSearch/pull/12627))
34-
- Bump `org.apache.commons:commonscodec` from 1.15 to 1.16.1 ([#12627](https://github.com/opensearch-project/OpenSearch/pull/12627))
35-
- Bump `org.apache.commons:commonslang` from 3.13.0 to 3.14.0 ([#12627](https://github.com/opensearch-project/OpenSearch/pull/12627))
36-
- Bump Apache Tika from 2.6.0 to 2.9.2 ([#12627](https://github.com/opensearch-project/OpenSearch/pull/12627))
37-
- Bump `com.gradle.enterprise` from 3.16.2 to 3.17.1 ([#13116](https://github.com/opensearch-project/OpenSearch/pull/13116), [#13191](https://github.com/opensearch-project/OpenSearch/pull/13191))
38-
- Bump `gradle/wrapper-validation-action` from 2 to 3 ([#13192](https://github.com/opensearch-project/OpenSearch/pull/13192))
39-
- Bump joda from 2.12.2 to 2.12.7 ([#13193](https://github.com/opensearch-project/OpenSearch/pull/13193))
40-
- Bump bouncycastle from 1.77 to 1.78 ([#13243](https://github.com/opensearch-project/OpenSearch/pull/13243))
41-
- Update google dependencies in repository-gcs and discovery-gce ([#13213](https://github.com/opensearch-project/OpenSearch/pull/13213))
11+
- Bump `com.github.spullara.mustache.java:compiler` from 0.9.10 to 0.9.13 ([#13329](https://github.com/opensearch-project/OpenSearch/pull/13329), [#13559](https://github.com/opensearch-project/OpenSearch/pull/13559))
12+
- Bump `org.gradle.test-retry` from 1.5.8 to 1.5.9 ([#13442](https://github.com/opensearch-project/OpenSearch/pull/13442))
13+
- Bump `org.apache.commons:commons-text` from 1.11.0 to 1.12.0 ([#13557](https://github.com/opensearch-project/OpenSearch/pull/13557))
14+
- Bump `org.hdrhistogram:HdrHistogram` from 2.1.12 to 2.2.1 ([#13556](https://github.com/opensearch-project/OpenSearch/pull/13556))
4215

4316
### Changed
44-
- [BWC and API enforcement] Enforcing the presence of API annotations at build time ([#12872](https://github.com/opensearch-project/OpenSearch/pull/12872))
45-
- Improve built-in secure transports support ([#12907](https://github.com/opensearch-project/OpenSearch/pull/12907))
46-
- Update links to documentation in rest-api-spec ([#13043](https://github.com/opensearch-project/OpenSearch/pull/13043))
47-
- Refactoring globMatch using simpleMatchWithNormalizedStrings from Regex ([#13104](https://github.com/opensearch-project/OpenSearch/pull/13104))
17+
- Add ability for Boolean and date field queries to run when only doc_values are enabled ([#11650](https://github.com/opensearch-project/OpenSearch/pull/11650))
18+
- Refactor implementations of query phase searcher, allow QueryCollectorContext to have zero collectors ([#13481](https://github.com/opensearch-project/OpenSearch/pull/13481))
4819

4920
### Deprecated
5021

5122
### Removed
5223
- Remove handling of index.mapper.dynamic in AutoCreateIndex([#13067](https://github.com/opensearch-project/OpenSearch/pull/13067))
5324

5425
### Fixed
55-
- Fix bulk API ignores ingest pipeline for upsert ([#12883](https://github.com/opensearch-project/OpenSearch/pull/12883))
56-
- Fix issue with feature flags where default value may not be honored ([#12849](https://github.com/opensearch-project/OpenSearch/pull/12849))
57-
- Fix UOE While building Exists query for nested search_as_you_type field ([#12048](https://github.com/opensearch-project/OpenSearch/pull/12048))
58-
- Client with Java 8 runtime and Apache HttpClient 5 Transport fails with java.lang.NoSuchMethodError: java.nio.ByteBuffer.flip()Ljava/nio/ByteBuffer ([#13100](https://github.com/opensearch-project/opensearch-java/pull/13100))
59-
- Enabled mockTelemetryPlugin for IT and fixed OOM issues ([#13054](https://github.com/opensearch-project/OpenSearch/pull/13054))
60-
- Fix implement mark() and markSupported() in class FilterStreamInput ([#13098](https://github.com/opensearch-project/OpenSearch/pull/13098))
61-
- Fix snapshot _status API to return correct status for partial snapshots ([#12812](https://github.com/opensearch-project/OpenSearch/pull/12812))
62-
- Ignore BaseRestHandler unconsumed content check as it's always consumed. ([#13290](https://github.com/opensearch-project/OpenSearch/pull/13290))
26+
- Fix negative RequestStats metric issue ([#13553](https://github.com/opensearch-project/OpenSearch/pull/13553))
27+
- Fix get field mapping API returns 404 error in mixed cluster with multiple versions ([#13624](https://github.com/opensearch-project/OpenSearch/pull/13624))
6328

6429
### Security
6530

CONTRIBUTING.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
- [Changelog](#changelog)
1010
- [Review Process](#review-process)
1111
- [Tips for Success](#tips)
12+
- [Troubleshooting Failing Builds](#troubleshooting-failing-builds)
1213

1314
# Contributing to OpenSearch
1415

@@ -180,3 +181,13 @@ We have a lot of mechanisms to help expedite towards an accepted PR. Here are so
180181

181182
In general, adding more guardrails to your changes increases the likelihood of swift PR acceptance. We can always relax these guard rails in smaller followup PRs. Reverting a GA feature is much more difficult. Check out the [DEVELOPER_GUIDE](./DEVELOPER_GUIDE.md#submitting-changes) for more useful tips.
182183

184+
## Troubleshooting Failing Builds
185+
186+
The OpenSearch testing framework offers many capabilities but exhibits significant complexity (it does lot of randomization internally to cover as many edge cases and variations as possible). Unfortunately, this posses a challenge by making it harder to discover important issues/bugs in straightforward way and may lead to so called flaky tests - the tests which flip randomly from success to failure without any code changes.
187+
188+
If your pull request reports a failing test(s) on one of the checks, please:
189+
- look if there is an existing [issue](https://github.com/opensearch-project/OpenSearch/issues) reported for the test in question
190+
- if not, please make sure this is not caused by your changes, run the failing test(s) locally for some time
191+
- if you are sure the failure is not related, please open a new [bug](https://github.com/opensearch-project/OpenSearch/issues/new?assignees=&labels=bug%2C+untriaged&projects=&template=bug_template.md&title=%5BBUG%5D) with `flaky-test` label
192+
- add a comment referencing the issue(s) or bug report(s) to your pull request explaining the failing build(s)
193+
- as a bonus point, try to contribute by fixing the flaky test(s)

DEVELOPER_GUIDE.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@
5757
- [Developer API](#developer-api)
5858
- [User API](#user-api)
5959
- [Experimental Development](#experimental-development)
60+
- [API Compatibility Checks](#api-compatibility-checks)
6061
- [Backports](#backports)
6162
- [LineLint](#linelint)
6263
- [Lucene Snapshots](#lucene-snapshots)
@@ -607,6 +608,20 @@ a LTS feature but with additional guard rails and communication mechanisms to si
607608
release, or be removed altogether. Any Developer or User APIs implemented along with the experimental feature should be marked with `@ExperimentalApi` (or documented as
608609
`@opensearch.experimental`) annotation to signal the implementation is not subject to LTS and does not follow backwards compatibility guidelines.
609610

611+
#### API Compatibility Checks
612+
613+
The compatibility checks for public APIs are performed using [japicmp](https://siom79.github.io/japicmp/) and are available as separate Gradle tasks (those are run on demand at the moment):
614+
615+
```
616+
./gradlew japicmp
617+
```
618+
619+
By default, the API compatibility checks are run against the latest released version of the OpenSearch, however the target version to compare to could be provided using system property during the build, fe.:
620+
621+
```
622+
./gradlew japicmp -Djapicmp.compare.version=2.14.0-SNAPSHOT
623+
```
624+
610625
### Backports
611626

612627
The Github workflow in [`backport.yml`](.github/workflows/backport.yml) creates backport PRs automatically when the original PR with an appropriate label `backport <backport-branch-name>` is merged to main with the backport workflow run successfully on the PR. For example, if a PR on main needs to be backported to `1.x` branch, add a label `backport 1.x` to the PR and make sure the backport workflow runs on the PR along with other checks. Once this PR is merged to main, the workflow will create a backport PR to the `1.x` branch.

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@
4545
This project has adopted the [Amazon Open Source Code of Conduct](CODE_OF_CONDUCT.md). For more information see the [Code of Conduct FAQ](https://aws.github.io/code-of-conduct-faq), or contact [opensource-codeofconduct@amazon.com](mailto:opensource-codeofconduct@amazon.com) with any additional questions or comments.
4646

4747
## Security
48-
If you discover a potential security issue in this project we ask that you notify AWS/Amazon Security via our [vulnerability reporting page](http://aws.amazon.com/security/vulnerability-reporting/) or directly via email to aws-security@amazon.com. Please do **not** create a public GitHub issue.
48+
If you discover a potential security issue in this project we ask that you notify OpenSearch Security directly via email to security@opensearch.org. Please do **not** create a public GitHub issue.
4949

5050
## License
5151

SECURITY.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
## Reporting a Vulnerability
22

3-
If you discover a potential security issue in this project we ask that you notify AWS/Amazon Security via our [vulnerability reporting page](http://aws.amazon.com/security/vulnerability-reporting/) or directly via email to aws-security@amazon.com. Please do **not** create a public GitHub issue.
3+
If you discover a potential security issue in this project we ask that you notify OpenSearch Security directly via email to security@opensearch.org. Please do **not** create a public GitHub issue.

build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ plugins {
5555
id 'opensearch.docker-support'
5656
id 'opensearch.global-build-info'
5757
id "com.diffplug.spotless" version "6.25.0" apply false
58-
id "org.gradle.test-retry" version "1.5.8" apply false
58+
id "org.gradle.test-retry" version "1.5.9" apply false
5959
id "test-report-aggregation"
6060
id 'jacoco-report-aggregation'
6161
}

buildSrc/src/main/java/org/opensearch/gradle/test/DistroTestPlugin.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,9 +77,9 @@
7777
import java.util.stream.Stream;
7878

7979
public class DistroTestPlugin implements Plugin<Project> {
80-
private static final String SYSTEM_JDK_VERSION = "21.0.2+13";
80+
private static final String SYSTEM_JDK_VERSION = "21.0.3+9";
8181
private static final String SYSTEM_JDK_VENDOR = "adoptium";
82-
private static final String GRADLE_JDK_VERSION = "21.0.2+13";
82+
private static final String GRADLE_JDK_VERSION = "21.0.3+9";
8383
private static final String GRADLE_JDK_VENDOR = "adoptium";
8484

8585
// all distributions used by distro tests. this is temporary until tests are per distribution

buildSrc/version.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ opensearch = 3.0.0
22
lucene = 9.11.0-snapshot-fb97840
33

44
bundled_jdk_vendor = adoptium
5-
bundled_jdk = 21.0.2+13
5+
bundled_jdk = 21.0.3+9
66

77
# optional dependencies
88
spatial4j = 0.7

distribution/packages/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ import java.util.regex.Pattern
6363
*/
6464

6565
plugins {
66-
id "com.netflix.nebula.ospackage-base" version "11.8.1"
66+
id "com.netflix.nebula.ospackage-base" version "11.9.0"
6767
}
6868

6969
void addProcessFilesTask(String type, boolean jdk) {

distribution/tools/plugin-cli/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ dependencies {
3838
compileOnly project(":server")
3939
compileOnly project(":libs:opensearch-cli")
4040
api "org.bouncycastle:bcpg-fips:1.0.7.1"
41-
api "org.bouncycastle:bc-fips:1.0.2.4"
41+
api "org.bouncycastle:bc-fips:1.0.2.5"
4242
testImplementation project(":test:framework")
4343
testImplementation 'com.google.jimfs:jimfs:1.3.0'
4444
testRuntimeOnly("com.google.guava:guava:${versions.guava}") {

distribution/tools/plugin-cli/licenses/bc-fips-1.0.2.4.jar.sha1

Lines changed: 0 additions & 1 deletion
This file was deleted.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
704e65f7e4fe679e5ab2aa8a840f27f8ced4c522

libs/core/src/main/java/org/opensearch/Version.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,7 @@ public class Version implements Comparable<Version>, ToXContentFragment {
103103
public static final Version V_2_13_0 = new Version(2130099, org.apache.lucene.util.Version.LUCENE_9_10_0);
104104
public static final Version V_2_13_1 = new Version(2130199, org.apache.lucene.util.Version.LUCENE_9_10_0);
105105
public static final Version V_2_14_0 = new Version(2140099, org.apache.lucene.util.Version.LUCENE_9_10_0);
106+
public static final Version V_2_15_0 = new Version(2150099, org.apache.lucene.util.Version.LUCENE_9_10_0);
106107
public static final Version V_3_0_0 = new Version(3000099, org.apache.lucene.util.Version.LUCENE_9_11_0);
107108
public static final Version CURRENT = V_3_0_0;
108109

libs/core/src/main/java/org/opensearch/core/common/io/stream/StreamInput.java

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@
8080
import java.util.Arrays;
8181
import java.util.Collection;
8282
import java.util.Collections;
83+
import java.util.Comparator;
8384
import java.util.Date;
8485
import java.util.EnumSet;
8586
import java.util.HashMap;
@@ -90,6 +91,8 @@
9091
import java.util.Locale;
9192
import java.util.Map;
9293
import java.util.Set;
94+
import java.util.SortedMap;
95+
import java.util.TreeMap;
9396
import java.util.concurrent.TimeUnit;
9497
import java.util.function.IntFunction;
9598

@@ -642,12 +645,47 @@ public <K, V> Map<K, V> readMap(Writeable.Reader<K> keyReader, Writeable.Reader<
642645
return Collections.emptyMap();
643646
}
644647
Map<K, V> map = new HashMap<>(size);
648+
readIntoMap(keyReader, valueReader, map, size);
649+
return map;
650+
}
651+
652+
/**
653+
* Read a serialized map into a SortedMap using the default ordering for the keys. If the result is empty it might be immutable.
654+
*/
655+
public <K extends Comparable<K>, V> SortedMap<K, V> readOrderedMap(Writeable.Reader<K> keyReader, Writeable.Reader<V> valueReader)
656+
throws IOException {
657+
return readOrderedMap(keyReader, valueReader, null);
658+
}
659+
660+
/**
661+
* Read a serialized map into a SortedMap, specifying a Comparator for the keys. If the result is empty it might be immutable.
662+
*/
663+
public <K extends Comparable<K>, V> SortedMap<K, V> readOrderedMap(
664+
Writeable.Reader<K> keyReader,
665+
Writeable.Reader<V> valueReader,
666+
@Nullable Comparator<K> keyComparator
667+
) throws IOException {
668+
int size = readArraySize();
669+
if (size == 0) {
670+
return Collections.emptySortedMap();
671+
}
672+
SortedMap<K, V> sortedMap;
673+
if (keyComparator == null) {
674+
sortedMap = new TreeMap<>();
675+
} else {
676+
sortedMap = new TreeMap<>(keyComparator);
677+
}
678+
readIntoMap(keyReader, valueReader, sortedMap, size);
679+
return sortedMap;
680+
}
681+
682+
private <K, V> void readIntoMap(Writeable.Reader<K> keyReader, Writeable.Reader<V> valueReader, Map<K, V> map, int size)
683+
throws IOException {
645684
for (int i = 0; i < size; i++) {
646685
K key = keyReader.read(this);
647686
V value = valueReader.read(this);
648687
map.put(key, value);
649688
}
650-
return map;
651689
}
652690

653691
/**

0 commit comments

Comments
 (0)