Skip to content

Commit 7f7aa05

Browse files
authored
Restore support for Java 8 for RestClient (#11562) (#11576)
Signed-off-by: Andriy Redko <[email protected]> (cherry picked from commit 4e72741)
1 parent 423f499 commit 7f7aa05

File tree

4 files changed

+27
-6
lines changed

4 files changed

+27
-6
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
8181
- Change error message when per shard document limit is breached ([#11312](https://github.com/opensearch-project/OpenSearch/pull/11312))
8282
- Improve boolean parsing performance ([#11308](https://github.com/opensearch-project/OpenSearch/pull/11308))
8383
- Interpret byte array as primitive using VarHandles ([#11362](https://github.com/opensearch-project/OpenSearch/pull/11362))
84+
- Restore support for Java 8 for RestClient ([#11562](https://github.com/opensearch-project/OpenSearch/pull/11562))
8485

8586
### Deprecated
8687

client/rest/build.gradle

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,8 @@ apply plugin: 'opensearch.build'
3434
apply plugin: 'opensearch.publish'
3535

3636
java {
37-
targetCompatibility = JavaVersion.VERSION_11
38-
sourceCompatibility = JavaVersion.VERSION_11
37+
targetCompatibility = JavaVersion.VERSION_1_8
38+
sourceCompatibility = JavaVersion.VERSION_1_8
3939
}
4040

4141
base {
@@ -104,3 +104,10 @@ thirdPartyAudit.ignoreMissingClasses(
104104
'javax.servlet.ServletContextEvent',
105105
'javax.servlet.ServletContextListener'
106106
)
107+
108+
tasks.withType(JavaCompile) {
109+
// Suppressing '[options] target value 8 is obsolete and will be removed in a future release'
110+
configure(options) {
111+
options.compilerArgs << '-Xlint:-options'
112+
}
113+
}

client/rest/src/main/java/org/opensearch/client/RestClient.java

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1021,9 +1021,15 @@ public long getContentLength() {
10211021
if (chunkedEnabled.get()) {
10221022
return -1L;
10231023
} else {
1024-
long size;
1024+
long size = 0;
1025+
final byte[] buf = new byte[8192];
1026+
int nread = 0;
1027+
10251028
try (InputStream is = getContent()) {
1026-
size = is.readAllBytes().length;
1029+
// read to EOF which may read more or less than buffer size
1030+
while ((nread = is.read(buf)) > 0) {
1031+
size += nread;
1032+
}
10271033
} catch (IOException ex) {
10281034
size = -1L;
10291035
}

client/test/build.gradle

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,8 @@
3030
apply plugin: 'opensearch.build'
3131

3232
java {
33-
targetCompatibility = JavaVersion.VERSION_11
34-
sourceCompatibility = JavaVersion.VERSION_11
33+
targetCompatibility = JavaVersion.VERSION_1_8
34+
sourceCompatibility = JavaVersion.VERSION_1_8
3535
}
3636

3737
base {
@@ -69,3 +69,10 @@ dependenciesInfo.enabled = false
6969
//we aren't releasing this jar
7070
thirdPartyAudit.enabled = false
7171
test.enabled = false
72+
73+
tasks.withType(JavaCompile) {
74+
// Suppressing '[options] target value 8 is obsolete and will be removed in a future release'
75+
configure(options) {
76+
options.compilerArgs << '-Xlint:-options'
77+
}
78+
}

0 commit comments

Comments
 (0)