Skip to content

Commit ab69f34

Browse files
dblockoksanay
andauthored
Fix integer overflow for remaining index stats (#960) (#965)
Signed-off-by: dblock <[email protected]> Co-authored-by: Oksana Yakusheva <[email protected]>
1 parent 1ef976e commit ab69f34

File tree

3 files changed

+72
-30
lines changed

3 files changed

+72
-30
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ Inspired from [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)
1313
### Removed
1414

1515
### Fixed
16+
- Fix integer overflow for variables in indices stats response ([#960](https://github.com/opensearch-project/opensearch-java/pull/960))
1617

1718
### Security
1819

java-client/src/main/java/org/opensearch/client/opensearch/_types/QueryCacheStats.java

Lines changed: 32 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -49,22 +49,22 @@
4949

5050
@JsonpDeserializable
5151
public class QueryCacheStats implements JsonpSerializable {
52-
private final int cacheCount;
52+
private final long cacheCount;
5353

54-
private final int cacheSize;
54+
private final long cacheSize;
5555

56-
private final int evictions;
56+
private final long evictions;
5757

58-
private final int hitCount;
58+
private final long hitCount;
5959

6060
@Nullable
6161
private final String memorySize;
6262

6363
private final long memorySizeInBytes;
6464

65-
private final int missCount;
65+
private final long missCount;
6666

67-
private final int totalCount;
67+
private final long totalCount;
6868

6969
// ---------------------------------------------------------------------------------------------
7070

@@ -88,28 +88,28 @@ public static QueryCacheStats of(Function<Builder, ObjectBuilder<QueryCacheStats
8888
/**
8989
* Required - API name: {@code cache_count}
9090
*/
91-
public final int cacheCount() {
91+
public final long cacheCount() {
9292
return this.cacheCount;
9393
}
9494

9595
/**
9696
* Required - API name: {@code cache_size}
9797
*/
98-
public final int cacheSize() {
98+
public final long cacheSize() {
9999
return this.cacheSize;
100100
}
101101

102102
/**
103103
* Required - API name: {@code evictions}
104104
*/
105-
public final int evictions() {
105+
public final long evictions() {
106106
return this.evictions;
107107
}
108108

109109
/**
110110
* Required - API name: {@code hit_count}
111111
*/
112-
public final int hitCount() {
112+
public final long hitCount() {
113113
return this.hitCount;
114114
}
115115

@@ -131,20 +131,21 @@ public final long memorySizeInBytes() {
131131
/**
132132
* Required - API name: {@code miss_count}
133133
*/
134-
public final int missCount() {
134+
public final long missCount() {
135135
return this.missCount;
136136
}
137137

138138
/**
139139
* Required - API name: {@code total_count}
140140
*/
141-
public final int totalCount() {
141+
public final long totalCount() {
142142
return this.totalCount;
143143
}
144144

145145
/**
146146
* Serialize this object to JSON.
147147
*/
148+
@Override
148149
public void serialize(JsonGenerator generator, JsonpMapper mapper) {
149150
generator.writeStartObject();
150151
serializeInternal(generator, mapper);
@@ -188,51 +189,51 @@ protected void serializeInternal(JsonGenerator generator, JsonpMapper mapper) {
188189
*/
189190

190191
public static class Builder extends ObjectBuilderBase implements ObjectBuilder<QueryCacheStats> {
191-
private Integer cacheCount;
192+
private Long cacheCount;
192193

193-
private Integer cacheSize;
194+
private Long cacheSize;
194195

195-
private Integer evictions;
196+
private Long evictions;
196197

197-
private Integer hitCount;
198+
private Long hitCount;
198199

199200
@Nullable
200201
private String memorySize;
201202

202203
private Long memorySizeInBytes;
203204

204-
private Integer missCount;
205+
private Long missCount;
205206

206-
private Integer totalCount;
207+
private Long totalCount;
207208

208209
/**
209210
* Required - API name: {@code cache_count}
210211
*/
211-
public final Builder cacheCount(int value) {
212+
public final Builder cacheCount(long value) {
212213
this.cacheCount = value;
213214
return this;
214215
}
215216

216217
/**
217218
* Required - API name: {@code cache_size}
218219
*/
219-
public final Builder cacheSize(int value) {
220+
public final Builder cacheSize(long value) {
220221
this.cacheSize = value;
221222
return this;
222223
}
223224

224225
/**
225226
* Required - API name: {@code evictions}
226227
*/
227-
public final Builder evictions(int value) {
228+
public final Builder evictions(long value) {
228229
this.evictions = value;
229230
return this;
230231
}
231232

232233
/**
233234
* Required - API name: {@code hit_count}
234235
*/
235-
public final Builder hitCount(int value) {
236+
public final Builder hitCount(long value) {
236237
this.hitCount = value;
237238
return this;
238239
}
@@ -256,15 +257,15 @@ public final Builder memorySizeInBytes(long value) {
256257
/**
257258
* Required - API name: {@code miss_count}
258259
*/
259-
public final Builder missCount(int value) {
260+
public final Builder missCount(long value) {
260261
this.missCount = value;
261262
return this;
262263
}
263264

264265
/**
265266
* Required - API name: {@code total_count}
266267
*/
267-
public final Builder totalCount(int value) {
268+
public final Builder totalCount(long value) {
268269
this.totalCount = value;
269270
return this;
270271
}
@@ -275,6 +276,7 @@ public final Builder totalCount(int value) {
275276
* @throws NullPointerException
276277
* if some of the required fields are null.
277278
*/
279+
@Override
278280
public QueryCacheStats build() {
279281
_checkSingleUse();
280282

@@ -294,14 +296,14 @@ public QueryCacheStats build() {
294296

295297
protected static void setupQueryCacheStatsDeserializer(ObjectDeserializer<QueryCacheStats.Builder> op) {
296298

297-
op.add(Builder::cacheCount, JsonpDeserializer.integerDeserializer(), "cache_count");
298-
op.add(Builder::cacheSize, JsonpDeserializer.integerDeserializer(), "cache_size");
299-
op.add(Builder::evictions, JsonpDeserializer.integerDeserializer(), "evictions");
300-
op.add(Builder::hitCount, JsonpDeserializer.integerDeserializer(), "hit_count");
299+
op.add(Builder::cacheCount, JsonpDeserializer.longDeserializer(), "cache_count");
300+
op.add(Builder::cacheSize, JsonpDeserializer.longDeserializer(), "cache_size");
301+
op.add(Builder::evictions, JsonpDeserializer.longDeserializer(), "evictions");
302+
op.add(Builder::hitCount, JsonpDeserializer.longDeserializer(), "hit_count");
301303
op.add(Builder::memorySize, JsonpDeserializer.stringDeserializer(), "memory_size");
302304
op.add(Builder::memorySizeInBytes, JsonpDeserializer.longDeserializer(), "memory_size_in_bytes");
303-
op.add(Builder::missCount, JsonpDeserializer.integerDeserializer(), "miss_count");
304-
op.add(Builder::totalCount, JsonpDeserializer.integerDeserializer(), "total_count");
305+
op.add(Builder::missCount, JsonpDeserializer.longDeserializer(), "miss_count");
306+
op.add(Builder::totalCount, JsonpDeserializer.longDeserializer(), "total_count");
305307

306308
}
307309

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
package org.opensearch.client.opensearch._types;
2+
3+
import static org.junit.Assert.assertEquals;
4+
5+
import jakarta.json.stream.JsonParser;
6+
import java.io.StringReader;
7+
import org.junit.Test;
8+
import org.opensearch.client.json.jackson.JacksonJsonpMapper;
9+
10+
public class QueryCacheStatsTest {
11+
12+
@Test
13+
public void testLongSerialization() {
14+
QueryCacheStats expected = new QueryCacheStats.Builder().cacheCount(2757938871l)
15+
.cacheSize(1757938872l)
16+
.evictions(3757938873l)
17+
.hitCount(4757938874l)
18+
.memorySizeInBytes(5757938875l)
19+
.missCount(6757938876l)
20+
.totalCount(7757938877l)
21+
.build();
22+
23+
String jsonString = "{\"cache_count\": 2757938871, \"cache_size\": 1757938872, \"evictions\":"
24+
+ " 3757938873, \"hit_count\": 4757938874, \"memory_size_in_bytes\": 5757938875, \"miss_count\":"
25+
+ " 6757938876, \"total_count\": 7757938877}";
26+
27+
StringReader reader = new StringReader(jsonString);
28+
JacksonJsonpMapper mapper = new JacksonJsonpMapper();
29+
JsonParser parser = mapper.jsonProvider().createParser(reader);
30+
QueryCacheStats actual = QueryCacheStats._DESERIALIZER.deserialize(parser, mapper);
31+
assertEquals(expected.hitCount(), actual.hitCount());
32+
assertEquals(expected.memorySizeInBytes(), actual.memorySizeInBytes());
33+
assertEquals(expected.missCount(), actual.missCount());
34+
assertEquals(expected.cacheCount(), actual.cacheCount());
35+
assertEquals(expected.totalCount(), actual.totalCount());
36+
assertEquals(expected.cacheSize(), actual.cacheSize());
37+
assertEquals(expected.evictions(), actual.evictions());
38+
}
39+
}

0 commit comments

Comments
 (0)