Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

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

Copy link
Copy link
@davidkel

Description

@davidkel
Issue body actions

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)
Reactions are currently unavailable

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      Morty Proxy This is a proxified and sanitized view of the page, visit original site.