diff --git a/README.rst b/README.rst
index 7cc7e8923..45ead7dbf 100644
--- a/README.rst
+++ b/README.rst
@@ -85,7 +85,7 @@ Java 8:
org.web3j
core
- 2.2.1
+ 2.2.2
Android:
@@ -105,7 +105,7 @@ Java 8:
.. code-block:: groovy
- compile ('org.web3j:core:2.2.1')
+ compile ('org.web3j:core:2.2.2')
Android:
diff --git a/build.gradle b/build.gradle
index 369f653b2..e7844c2d8 100644
--- a/build.gradle
+++ b/build.gradle
@@ -29,7 +29,7 @@ apply plugin: 'application'
apply plugin: 'checkstyle'
group 'org.web3j'
-version '2.2.1'
+version '2.2.2'
sourceCompatibility = 1.8
diff --git a/docs/source/getting_started.rst b/docs/source/getting_started.rst
index c62bd8400..2ee91a4e4 100644
--- a/docs/source/getting_started.rst
+++ b/docs/source/getting_started.rst
@@ -13,7 +13,7 @@ Java 8:
org.web3j
core
- 2.2.1
+ 2.2.2
Android:
@@ -33,7 +33,7 @@ Java 8:
.. code-block:: groovy
- compile ('org.web3j:core:2.2.1')
+ compile ('org.web3j:core:2.2.2')
Android:
diff --git a/src/main/java/org/web3j/tx/Contract.java b/src/main/java/org/web3j/tx/Contract.java
index 6254c8166..26432ea55 100644
--- a/src/main/java/org/web3j/tx/Contract.java
+++ b/src/main/java/org/web3j/tx/Contract.java
@@ -170,7 +170,11 @@ protected CompletableFuture> executeCallMultipleValueReturnAsync(
protected T executeCallSingleValueReturn(
Function function) throws InterruptedException, ExecutionException {
List values = executeCall(function);
- return (T) values.get(0);
+ if (!values.isEmpty()) {
+ return (T) values.get(0);
+ } else {
+ return null;
+ }
}
protected List executeCallMultipleValueReturn(
diff --git a/src/test/java/org/web3j/tx/ContractTest.java b/src/test/java/org/web3j/tx/ContractTest.java
index a177750db..938ee9ac9 100644
--- a/src/test/java/org/web3j/tx/ContractTest.java
+++ b/src/test/java/org/web3j/tx/ContractTest.java
@@ -40,6 +40,7 @@
import static org.hamcrest.CoreMatchers.equalTo;
import static org.hamcrest.CoreMatchers.is;
import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertThat;
import static org.junit.Assert.assertTrue;
import static org.mockito.Matchers.any;
@@ -147,6 +148,17 @@ public void testCallSingleValue() throws Exception {
assertThat(contract.callSingleValue().get(), equalTo(new Utf8String("")));
}
+ @Test
+ public void testCallSingleValueEmpty() throws Exception {
+ // Example taken from FunctionReturnDecoderTest
+
+ EthCall ethCall = new EthCall();
+ ethCall.setResult("0x");
+ prepareCall(ethCall);
+
+ assertNull(contract.callSingleValue().get());
+ }
+
@Test
public void testCallMultipleValue() throws Exception {
EthCall ethCall = new EthCall();
@@ -160,6 +172,16 @@ public void testCallMultipleValue() throws Exception {
new Uint256(BigInteger.valueOf(7)))));
}
+ @Test
+ public void testCallMultipleValueEmpty() throws Exception {
+ EthCall ethCall = new EthCall();
+ ethCall.setResult("0x");
+ prepareCall(ethCall);
+
+ assertThat(contract.callMultipleValue().get(),
+ equalTo(Collections.emptyList()));
+ }
+
private void prepareCall(EthCall ethCall) {
Request request = mock(Request.class);
when(request.sendAsync()).thenReturn(Async.run(() -> ethCall));