Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Exception when pass empty list to the smart contract #733

Closed
Hirama opened this Issue Oct 10, 2018 · 2 comments

Comments

Projects
None yet
6 participants
@Hirama
Copy link

Hirama commented Oct 10, 2018

Contract with function addAddresses(address point, address[] list) external;

When I try to execute contract method.

public RemoteCall<TransactionReceipt> addAddresses(String point, List<String> list) {
        final Function function = new Function(
                FUNC_ADDADDRESSES, 
                Arrays.<Type>asList(new Address(point),
                new DynamicArray<Address>(
                        org.web3j.abi.Utils.typeMap(list, Address.class))),
                Collections.<TypeReference<?>>emptyList());
        return executeRemoteCallTransaction(function);
    }

I got exception java.lang.IndexOutOfBoundsException: Index: 0, Size: 0

image
Problem is in this part of the code when trying to get the type from the first element of the empty list.

@MarkOSullivan94

This comment has been minimized.

Copy link
Contributor

MarkOSullivan94 commented Oct 13, 2018

@Hirama curious what you are wanting done here

@iikirilov iikirilov added the bug label Nov 8, 2018

@iikirilov

This comment has been minimized.

Copy link
Member

iikirilov commented Nov 9, 2018

Considering the Arrays.sol contract in web3j-codegen there is a method:

    function dynamicReverse(uint[] input) public pure returns (uint[] result) {
        uint length = input.length;
        result = new uint[](length);

        for (uint i = 0; i < length; i++) {
            result[i] = input[length - (i + 1)];
        }
        return result;
    }

The web3j generator will generate:

    public RemoteCall<List> dynamicReverse(List<BigInteger> input) {
        final Function function = new Function(FUNC_DYNAMICREVERSE, 
                java.util.Arrays.<Type>asList(new org.web3j.abi.datatypes.DynamicArray<org.web3j.abi.datatypes.generated.Uint256>(
                        org.web3j.abi.Utils.typeMap(input, org.web3j.abi.datatypes.generated.Uint256.class))), 
                java.util.Arrays.<TypeReference<?>>asList(new TypeReference<DynamicArray<Uint256>>() {}));
        return new RemoteCall<List>(
                new Callable<List>() {
                    @Override
                    @SuppressWarnings("unchecked")
                    public List call() throws Exception {
                        List<Type> result = (List<Type>) executeCallSingleValueReturn(function, List.class);
                        return convertToNative(result);
                    }
                });
    }

If one was to call arrays.dynamicReverse(new Arraylist<BigInteger>()) web3j will complain.
The DynamicArray constructor is called:

    public DynamicArray(List<T> values) {
        super(values.get(0).getTypeAsString() + "[]", values);
    }

As the list is empty we should get the type of the list via reflection?

xaviarias added a commit to xaviarias/web3j that referenced this issue Nov 22, 2018

xaviarias added a commit to xaviarias/web3j that referenced this issue Nov 22, 2018

xaviarias added a commit to xaviarias/web3j that referenced this issue Nov 22, 2018

xaviarias added a commit to xaviarias/web3j that referenced this issue Nov 22, 2018

xaviarias added a commit to xaviarias/web3j that referenced this issue Nov 22, 2018

xaviarias added a commit to xaviarias/web3j that referenced this issue Nov 22, 2018

xaviarias added a commit to xaviarias/web3j that referenced this issue Nov 22, 2018

@snazha-blkio snazha-blkio added this to the 4.1.x milestone Jan 18, 2019

xaviarias added a commit to xaviarias/web3j that referenced this issue Jan 18, 2019

xaviarias added a commit to xaviarias/web3j that referenced this issue Jan 18, 2019

xaviarias added a commit to xaviarias/web3j that referenced this issue Jan 18, 2019

xaviarias added a commit to xaviarias/web3j that referenced this issue Jan 18, 2019

xaviarias added a commit to xaviarias/web3j that referenced this issue Jan 18, 2019

xaviarias added a commit to xaviarias/web3j that referenced this issue Jan 18, 2019

xaviarias added a commit to xaviarias/web3j that referenced this issue Jan 18, 2019

xaviarias added a commit to xaviarias/web3j that referenced this issue Jan 18, 2019

web3j#733 Fix array issues
 * Make StaticArray abstract to be consistent with array model
 * Make static array value getter unmodifiable to prevent unwanted changes
 * Make Array.getTypeAsString abstract to make subclasses explicit
 * Remove zero-length check as static arrays will prevent it explicitly

snazha-blkio added a commit that referenced this issue Feb 10, 2019

Merge pull request #796 from xaviarias/issue-733-empy-arrays
Fix for isse #733 Add explicit component type in constructors

snazha-blkio added a commit that referenced this issue Mar 7, 2019

snazha-blkio added a commit that referenced this issue Mar 7, 2019

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.