Skip to content

Commit 8423a08

Browse files
retarayshrey
authored andcommitted
Restore support for Java 8 for RestClient (opensearch-project#11562)
Signed-off-by: Andriy Redko <andriy.redko@aiven.io>
1 parent 390db6d commit 8423a08

File tree

5 files changed

+36
-15
lines changed

5 files changed

+36
-15
lines changed

CHANGELOG.md

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

174175
### Deprecated
175176

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 {
@@ -109,3 +109,10 @@ thirdPartyAudit.ignoreMissingClasses(
109109
'javax.servlet.ServletContextEvent',
110110
'javax.servlet.ServletContextListener'
111111
)
112+
113+
tasks.withType(JavaCompile) {
114+
// Suppressing '[options] target value 8 is obsolete and will be removed in a future release'
115+
configure(options) {
116+
options.compilerArgs << '-Xlint:-options'
117+
}
118+
}

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

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1116,9 +1116,15 @@ public long getContentLength() {
11161116
if (chunkedEnabled.get()) {
11171117
return -1L;
11181118
} else {
1119-
long size;
1119+
long size = 0;
1120+
final byte[] buf = new byte[8192];
1121+
int nread = 0;
1122+
11201123
try (InputStream is = getContent()) {
1121-
size = is.readAllBytes().length;
1124+
// read to EOF which may read more or less than buffer size
1125+
while ((nread = is.read(buf)) > 0) {
1126+
size += nread;
1127+
}
11221128
} catch (IOException ex) {
11231129
size = -1L;
11241130
}

client/rest/src/test/java/org/opensearch/client/nio/HeapBufferedAsyncEntityConsumerTests.java

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -35,34 +35,34 @@ public void tearDown() {
3535
}
3636

3737
public void testConsumerAllocatesBufferLimit() throws IOException {
38-
consumer.consume(randomByteBufferOfLength(1000).flip());
38+
consumer.consume((ByteBuffer) randomByteBufferOfLength(1000).flip());
3939
assertThat(consumer.getBuffer().capacity(), equalTo(1000));
4040
}
4141

4242
public void testConsumerAllocatesEmptyBuffer() throws IOException {
43-
consumer.consume(ByteBuffer.allocate(0).flip());
43+
consumer.consume((ByteBuffer) ByteBuffer.allocate(0).flip());
4444
assertThat(consumer.getBuffer().capacity(), equalTo(0));
4545
}
4646

4747
public void testConsumerExpandsBufferLimits() throws IOException {
48-
consumer.consume(randomByteBufferOfLength(1000).flip());
49-
consumer.consume(randomByteBufferOfLength(2000).flip());
50-
consumer.consume(randomByteBufferOfLength(3000).flip());
48+
consumer.consume((ByteBuffer) randomByteBufferOfLength(1000).flip());
49+
consumer.consume((ByteBuffer) randomByteBufferOfLength(2000).flip());
50+
consumer.consume((ByteBuffer) randomByteBufferOfLength(3000).flip());
5151
assertThat(consumer.getBuffer().capacity(), equalTo(6000));
5252
}
5353

5454
public void testConsumerAllocatesLimit() throws IOException {
55-
consumer.consume(randomByteBufferOfLength(BUFFER_LIMIT).flip());
55+
consumer.consume((ByteBuffer) randomByteBufferOfLength(BUFFER_LIMIT).flip());
5656
assertThat(consumer.getBuffer().capacity(), equalTo(BUFFER_LIMIT));
5757
}
5858

5959
public void testConsumerFailsToAllocateOverLimit() throws IOException {
60-
assertThrows(ContentTooLongException.class, () -> consumer.consume(randomByteBufferOfLength(BUFFER_LIMIT + 1).flip()));
60+
assertThrows(ContentTooLongException.class, () -> consumer.consume((ByteBuffer) randomByteBufferOfLength(BUFFER_LIMIT + 1).flip()));
6161
}
6262

6363
public void testConsumerFailsToExpandOverLimit() throws IOException {
64-
consumer.consume(randomByteBufferOfLength(BUFFER_LIMIT).flip());
65-
assertThrows(ContentTooLongException.class, () -> consumer.consume(randomByteBufferOfLength(1).flip()));
64+
consumer.consume((ByteBuffer) randomByteBufferOfLength(BUFFER_LIMIT).flip());
65+
assertThrows(ContentTooLongException.class, () -> consumer.consume((ByteBuffer) randomByteBufferOfLength(1).flip()));
6666
}
6767

6868
private static ByteBuffer randomByteBufferOfLength(int length) {

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)