当我尝试使用txBuilder.toLedgerTransaction(getServiceHub())
时,我得到KotlinNullPointerException的原因是什么?我使用verify()
然后我意识到问题出在toLedgerTransaction()中。当我向State添加新字段时出现此问题。他们有co.paralleluniverse.common.util.Pair
类型,我认为序列化存在一些问题。错误讯息:
"stackTrace": [
{
"methodName": "reportGet",
"fileName": null,
"lineNumber": -1,
"className": "java.util.concurrent.CompletableFuture",
"nativeMethod": false
},
{
"methodName": "get",
"fileName": null,
"lineNumber": -1,
"className": "java.util.concurrent.CompletableFuture",
"nativeMethod": false
},
{
"methodName": "get",
"fileName": "CordaFutureImpl.kt",
"lineNumber": -1,
"className": "net.corda.core.internal.concurrent.CordaFutureImpl",
"nativeMethod": false
},
{
"methodName": "createProject",
"fileName": "ClientHttpApi.java",
"lineNumber": 136,
"className": "com.template.api.ClientHttpApi",
"nativeMethod": false
},
{
"methodName": "invoke0",
"fileName": null,
"lineNumber": -2,
"className": "sun.reflect.NativeMethodAccessorImpl",
"nativeMethod": true
},
{
"methodName": "invoke",
"fileName": null,
"lineNumber": -1,
"className": "sun.reflect.NativeMethodAccessorImpl",
"nativeMethod": false
},
{
"methodName": "invoke",
"fileName": null,
"lineNumber": -1,
"className": "sun.reflect.DelegatingMethodAccessorImpl",
"nativeMethod": false
},
{
"methodName": "invoke",
"fileName": null,
"lineNumber": -1,
"className": "java.lang.reflect.Method",
"nativeMethod": false
},
{
"methodName": "invoke",
"fileName": "ResourceMethodInvocationHandlerFactory.java",
"lineNumber": 81,
"className": "org.glassfish.jersey.server.model.internal.ResourceMethodInvocationHandlerFactory$1",
"nativeMethod": false
},
{
"methodName": "run",
"fileName": "AbstractJavaResourceMethodDispatcher.java",
"lineNumber": 144,
"className": "org.glassfish.jersey.server.model.internal.AbstractJavaResourceMethodDispatcher$1",
"nativeMethod": false
},
{
"methodName": "invoke",
"fileName": "AbstractJavaResourceMethodDispatcher.java",
"lineNumber": 161,
"className": "org.glassfish.jersey.server.model.internal.AbstractJavaResourceMethodDispatcher",
"nativeMethod": false
},
{
"methodName": "doDispatch",
"fileName": "JavaResourceMethodDispatcherProvider.java",
"lineNumber": 160,
"className": "org.glassfish.jersey.server.model.internal.JavaResourceMethodDispatcherProvider$ResponseOutInvoker",
"nativeMethod": false
},
{
"methodName": "dispatch",
"fileName": "AbstractJavaResourceMethodDispatcher.java",
"lineNumber": 99,
"className": "org.glassfish.jersey.server.model.internal.AbstractJavaResourceMethodDispatcher",
"nativeMethod": false
},
{
"methodName": "invoke",
"fileName": "ResourceMethodInvoker.java",
"lineNumber": 389,
"className": "org.glassfish.jersey.server.model.ResourceMethodInvoker",
"nativeMethod": false
},
{
"methodName": "apply",
"fileName": "ResourceMethodInvoker.java",
"lineNumber": 347,
"className": "org.glassfish.jersey.server.model.ResourceMethodInvoker",
"nativeMethod": false
},
{
"methodName": "apply",
"fileName": "ResourceMethodInvoker.java",
"lineNumber": 102,
"className": "org.glassfish.jersey.server.model.ResourceMethodInvoker",
"nativeMethod": false
},
{
"methodName": "run",
"fileName": "ServerRuntime.java",
"lineNumber": 326,
"className": "org.glassfish.jersey.server.ServerRuntime$2",
"nativeMethod": false
},
{
"methodName": "call",
"fileName": "Errors.java",
"lineNumber": 271,
"className": "org.glassfish.jersey.internal.Errors$1",
"nativeMethod": false
},
{
"methodName": "call",
"fileName": "Errors.java",
"lineNumber": 267,
"className": "org.glassfish.jersey.internal.Errors$1",
"nativeMethod": false
},
{
"methodName": "process",
"fileName": "Errors.java",
"lineNumber": 315,
"className": "org.glassfish.jersey.internal.Errors",
"nativeMethod": false
},
{
"methodName": "process",
"fileName": "Errors.java",
"lineNumber": 297,
"className": "org.glassfish.jersey.internal.Errors",
"nativeMethod": false
},
{
"methodName": "process",
"fileName": "Errors.java",
"lineNumber": 267,
"className": "org.glassfish.jersey.internal.Errors",
"nativeMethod": false
},
{
"methodName": "runInScope",
"fileName": "RequestScope.java",
"lineNumber": 317,
"className": "org.glassfish.jersey.process.internal.RequestScope",
"nativeMethod": false
},
{
"methodName": "process",
"fileName": "ServerRuntime.java",
"lineNumber": 305,
"className": "org.glassfish.jersey.server.ServerRuntime",
"nativeMethod": false
},
{
"methodName": "handle",
"fileName": "ApplicationHandler.java",
"lineNumber": 1154,
"className": "org.glassfish.jersey.server.ApplicationHandler",
"nativeMethod": false
},
{
"methodName": "serviceImpl",
"fileName": "WebComponent.java",
"lineNumber": 473,
"className": "org.glassfish.jersey.servlet.WebComponent",
"nativeMethod": false
},
{
"methodName": "service",
"fileName": "WebComponent.java",
"lineNumber": 427,
"className": "org.glassfish.jersey.servlet.WebComponent",
"nativeMethod": false
},
{
"methodName": "service",
"fileName": "ServletContainer.java",
"lineNumber": 388,
"className": "org.glassfish.jersey.servlet.ServletContainer",
"nativeMethod": false
},
{
"methodName": "service",
"fileName": "ServletContainer.java",
"lineNumber": 341,
"className": "org.glassfish.jersey.servlet.ServletContainer",
"nativeMethod": false
},
{
"methodName": "service",
"fileName": "ServletContainer.java",
"lineNumber": 228,
"className": "org.glassfish.jersey.servlet.ServletContainer",
"nativeMethod": false
},
{
"methodName": "handle",
"fileName": "ServletHolder.java",
"lineNumber": 841,
"className": "org.eclipse.jetty.servlet.ServletHolder",
"nativeMethod": false
},
{
"methodName": "doHandle",
"fileName": "ServletHandler.java",
"lineNumber": 535,
"className": "org.eclipse.jetty.servlet.ServletHandler",
"nativeMethod": false
},
{
"methodName": "nextHandle",
"fileName": "ScopedHandler.java",
"lineNumber": 188,
"className": "org.eclipse.jetty.server.handler.ScopedHandler",
"nativeMethod": false
},
{
"methodName": "doHandle",
"fileName": "ContextHandler.java",
"lineNumber": 1253,
"className": "org.eclipse.jetty.server.handler.ContextHandler",
"nativeMethod": false
},
{
"methodName": "nextScope",
"fileName": "ScopedHandler.java",
"lineNumber": 168,
"className": "org.eclipse.jetty.server.handler.ScopedHandler",
"nativeMethod": false
},
{
"methodName": "doScope",
"fileName": "ServletHandler.java",
"lineNumber": 473,
"className": "org.eclipse.jetty.servlet.ServletHandler",
"nativeMethod": false
},
{
"methodName": "nextScope",
"fileName": "ScopedHandler.java",
"lineNumber": 166,
"className": "org.eclipse.jetty.server.handler.ScopedHandler",
"nativeMethod": false
},
{
"methodName": "doScope",
"fileName": "ContextHandler.java",
"lineNumber": 1155,
"className": "org.eclipse.jetty.server.handler.ContextHandler",
"nativeMethod": false
},
{
"methodName": "handle",
"fileName": "ScopedHandler.java",
"lineNumber": 141,
"className": "org.eclipse.jetty.server.handler.ScopedHandler",
"nativeMethod": false
},
{
"methodName": "handle",
"fileName": "HandlerCollection.java",
"lineNumber": 126,
"className": "org.eclipse.jetty.server.handler.HandlerCollection",
"nativeMethod": false
},
{
"methodName": "handle",
"fileName": "HandlerWrapper.java",
"lineNumber": 132,
"className": "org.eclipse.jetty.server.handler.HandlerWrapper",
"nativeMethod": false
},
{
"methodName": "handle",
"fileName": "Server.java",
"lineNumber": 561,
"className": "org.eclipse.jetty.server.Server",
"nativeMethod": false
},
{
"methodName": "handle",
"fileName": "HttpChannel.java",
"lineNumber": 334,
"className": "org.eclipse.jetty.server.HttpChannel",
"nativeMethod": false
},
{
"methodName": "onFillable",
"fileName": "HttpConnection.java",
"lineNumber": 251,
"className": "org.eclipse.jetty.server.HttpConnection",
"nativeMethod": false
},
{
"methodName": "succeeded",
"fileName": "AbstractConnection.java",
"lineNumber": 279,
"className": "org.eclipse.jetty.io.AbstractConnection$ReadCallback",
"nativeMethod": false
},
{
"methodName": "fillable",
"fileName": "FillInterest.java",
"lineNumber": 104,
"className": "org.eclipse.jetty.io.FillInterest",
"nativeMethod": false
},
{
"methodName": "run",
"fileName": "ChannelEndPoint.java",
"lineNumber": 124,
"className": "org.eclipse.jetty.io.ChannelEndPoint$2",
"nativeMethod": false
},
{
"methodName": "runJob",
"fileName": "QueuedThreadPool.java",
"lineNumber": 679,
"className": "org.eclipse.jetty.util.thread.QueuedThreadPool",
"nativeMethod": false
},
{
"methodName": "run",
"fileName": "QueuedThreadPool.java",
"lineNumber": 597,
"className": "org.eclipse.jetty.util.thread.QueuedThreadPool$2",
"nativeMethod": false
},
{
"methodName": "run",
"fileName": null,
"lineNumber": -1,
"className": "java.lang.Thread",
"nativeMethod": false
}
],
"localizedMessage": "kotlin.KotlinNullPointerException: net.corda.core.contracts.TransactionState -> data(net.corda.core.contracts.ContractState) -> null",
"message": "kotlin.KotlinNullPointerException: net.corda.core.contracts.TransactionState -> data(net.corda.core.contracts.ContractState) -> null",
"suppressed": []
堆栈跟踪以CordaRPCOps的流程调用结束,因此它无用。
答案 0 :(得分:0)
我相信您正在实施验证交易的旧语法。在更高版本的Corda中,TransactionBuilder
对象已经可以调用verify()
方法。
例如:
// Build the transaction, add the output state and the command to the transaction.
TransactionBuilder transactionBuilder = new TransactionBuilder(notary)
.addOutputState(output)
.addCommand(new AssetContract.Commands.CreateAsset(),
Arrays.asList(getOurIdentity().getOwningKey())); // Required Signers
// Verify the transaction
transactionBuilder.verify(getServiceHub());