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

NullPointerException trying to handle an unannotated return type via contract-api #231

Open
davidkel opened this issue Mar 3, 2022 · 3 comments

Comments

@davidkel
Copy link

davidkel commented Mar 3, 2022

Using 2.2.3LTS using the contract-api I have this method

   @Transaction(submit=false)
    public QueryResponse<String> paginatedRichQuery(Context ctx, String queryString, String pagesize, String passedBookmark) {
        logger.debug("Entering paginatedRichQuery with pagesize [" + pagesize + "] and query string: " + queryString);
        int pageSize = Integer.parseInt(pagesize);

        final QueryResultsIteratorWithMetadata<KeyValue> iterator = ctx.getStub().getQueryResultWithPagination(queryString, pageSize, passedBookmark);
        QueryResponseMetadata metadata = iterator.getMetadata();
        ArrayList<String> results = this.getAllResults(iterator);

        QueryResponse<String> response = new QueryResponse<String>(results.toArray(new String[results.size()]), new ResponseMetadata(metadata));
        logger.debug("Exiting paginatedRichQuery with response: " + response.toString());
        return response;
    }

QueryResponse is defined as follows

public class QueryResponse<T> {
    private T[] results;

    private ResponseMetadata responseMetadata;

    public QueryResponse(T[] results, ResponseMetadata responseMetadata) {
        this.results = results;
        this.responseMetadata = responseMetadata;
    }

    public T[] getResults() {
        return results;
    }

    public void setResults(T[] results) {
        this.results = results;
    }

    public ResponseMetadata getResponseMetadata() {
        return responseMetadata;
    }

    public void setResponseMetadata(ResponseMetadata responseMetadata) {
        this.responseMetadata = responseMetadata;
    }

}

When I invoke the transaction it fails due to trying because of the return value with

Thread[fabric-txinvoke:5,5,main] 12:04:38:330 INFO    org.hyperledger.fabric.contract.ContractRouter processRequest                    Got routing:paginatedRichQuery:org.example.FixedAssetContract
Thread[fabric-txinvoke:5,5,main] 12:04:38:345 SEVERE  org.hyperledger.fabric.Logger error                                              nulljava.lang.NullPointerException
        at org.hyperledger.fabric.contract.execution.JSONTransactionSerializer.toBuffer(JSONTransactionSerializer.java:84)
        at org.hyperledger.fabric.contract.execution.impl.ContractExecutionService.convertReturn(ContractExecutionService.java:89)
        at org.hyperledger.fabric.contract.execution.impl.ContractExecutionService.executeRequest(ContractExecutionService.java:67)
        at org.hyperledger.fabric.contract.ContractRouter.processRequest(ContractRouter.java:119)
        at org.hyperledger.fabric.contract.ContractRouter.invoke(ContractRouter.java:130)
        at org.hyperledger.fabric.shim.impl.ChaincodeInvocationTask.call(ChaincodeInvocationTask.java:100)
        at org.hyperledger.fabric.shim.impl.InvocationTaskManager.lambda$newTask$17(InvocationTaskManager.java:265)
        at java.base/java.util.concurrent.CompletableFuture$AsyncRun.run(CompletableFuture.java:1736)
        at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)
        at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)
        at java.base/java.lang.Thread.run(Thread.java:834)
@llkking
Copy link

llkking commented Jul 27, 2022

also got this problem...actually peer returned the response but org.hyperledger.fabric.contract.execution.JSONTransactionSerializer.toBuffer(JSONTransactionSerializer.java:84) handle response happened a exception.i think maybe it's a bug

@llkking
Copy link

llkking commented Jul 27, 2022

problem solved. cc method return value type should be defined by @datatype

@mbwhite
Copy link
Member

mbwhite commented Sep 26, 2022

Could certainly improve the error message here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants