Skip to content

Commit 5001c05

Browse files
AlexandrouRjosh-richardson
authored andcommitted
Fix gradle warnings (LFDT-web3j#1101)
* Clearing gradle warnings * . * . * removed -Xlint:deprecation from build * refactoring * added deprecation annotations * Applied feedback.
1 parent bee23aa commit 5001c05

File tree

56 files changed

+705
-423
lines changed

Some content is hidden

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

56 files changed

+705
-423
lines changed

abi/src/main/java/org/web3j/abi/TypeReference.java

+2
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,8 @@ public java.lang.reflect.Type getType() {
114114
*
115115
* @param solidityType the solidity as a string eg Address Int
116116
* @param primitives is it a primitive type
117+
* @return returns
118+
* @throws ClassNotFoundException when the class cannot be found.
117119
*/
118120
protected static Class<? extends org.web3j.abi.datatypes.Type> getAtomicTypeClass(
119121
String solidityType, boolean primitives) throws ClassNotFoundException {

abi/src/main/java/org/web3j/abi/datatypes/DynamicArray.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ public class DynamicArray<T extends Type> extends Array<T> {
1919

2020
@Deprecated
2121
@SafeVarargs
22-
@SuppressWarnings("unchecked")
22+
@SuppressWarnings({"unchecked"})
2323
public DynamicArray(T... values) {
2424
super((Class<T>) AbiTypes.getType(values[0].getTypeAsString()), values);
2525
}

abi/src/test/java/org/web3j/abi/TypeDecoderTest.java

+28-28
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
import org.web3j.abi.datatypes.DynamicBytes;
2424
import org.web3j.abi.datatypes.Int;
2525
import org.web3j.abi.datatypes.StaticArray;
26+
import org.web3j.abi.datatypes.Type;
2627
import org.web3j.abi.datatypes.Uint;
2728
import org.web3j.abi.datatypes.Utf8String;
2829
import org.web3j.abi.datatypes.generated.Bytes1;
@@ -37,6 +38,7 @@
3738

3839
import static org.junit.jupiter.api.Assertions.assertEquals;
3940
import static org.junit.jupiter.api.Assertions.assertThrows;
41+
import static org.junit.jupiter.api.Assertions.assertTrue;
4042

4143
public class TypeDecoderTest {
4244

@@ -345,14 +347,14 @@ public void testStaticArray() throws Exception {
345347
new Utf8String("Hello, world!"),
346348
new Utf8String("world! Hello,"))));
347349

348-
StaticArray2 arr =
349-
(StaticArray2)
350-
TypeDecoder.instantiateType("uint256[2]", new long[] {10, Long.MAX_VALUE});
351-
assert (arr instanceof StaticArray2);
350+
Type arr = TypeDecoder.instantiateType("uint256[2]", new long[] {10, Long.MAX_VALUE});
352351

353-
assertEquals(arr.getValue().get(0), (new Uint256(BigInteger.TEN)));
352+
assertTrue(arr instanceof StaticArray2);
353+
StaticArray2 staticArray2 = (StaticArray2) arr;
354+
assertEquals(staticArray2.getValue().get(0), (new Uint256(BigInteger.TEN)));
354355

355-
assertEquals(arr.getValue().get(1), (new Uint256(BigInteger.valueOf(Long.MAX_VALUE))));
356+
assertEquals(
357+
staticArray2.getValue().get(1), (new Uint256(BigInteger.valueOf(Long.MAX_VALUE))));
356358
}
357359

358360
@Test
@@ -369,7 +371,7 @@ public void testEmptyStaticArray() {
369371
}
370372

371373
@Test
372-
public void testEmptyStaticArrayInstantiateType() throws Exception {
374+
public void testEmptyStaticArrayInstantiateType() {
373375
assertThrows(
374376
ClassNotFoundException.class,
375377
() -> TypeDecoder.instantiateType("uint256[0]", new long[] {}));
@@ -410,17 +412,18 @@ public void testDynamicArray() throws Exception {
410412
new Utf8String("Hello, world!"),
411413
new Utf8String("world! Hello,"))));
412414

413-
DynamicArray arr =
414-
(DynamicArray)
415-
TypeDecoder.instantiateType(
416-
"string[]", new String[] {"Hello, world!", "world! Hello,"});
417-
assert (arr instanceof DynamicArray);
415+
Type arr =
416+
TypeDecoder.instantiateType(
417+
"string[]", new String[] {"Hello, world!", "world! Hello,"});
418+
assertTrue(arr instanceof DynamicArray);
419+
DynamicArray dynamicArray = (DynamicArray) arr;
418420

419-
assertEquals(arr.getValue().get(0), (new Utf8String("Hello, world!")));
421+
assertEquals(dynamicArray.getValue().get(0), (new Utf8String("Hello, world!")));
420422

421-
assertEquals(arr.getValue().get(1), (new Utf8String("world! Hello,")));
423+
assertEquals(dynamicArray.getValue().get(1), (new Utf8String("world! Hello,")));
422424
}
423425

426+
@SuppressWarnings("unchecked")
424427
@Test
425428
public void multiDimArrays() throws Exception {
426429
byte[] bytes1d = new byte[] {1, 2, 3};
@@ -429,20 +432,17 @@ public void multiDimArrays() throws Exception {
429432

430433
assertEquals(TypeDecoder.instantiateType("bytes", bytes1d), (new DynamicBytes(bytes1d)));
431434

432-
StaticArray3<DynamicArray<Uint256>> twoDim =
433-
(StaticArray3<DynamicArray<Uint256>>)
434-
TypeDecoder.instantiateType("uint256[][3]", bytes2d);
435-
assert (twoDim instanceof StaticArray3);
436-
DynamicArray<Uint256> row1 = twoDim.getValue().get(1);
437-
assert (row1 instanceof DynamicArray);
438-
assertEquals(row1.getValue().get(2), (new Uint256(3)));
439-
440-
StaticArray3<StaticArray3<DynamicArray<Uint256>>> threeDim =
441-
(StaticArray3<StaticArray3<DynamicArray<Uint256>>>)
442-
TypeDecoder.instantiateType("uint256[][3][3]", bytes3d);
443-
assert (threeDim instanceof StaticArray3);
444-
row1 = threeDim.getValue().get(1).getValue().get(1);
445-
assert (row1 instanceof DynamicArray);
435+
Type twoDim = TypeDecoder.instantiateType("uint256[][3]", bytes2d);
436+
assertTrue(twoDim instanceof StaticArray3);
437+
StaticArray3<DynamicArray<Uint256>> staticArray3 =
438+
(StaticArray3<DynamicArray<Uint256>>) twoDim;
439+
DynamicArray<Uint256> row1 = staticArray3.getValue().get(1);
440+
assertEquals(row1.getValue().get(2), new Uint256(3));
441+
Type threeDim = TypeDecoder.instantiateType("uint256[][3][3]", bytes3d);
442+
assertTrue(threeDim instanceof StaticArray3);
443+
StaticArray3<StaticArray3<DynamicArray<Uint256>>> staticArray3StaticArray3 =
444+
(StaticArray3<StaticArray3<DynamicArray<Uint256>>>) threeDim;
445+
row1 = staticArray3StaticArray3.getValue().get(1).getValue().get(1);
446446
assertEquals(row1.getValue().get(1), (new Uint256(2)));
447447
}
448448
}

abi/src/test/java/org/web3j/abi/TypeEncoderTest.java

+3-1
Original file line numberDiff line numberDiff line change
@@ -304,15 +304,16 @@ public void testDynamicArray() {
304304
+ "0000000000000000000000000000000000000000000000000000000000000003"));
305305
}
306306

