Skip to content

Commit 35b98af

Browse files
gkorlandsazzad16
andauthored
clean warns (#2335)
* clean warns * Add more try-resource blocks * Update RedisVersionUtil.java * Update src/test/java/redis/clients/jedis/tests/JedisSentinelPoolWithCompleteCredentialsTest.java Co-authored-by: M Sazzadul Hoque <[email protected]> * Update src/test/java/redis/clients/jedis/tests/JedisSentinelPoolWithCompleteCredentialsTest.java Co-authored-by: M Sazzadul Hoque <[email protected]> * Update src/main/java/redis/clients/jedis/ZParams.java Co-authored-by: M Sazzadul Hoque <[email protected]>
1 parent a776efc commit 35b98af

File tree

11 files changed

+178
-197
lines changed

11 files changed

+178
-197
lines changed

src/main/java/redis/clients/jedis/BinaryClient.java

Lines changed: 93 additions & 94 deletions
Large diffs are not rendered by default.

src/main/java/redis/clients/jedis/BinaryJedisPubSub.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -104,32 +104,32 @@ private void process(Client client) {
104104
throw new JedisException("Unknown message type: " + firstObj);
105105
}
106106
final byte[] resp = (byte[]) firstObj;
107-
if (Arrays.equals(SUBSCRIBE.raw, resp)) {
107+
if (Arrays.equals(SUBSCRIBE.getRaw(), resp)) {
108108
subscribedChannels = ((Long) reply.get(2)).intValue();
109109
final byte[] bchannel = (byte[]) reply.get(1);
110110
onSubscribe(bchannel, subscribedChannels);
111-
} else if (Arrays.equals(UNSUBSCRIBE.raw, resp)) {
111+
} else if (Arrays.equals(UNSUBSCRIBE.getRaw(), resp)) {
112112
subscribedChannels = ((Long) reply.get(2)).intValue();
113113
final byte[] bchannel = (byte[]) reply.get(1);
114114
onUnsubscribe(bchannel, subscribedChannels);
115-
} else if (Arrays.equals(MESSAGE.raw, resp)) {
115+
} else if (Arrays.equals(MESSAGE.getRaw(), resp)) {
116116
final byte[] bchannel = (byte[]) reply.get(1);
117117
final byte[] bmesg = (byte[]) reply.get(2);
118118
onMessage(bchannel, bmesg);
119-
} else if (Arrays.equals(PMESSAGE.raw, resp)) {
119+
} else if (Arrays.equals(PMESSAGE.getRaw(), resp)) {
120120
final byte[] bpattern = (byte[]) reply.get(1);
121121
final byte[] bchannel = (byte[]) reply.get(2);
122122
final byte[] bmesg = (byte[]) reply.get(3);
123123
onPMessage(bpattern, bchannel, bmesg);
124-
} else if (Arrays.equals(PSUBSCRIBE.raw, resp)) {
124+
} else if (Arrays.equals(PSUBSCRIBE.getRaw(), resp)) {
125125
subscribedChannels = ((Long) reply.get(2)).intValue();
126126
final byte[] bpattern = (byte[]) reply.get(1);
127127
onPSubscribe(bpattern, subscribedChannels);
128-
} else if (Arrays.equals(PUNSUBSCRIBE.raw, resp)) {
128+
} else if (Arrays.equals(PUNSUBSCRIBE.getRaw(), resp)) {
129129
subscribedChannels = ((Long) reply.get(2)).intValue();
130130
final byte[] bpattern = (byte[]) reply.get(1);
131131
onPUnsubscribe(bpattern, subscribedChannels);
132-
} else if (Arrays.equals(PONG.raw, resp)) {
132+
} else if (Arrays.equals(PONG.getRaw(), resp)) {
133133
final byte[] bpattern = (byte[]) reply.get(1);
134134
onPong(bpattern);
135135
} else {

src/main/java/redis/clients/jedis/BuilderFactory.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -629,7 +629,6 @@ public String toString() {
629629

630630
public static final Builder<StreamEntryID> STREAM_ENTRY_ID = new Builder<StreamEntryID>() {
631631
@Override
632-
@SuppressWarnings("unchecked")
633632
public StreamEntryID build(Object data) {
634633
if (null == data) {
635634
return null;

src/main/java/redis/clients/jedis/Jedis.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3121,7 +3121,7 @@ public List<Map<String, String>> sentinelMasters() {
31213121

31223122
final List<Map<String, String>> masters = new ArrayList<>();
31233123
for (Object obj : reply) {
3124-
masters.add(BuilderFactory.STRING_MAP.build((List) obj));
3124+
masters.add(BuilderFactory.STRING_MAP.build( obj));
31253125
}
31263126
return masters;
31273127
}
@@ -3192,7 +3192,6 @@ public Long sentinelReset(final String pattern) {
31923192
* @return
31933193
*/
31943194
@Override
3195-
@SuppressWarnings("rawtypes")
31963195
public List<Map<String, String>> sentinelSlaves(final String masterName) {
31973196
client.sentinel(Protocol.SENTINEL_SLAVES, masterName);
31983197
final List<Object> reply = client.getObjectMultiBulkReply();

src/main/java/redis/clients/jedis/JedisPubSub.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -134,41 +134,41 @@ private void process(Client client) {
134134
throw new JedisException("Unknown message type: " + firstObj);
135135
}
136136
final byte[] resp = (byte[]) firstObj;
137-
if (Arrays.equals(SUBSCRIBE.raw, resp)) {
137+
if (Arrays.equals(SUBSCRIBE.getRaw(), resp)) {
138138
subscribedChannels = ((Long) reply.get(2)).intValue();
139139
final byte[] bchannel = (byte[]) reply.get(1);
140140
final String strchannel = (bchannel == null) ? null : SafeEncoder.encode(bchannel);
141141
onSubscribe(strchannel, subscribedChannels);
142-
} else if (Arrays.equals(UNSUBSCRIBE.raw, resp)) {
142+
} else if (Arrays.equals(UNSUBSCRIBE.getRaw(), resp)) {
143143
subscribedChannels = ((Long) reply.get(2)).intValue();
144144
final byte[] bchannel = (byte[]) reply.get(1);
145145
final String strchannel = (bchannel == null) ? null : SafeEncoder.encode(bchannel);
146146
onUnsubscribe(strchannel, subscribedChannels);
147-
} else if (Arrays.equals(MESSAGE.raw, resp)) {
147+
} else if (Arrays.equals(MESSAGE.getRaw(), resp)) {
148148
final byte[] bchannel = (byte[]) reply.get(1);
149149
final byte[] bmesg = (byte[]) reply.get(2);
150150
final String strchannel = (bchannel == null) ? null : SafeEncoder.encode(bchannel);
151151
final String strmesg = (bmesg == null) ? null : SafeEncoder.encode(bmesg);
152152
onMessage(strchannel, strmesg);
153-
} else if (Arrays.equals(PMESSAGE.raw, resp)) {
153+
} else if (Arrays.equals(PMESSAGE.getRaw(), resp)) {
154154
final byte[] bpattern = (byte[]) reply.get(1);
155155
final byte[] bchannel = (byte[]) reply.get(2);
156156
final byte[] bmesg = (byte[]) reply.get(3);
157157
final String strpattern = (bpattern == null) ? null : SafeEncoder.encode(bpattern);
158158
final String strchannel = (bchannel == null) ? null : SafeEncoder.encode(bchannel);
159159
final String strmesg = (bmesg == null) ? null : SafeEncoder.encode(bmesg);
160160
onPMessage(strpattern, strchannel, strmesg);
161-
} else if (Arrays.equals(PSUBSCRIBE.raw, resp)) {
161+
} else if (Arrays.equals(PSUBSCRIBE.getRaw(), resp)) {
162162
subscribedChannels = ((Long) reply.get(2)).intValue();
163163
final byte[] bpattern = (byte[]) reply.get(1);
164164
final String strpattern = (bpattern == null) ? null : SafeEncoder.encode(bpattern);
165165
onPSubscribe(strpattern, subscribedChannels);
166-
} else if (Arrays.equals(PUNSUBSCRIBE.raw, resp)) {
166+
} else if (Arrays.equals(PUNSUBSCRIBE.getRaw(), resp)) {
167167
subscribedChannels = ((Long) reply.get(2)).intValue();
168168
final byte[] bpattern = (byte[]) reply.get(1);
169169
final String strpattern = (bpattern == null) ? null : SafeEncoder.encode(bpattern);
170170
onPUnsubscribe(strpattern, subscribedChannels);
171-
} else if (Arrays.equals(PONG.raw, resp)) {
171+
} else if (Arrays.equals(PONG.getRaw(), resp)) {
172172
final byte[] bpattern = (byte[]) reply.get(1);
173173
final String strpattern = (bpattern == null) ? null : SafeEncoder.encode(bpattern);
174174
onPong(strpattern);

src/main/java/redis/clients/jedis/SortingParams.java

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ public SortingParams by(final String pattern) {
5050
* @return the SortingParams Object
5151
*/
5252
public SortingParams by(final byte[] pattern) {
53-
params.add(BY.raw);
53+
params.add(BY.getRaw());
5454
params.add(pattern);
5555
return this;
5656
}
@@ -63,8 +63,8 @@ public SortingParams by(final byte[] pattern) {
6363
* @return the SortingParams Object
6464
*/
6565
public SortingParams nosort() {
66-
params.add(BY.raw);
67-
params.add(NOSORT.raw);
66+
params.add(BY.getRaw());
67+
params.add(NOSORT.getRaw());
6868
return this;
6969
}
7070

@@ -77,7 +77,7 @@ public Collection<byte[]> getParams() {
7777
* @return the sortingParams Object
7878
*/
7979
public SortingParams desc() {
80-
params.add(DESC.raw);
80+
params.add(DESC.getRaw());
8181
return this;
8282
}
8383

@@ -86,7 +86,7 @@ public SortingParams desc() {
8686
* @return the SortingParams Object
8787
*/
8888
public SortingParams asc() {
89-
params.add(ASC.raw);
89+
params.add(ASC.getRaw());
9090
return this;
9191
}
9292

@@ -97,7 +97,7 @@ public SortingParams asc() {
9797
* @return the SortingParams Object
9898
*/
9999
public SortingParams limit(final int start, final int count) {
100-
params.add(LIMIT.raw);
100+
params.add(LIMIT.getRaw());
101101
params.add(Protocol.toByteArray(start));
102102
params.add(Protocol.toByteArray(count));
103103
return this;
@@ -109,7 +109,7 @@ public SortingParams limit(final int start, final int count) {
109109
* @return the SortingParams Object
110110
*/
111111
public SortingParams alpha() {
112-
params.add(ALPHA.raw);
112+
params.add(ALPHA.getRaw());
113113
return this;
114114
}
115115

@@ -129,7 +129,7 @@ public SortingParams alpha() {
129129
*/
130130
public SortingParams get(String... patterns) {
131131
for (final String pattern : patterns) {
132-
params.add(GET.raw);
132+
params.add(GET.getRaw());
133133
params.add(SafeEncoder.encode(pattern));
134134
}
135135
return this;
@@ -151,7 +151,7 @@ public SortingParams get(String... patterns) {
151151
*/
152152
public SortingParams get(byte[]... patterns) {
153153
for (final byte[] pattern : patterns) {
154-
params.add(GET.raw);
154+
params.add(GET.getRaw());
155155
params.add(pattern);
156156
}
157157
return this;

src/main/java/redis/clients/jedis/StreamConsumersInfo.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@
1111
*/
1212
public class StreamConsumersInfo {
1313

14-
public final static String NAME = "name";
15-
public final static String IDLE = "idle";
16-
public final static String PENDING = "pending";
14+
public static final String NAME = "name";
15+
public static final String IDLE = "idle";
16+
public static final String PENDING = "pending";
1717

1818
private final String name;
1919
private final long idle;

src/main/java/redis/clients/jedis/ZParams.java

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,19 @@ public class ZParams {
1414
public enum Aggregate {
1515
SUM, MIN, MAX;
1616

17+
/**
18+
* @deprecated This will be private in future. Use {@link #getRaw()}.
19+
*/
20+
@Deprecated
1721
public final byte[] raw;
1822

1923
Aggregate() {
2024
raw = SafeEncoder.encode(name());
2125
}
26+
27+
public byte[] getRaw() {
28+
return raw;
29+
}
2230
}
2331

2432
private final List<byte[]> params = new ArrayList<>();
@@ -29,7 +37,7 @@ public enum Aggregate {
2937
* @return
3038
*/
3139
public ZParams weights(final double... weights) {
32-
params.add(WEIGHTS.raw);
40+
params.add(WEIGHTS.getRaw());
3341
for (final double weight : weights) {
3442
params.add(Protocol.toByteArray(weight));
3543
}
@@ -42,7 +50,7 @@ public Collection<byte[]> getParams() {
4250
}
4351

4452
public ZParams aggregate(final Aggregate aggregate) {
45-
params.add(AGGREGATE.raw);
53+
params.add(AGGREGATE.getRaw());
4654
params.add(aggregate.raw);
4755
return this;
4856
}

src/main/java/redis/clients/jedis/params/GeoRadiusStoreParam.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package redis.clients.jedis.params;
22

33
import java.util.ArrayList;
4+
import java.util.Collections;
45
import java.util.LinkedList;
56
import java.util.List;
67

@@ -92,10 +93,8 @@ public byte[][] getByteKeys(byte[] key) {
9293
}
9394

9495
public byte[][] getByteParams(byte[]... args) {
95-
ArrayList<byte[]> byteParams = new ArrayList<byte[]>();
96-
for (byte[] arg : args) {
97-
byteParams.add(arg);
98-
}
96+
ArrayList<byte[]> byteParams = new ArrayList<>();
97+
Collections.addAll(byteParams, args);
9998

10099
if (contains(STORE)) {
101100
byteParams.add(SafeEncoder.encode(STORE));

src/test/java/redis/clients/jedis/tests/JedisSentinelPoolTest.java

Lines changed: 14 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -104,31 +104,22 @@ public void returnResourceShouldResetState() {
104104
GenericObjectPoolConfig config = new GenericObjectPoolConfig();
105105
config.setMaxTotal(1);
106106
config.setBlockWhenExhausted(false);
107-
JedisSentinelPool pool = new JedisSentinelPool(MASTER_NAME, sentinels, config, 1000,
108-
"foobared", 2);
109-
110-
Jedis jedis = pool.getResource();
111-
Jedis jedis2 = null;
112-
113-
try {
114-
jedis.set("hello", "jedis");
115-
Transaction t = jedis.multi();
116-
t.set("hello", "world");
117-
jedis.close();
118-
119-
jedis2 = pool.getResource();
120-
121-
assertSame(jedis, jedis2);
122-
assertEquals("jedis", jedis2.get("hello"));
123-
} catch (JedisConnectionException e) {
124-
if (jedis2 != null) {
125-
jedis2 = null;
107+
try ( JedisSentinelPool pool = new JedisSentinelPool(MASTER_NAME, sentinels, config, 1000,
108+
"foobared", 2)){
109+
110+
Jedis jedis = null;
111+
try(Jedis jedis1 = pool.getResource()){
112+
jedis = jedis1;
113+
jedis1.set("hello", "jedis");
114+
Transaction t = jedis1.multi();
115+
t.set("hello", "world");
126116
}
127-
} finally {
128-
jedis2.close();
129117

130-
pool.destroy();
131-
}
118+
try(Jedis jedis2 = pool.getResource()){
119+
assertSame(jedis, jedis2);
120+
assertEquals("jedis", jedis2.get("hello"));
121+
}
122+
}
132123
}
133124

134125
@Test

0 commit comments

Comments
 (0)