hyperledger-web3j / web3j

Lightweight Java and Android library for integration with Ethereum clients
https://www.web3labs.com/web3j-sdk
Other
5.12k stars 1.69k forks source link

java.lang.StringIndexOutOfBoundsException: String index out of range: 4544 #449

Closed vipinkp closed 4 years ago

vipinkp commented 6 years ago
`public String getPurchaseOrderForVendor(String contractAddress,String accountAddress, String 
vendorName)
{

    TransactionManager tx = getTransactionManager(accountAddress);
    Tuple3<List<BigInteger>, List<BigInteger>, List<byte[]>> result;
    try
    {

        InvoiceSettlement_sol_InvoiceSettlement dm = InvoiceSettlement_sol_InvoiceSettlement.load(contractAddress, quorum, tx, GAS_PRICE, GAS_LIMIT);
        result = dm.getPurchaseOrderForVendor("name").send();

    } catch (Exception e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    return "somereturnvalue";
}`

web3j v 3.3.1 , solidity 0.4.21.

The error java.lang.StringIndexOutOfBoundsException: String index out of range: 4544 occurs when i am returning a byte[] from a function in solidity. i am using ganache-cli and tested the same code with quorum also.

dave1981 commented 6 years ago

I have a similar problem, I don't know if it's the same problem or not. I wrote a post also in the Ethereum StackExchange (https://ethereum.stackexchange.com/questions/42927/string-returned-from-mapping-of-struct-array) but with no success, my code should work fine... For every transaction, I store some information in this struct:

struct MoneyTransfer{
    address sender;
    string comment;
    uint creationTime;
    uint quantity;
}
struct Transfers {
        MoneyTransfer[] structArray;
      }
mapping(address => Transfers) private moneyTransferMap;

For each address, the first "comment" string returned by the Java wrapper is this one:

"\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000�\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0004"

Another strange thing: after putting another object in the same array, if the first "comment" string was a long one (80 chars), when I try to get the data with the Java wrapper, I get this error:

java.lang.StringIndexOutOfBoundsException: String index out of range: 1952737052 at java.lang.String.substring(Unknown Source) at org.web3j.abi.TypeDecoder.decodeDynamicBytes(TypeDecoder.java:184) at org.web3j.abi.TypeDecoder.decodeUtf8String(TypeDecoder.java:192) at org.web3j.abi.TypeDecoder.decode(TypeDecoder.java:65) at org.web3j.abi.TypeDecoder.decodeArrayElements(TypeDecoder.java:264) at org.web3j.abi.TypeDecoder.decodeDynamicArray(TypeDecoder.java:244) at org.web3j.abi.FunctionReturnDecoder.build(FunctionReturnDecoder.java:105) at org.web3j.abi.FunctionReturnDecoder.decode(FunctionReturnDecoder.java:42) at org.web3j.tx.Contract.executeCall(Contract.java:178) at org.web3j.tx.Contract.executeCallMultipleValueReturn(Contract.java:214)

stale[bot] commented 5 years ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

AlexandrouR commented 4 years ago

@vipinkp is this issue still relevant?

stale[bot] commented 4 years ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

umutmaz commented 3 years ago

any update on this?