307+
@SuppressWarnings("unchecked")
307308
@Test
308309
public void testEmptyArray() {
309-
@SuppressWarnings("unchecked")
310310
DynamicArray<Uint> array = new DynamicArray(Uint.class);
311311
assertEquals(
312312
TypeEncoder.encodeDynamicArray(array),
313313
("0000000000000000000000000000000000000000000000000000000000000000"));
314314
}
315315

316+
@SuppressWarnings("unchecked")
316317
@Test
317318
public void testArrayOfBytes() {
318319
DynamicArray<DynamicBytes> array =
@@ -376,6 +377,7 @@ public void testArrayOfBytes() {
376377
+ "0000000000000000000000000000000000000000000000000000000000000000"));
377378
}
378379

380+
@SuppressWarnings("unchecked")
379381
@Test
380382
public void testArrayOfStrings() {
381383
DynamicArray<Utf8String> array =

abi/src/test/java/org/web3j/abi/UtilsTest.java

+2-1
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939
public class UtilsTest {
4040

4141
@Test
42-
public void testGetTypeName() throws ClassNotFoundException {
42+
public void testGetTypeName() {
4343
assertEquals(Utils.getTypeName(new TypeReference<Uint>() {}), ("uint256"));
4444
assertEquals(Utils.getTypeName(new TypeReference<Int>() {}), ("int256"));
4545
assertEquals(Utils.getTypeName(new TypeReference<Ufixed>() {}), ("ufixed256"));
@@ -71,6 +71,7 @@ public void testTypeMap() {
7171
new Uint256(BigInteger.TEN))));
7272
}
7373

74+
@SuppressWarnings("unchecked")
7475
@Test
7576
public void testTypeMapNested() {
7677
List<BigInteger> innerList1 = Arrays.asList(BigInteger.valueOf(1), BigInteger.valueOf(2));

besu/src/main/java/org/web3j/protocol/besu/Besu.java

-15
Original file line numberDiff line numberDiff line change
@@ -41,21 +41,6 @@ static Besu build(Web3jService web3jService) {
4141

4242
Request<?, BooleanResponse> minerStop();
4343

44-
/** @deprecated This is deprecated as the method name is wrong. */
45-
default Request<?, BooleanResponse> clicqueDiscard(String address) {
46-
return cliqueDiscard(address);
47-
}
48-
49-
/** @deprecated This is deprecated as the method name is wrong. */
50-
default Request<?, EthAccounts> clicqueGetSigners(DefaultBlockParameter defaultBlockParameter) {
51-
return cliqueGetSigners(defaultBlockParameter);
52-
}
53-
54-
/** @deprecated This is deprecated as the method name is wrong. */
55-
default Request<?, EthAccounts> clicqueGetSignersAtHash(String blockHash) {
56-
return cliqueGetSignersAtHash(blockHash);
57-
}
58-
5944
Request<?, BooleanResponse> cliqueDiscard(String address);
6045

6146
Request<?, EthAccounts> cliqueGetSigners(DefaultBlockParameter defaultBlockParameter);

besu/src/test/java/org/web3j/protocol/besu/RequestTest.java

+3-3
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ public void testMinerStop() throws Exception {
5959
@Test
6060
public void testClicqueDiscard() throws Exception {
6161
final String accountId = "0xFE3B557E8Fb62b89F4916B721be55cEb828dBd73";
62-
web3j.clicqueDiscard(accountId).send();
62+
web3j.cliqueDiscard(accountId).send();
6363

6464
verifyResult(
6565
"{\"jsonrpc\":\"2.0\",\"method\":\"clique_discard\","
@@ -69,7 +69,7 @@ public void testClicqueDiscard() throws Exception {
6969
@Test
7070
public void testClicqueGetSigners() throws Exception {
7171
final DefaultBlockParameter blockParameter = DefaultBlockParameter.valueOf("latest");
72-
web3j.clicqueGetSigners(blockParameter).send();
72+
web3j.cliqueGetSigners(blockParameter).send();
7373

7474
verifyResult(
7575
"{\"jsonrpc\":\"2.0\",\"method\":\"clique_getSigners\","
@@ -80,7 +80,7 @@ public void testClicqueGetSigners() throws Exception {
8080
public void testClicqueGetSignersAtHash() throws Exception {
8181
final String blockHash =
8282
"0x98b2ddb5106b03649d2d337d42154702796438b3c74fd25a5782940e84237a48";
83-
web3j.clicqueGetSignersAtHash(blockHash).send();
83+
web3j.cliqueGetSignersAtHash(blockHash).send();
8484

8585
verifyResult(
8686
"{\"jsonrpc\":\"2.0\",\"method\":\"clique_getSignersAtHash\",\"params\":"

codegen/src/main/java/org/web3j/codegen/TruffleJsonFunctionWrapperGenerator.java

+1
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@
4747
* contains information about deployment addresses. This should make integration with Truffle
4848
* easier.
4949
*/
50+
@SuppressWarnings("deprecation")
5051
public class TruffleJsonFunctionWrapperGenerator extends FunctionWrapperGenerator {
5152

5253
private static final String USAGE =

codegen/src/main/java/org/web3j/codegen/TupleGenerator.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ private void generate(String destinationDir) throws IOException {
5454
}
5555

5656
private TypeSpec createTuple(int size) {
57-
String javadoc = "@deprecated use 'component$L' method instead";
57+
String javadoc = "@deprecated use 'component$L' method instead \n @return returns a value";
5858
String className = CLASS_NAME + size;
5959
TypeSpec.Builder typeSpecBuilder =
6060
TypeSpec.classBuilder(className)

core/src/main/java/org/web3j/protocol/core/RemoteFunctionCall.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ public String encodeFunctionCall() {
4646
/**
4747
* decode a method response
4848
*
49-
* @param response
49+
* @param response the encoded response
5050
* @return list of abi types
5151
*/
5252
public List<Type> decodeFunctionResponse(String response) {

core/src/main/java/org/web3j/protocol/core/filters/Filter.java

+1
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,7 @@ private void getInitialFilterLogs() {
115115
ethLog = new EthLog();
116116
ethLog.setResult(Collections.emptyList());
117117
}
118+
118119
process(ethLog.getLogs());
119120

120121
} catch (IOException e) {

core/src/main/java/org/web3j/protocol/websocket/WebSocketService.java

+17-17
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,7 @@ void onWebSocketMessage(String messageStr) throws IOException {
212212
}
213213
}
214214

215+
@SuppressWarnings("unchecked")
215216
private void processRequestReply(String replyStr, JsonNode replyJson) throws IOException {
216217
long replyId = getReplyId(replyJson);
217218
WebSocketRequest request = getAndRemoveRequest(replyId);
@@ -229,15 +230,15 @@ private void processRequestReply(String replyStr, JsonNode replyJson) throws IOE
229230
}
230231
}
231232

233+
@SuppressWarnings("unchecked")
232234
private void processSubscriptionResponse(long replyId, EthSubscribe reply) throws IOException {
233235
WebSocketSubscription subscription = subscriptionRequestForId.get(replyId);
234236
processSubscriptionResponse(
235237
reply, subscription.getSubject(), subscription.getResponseType());
236238
}
237239

238240
private <T extends Notification<?>> void processSubscriptionResponse(
239-
EthSubscribe subscriptionReply, BehaviorSubject<T> subject, Class<T> responseType)
240-
throws IOException {
241+
EthSubscribe subscriptionReply, BehaviorSubject<T> subject, Class<T> responseType) {
241242
if (!subscriptionReply.hasError()) {
242243
establishSubscription(subject, responseType, subscriptionReply);
243244
} else {
@@ -271,6 +272,7 @@ private <T extends Notification<?>> void reportSubscriptionError(
271272
"Subscription request failed with error: %s", error.getMessage())));
272273
}
273274

275+
@SuppressWarnings("unchecked")
274276
private void sendReplyToListener(WebSocketRequest request, Object reply) {
275277
request.getOnReply().complete(reply);
276278
}
@@ -302,6 +304,7 @@ private String extractSubscriptionId(JsonNode replyJson) {
302304
return replyJson.get("params").get("subscription").asText();
303305
}
304306

307+
@SuppressWarnings("unchecked")
305308
private void sendEventToSubscriber(JsonNode replyJson, WebSocketSubscription subscription) {
306309
Object event = objectMapper.convertValue(replyJson, subscription.getResponseType());
307310
subscription.getSubject().onNext(event);
@@ -400,11 +403,10 @@ private <T extends Notification<?>> void closeSubscription(
400403
private void unsubscribeFromEventsStream(String subscriptionId, String unsubscribeMethod) {
401404
sendAsync(unsubscribeRequest(subscriptionId, unsubscribeMethod), EthUnsubscribe.class)
402405
.thenAccept(
403-
ethUnsubscribe -> {
404-
log.debug(
405-
"Successfully unsubscribed from subscription with id {}",
406-
subscriptionId);
407-
})
406+
ethUnsubscribe ->
407+
log.debug(
408+
"Successfully unsubscribed from subscription with id {}",
409+
subscriptionId))
408410
.exceptionally(
409411
throwable -> {
410412
log.error(
@@ -438,22 +440,20 @@ private void closeOutstandingRequests() {
438440
requestForId
439441
.values()
440442
.forEach(
441-
request -> {
442-
request.getOnReply()
443-
.completeExceptionally(
444-
new IOException("Connection was closed"));
445-
});
443+
request ->
444+
request.getOnReply()
445+
.completeExceptionally(
446+
new IOException("Connection was closed")));
446447
}
447448

448449
private void closeOutstandingSubscriptions() {
449450
subscriptionForId
450451
.values()
451452
.forEach(
452-
subscription -> {
453-
subscription
454-
.getSubject()
455-
.onError(new IOException("Connection was closed"));
456-
});
453+
subscription ->
454+
subscription
455+
.getSubject()
456+
.onError(new IOException("Connection was closed")));
457457
}
458458

459459
// Method visible for unit-tests

core/src/main/java/org/web3j/tx/Contract.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@
5151
/**
5252
* Solidity contract type abstraction for interacting with smart contracts via native Java types.
5353
*/
54-
@SuppressWarnings("WeakerAccess")
54+
@SuppressWarnings({"WeakerAccess", "deprecation"})
5555
public abstract class Contract extends ManagedTransaction {
5656

5757
// https://www.reddit.com/r/ethereum/comments/5g8ia6/attention_miners_we_recommend_raising_gas_limit/

core/src/main/java/org/web3j/tx/gas/DefaultGasProvider.java

+2-5
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,9 @@
1414

1515
import java.math.BigInteger;
1616

17-
import org.web3j.tx.Contract;
18-
import org.web3j.tx.ManagedTransaction;
19-
2017
public class DefaultGasProvider extends StaticGasProvider {
21-
public static final BigInteger GAS_LIMIT = Contract.GAS_LIMIT;
22-
public static final BigInteger GAS_PRICE = ManagedTransaction.GAS_PRICE;
18+
public static final BigInteger GAS_LIMIT = BigInteger.valueOf(9_000_000);
19+
public static final BigInteger GAS_PRICE = BigInteger.valueOf(4_100_000_000L);
2320

2421
public DefaultGasProvider() {
2522
super(GAS_PRICE, GAS_LIMIT);

core/src/main/java/org/web3j/tx/gas/StaticGasProvider.java

+1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414

1515
import java.math.BigInteger;
1616

17+
@SuppressWarnings("deprecation")
1718
public class StaticGasProvider implements ContractGasProvider {
1819
private BigInteger gasPrice;
1920
private BigInteger gasLimit;

core/src/main/java/org/web3j/tx/response/PollingTransactionReceiptProcessor.java

+4-5
Original file line numberDiff line numberDiff line change
@@ -42,18 +42,17 @@ private TransactionReceipt getTransactionReceipt(
4242
String transactionHash, long sleepDuration, int attempts)
4343
throws IOException, TransactionException {
4444

45-
Optional<TransactionReceipt> receiptOptional =
46-
(Optional<TransactionReceipt>) sendTransactionReceiptRequest(transactionHash);
45+
Optional<? extends TransactionReceipt> receiptOptional =
46+
sendTransactionReceiptRequest(transactionHash);
4747
for (int i = 0; i < attempts; i++) {
4848
if (!receiptOptional.isPresent()) {
4949
try {
5050
Thread.sleep(sleepDuration);
5151
} catch (InterruptedException e) {
5252
throw new TransactionException(e);
5353
}
54-
receiptOptional =
55-
(Optional<TransactionReceipt>)
56-
sendTransactionReceiptRequest(transactionHash);
54+
55+
receiptOptional = sendTransactionReceiptRequest(transactionHash);
5756
} else {
5857
return receiptOptional.get();
5958
}

0 commit comments

Comments
 (0)