在使用serviceComb时, 如果抛出以下异常:
1 org.apache.servicecomb.serviceregistry.consumer.MicroserviceVersions >> Failed to setInstances, appId=hoolink-development, microserviceName=factory-rpc. 2 java.lang.NullPointerException: null 3 at org.apache.servicecomb.swagger.SwaggerUtils.validateSwaggerSwaggerUtils.java:80) 4 at org.apache.servicecomb.core.definition.SchemaUtils.parseSwaggerSchemaUtils.java:49) 5 at org.apache.servicecomb.core.definition.schema.ConsumerSchemaFactory.loadSwaggerConsumerSchemaFactory.java:77) 6 at org.apache.servicecomb.core.definition.schema.ConsumerSchemaFactory.createSchemaConsumerSchemaFactory.java:54) 7 at org.apache.servicecomb.core.definition.schema.ConsumerSchemaFactory.createSchemaConsumerSchemaFactory.java:33) 8 at org.apache.servicecomb.core.definition.schema.AbstractSchemaFactory.getOrCreateSchemaAbstractSchemaFactory.java:65) 9 at org.apache.servicecomb.core.definition.schema.ConsumerSchemaFactory.createConsumerSchemaConsumerSchemaFactory.java:47) 10 at org.apache.servicecomb.core.definition.MicroserviceVersionMeta.<init>MicroserviceVersionMeta.java:40) 11 at org.apache.servicecomb.core.definition.MicroserviceVersionMetaFactory.createMicroserviceVersionMetaFactory.java:38) 12 at org.apache.servicecomb.serviceregistry.consumer.MicroserviceVersions.lambda$setInstances$0MicroserviceVersions.java:182) 13 at java.util.concurrent.ConcurrentHashMap.computeIfAbsentConcurrentHashMap.java:1660) 14 at org.apache.servicecomb.foundation.common.concurrent.ConcurrentHashMapEx.computeIfAbsentConcurrentHashMapEx.java:56) 15 at org.apache.servicecomb.serviceregistry.consumer.MicroserviceVersions.setInstancesMicroserviceVersions.java:180) 16 at org.apache.servicecomb.serviceregistry.consumer.MicroserviceVersions.safeSetInstancesMicroserviceVersions.java:160) 17 at org.apache.servicecomb.serviceregistry.consumer.MicroserviceVersions.pullInstancesMicroserviceVersions.java:155) 18 at org.apache.servicecomb.serviceregistry.consumer.MicroserviceVersions.submitPullMicroserviceVersions.java:127) 19 at org.apache.servicecomb.serviceregistry.consumer.MicroserviceManager.lambda$getOrCreateMicroserviceVersions$0MicroserviceManager.java:55) 20 at java.util.concurrent.ConcurrentHashMap.computeIfAbsentConcurrentHashMap.java:1660) 21 at org.apache.servicecomb.foundation.common.concurrent.ConcurrentHashMapEx.computeIfAbsentConcurrentHashMapEx.java:56) 22 at org.apache.servicecomb.serviceregistry.consumer.MicroserviceManager.getOrCreateMicroserviceVersionsMicroserviceManager.java:53) 23 at org.apache.servicecomb.serviceregistry.consumer.MicroserviceManager.getOrCreateMicroserviceVersionRuleMicroserviceManager.java:79) 24 at org.apache.servicecomb.serviceregistry.consumer.AppManager.getOrCreateMicroserviceVersionRuleAppManager.java:59) 25 at org.apache.servicecomb.edge.core.EdgeInvocation.findMicroserviceVersionMetaEdgeInvocation.java:85) 26 at org.apache.servicecomb.edge.core.EdgeInvocation.edgeInvokeEdgeInvocation.java:68) 27 at com.hoolink.gateway.build.dispatcher.ApiDispatcher.onRequestApiDispatcher.java:98) 28 at io.vertx.ext.web.impl.RouteImpl.handleContextRouteImpl.java:223) 29 at io.vertx.ext.web.impl.RoutingContextImplBase.iterateNextRoutingContextImplBase.java:101) 30 at io.vertx.ext.web.impl.RoutingContextImpl.nextRoutingContextImpl.java:120) 31 at org.apache.servicecomb.transport.rest.vertx.RestBodyHandler$BHandler.doEndRestBodyHandler.java:248) 32 at org.apache.servicecomb.transport.rest.vertx.RestBodyHandler$BHandler.endRestBodyHandler.java:226) 33 at org.apache.servicecomb.transport.rest.vertx.RestBodyHandler.lambda$handle$0RestBodyHandler.java:86) 34 at io.vertx.core.http.impl.HttpServerRequestImpl.handleEndHttpServerRequestImpl.java:418) 35 at io.vertx.core.http.impl.ServerConnection.handleLastHttpContentServerConnection.java:475) 36 at io.vertx.core.http.impl.ServerConnection.handleContentServerConnection.java:469) 37 at io.vertx.core.http.impl.ServerConnection.processMessageServerConnection.java:449) 38 at io.vertx.core.http.impl.ServerConnection.handleMessageServerConnection.java:156) 39 at io.vertx.core.http.impl.HttpServerImpl$ServerHandlerWithWebSockets.handleMessageHttpServerImpl.java:705) 40 at io.vertx.core.http.impl.HttpServerImpl$ServerHandlerWithWebSockets.handleMessageHttpServerImpl.java:614) 41 at io.vertx.core.net.impl.VertxHandler.lambda$channelRead$1VertxHandler.java:150) 42 at io.vertx.core.impl.ContextImpl.lambda$wrapTask$2ContextImpl.java:342) 43 at io.vertx.core.impl.ContextImpl.executeFromIOContextImpl.java:200) 44 at io.vertx.core.net.impl.VertxHandler.channelReadVertxHandler.java:148) 45 at io.netty.channel.AbstractChannelHandlerContext.invokeChannelReadAbstractChannelHandlerContext.java:362) 46 at io.netty.channel.AbstractChannelHandlerContext.invokeChannelReadAbstractChannelHandlerContext.java:348) 47 at io.netty.channel.AbstractChannelHandlerContext.fireChannelReadAbstractChannelHandlerContext.java:340) 48 at io.netty.handler.timeout.IdleStateHandler.channelReadIdleStateHandler.java:286) 49 at io.netty.channel.AbstractChannelHandlerContext.invokeChannelReadAbstractChannelHandlerContext.java:362) 50 at io.netty.channel.AbstractChannelHandlerContext.invokeChannelReadAbstractChannelHandlerContext.java:348) 51 at io.netty.channel.AbstractChannelHandlerContext.fireChannelReadAbstractChannelHandlerContext.java:340) 52 at io.netty.handler.codec.ByteToMessageDecoder.fireChannelReadByteToMessageDecoder.java:310) 53 at io.netty.handler.codec.ByteToMessageDecoder.channelReadByteToMessageDecoder.java:284) 54 at io.netty.channel.AbstractChannelHandlerContext.invokeChannelReadAbstractChannelHandlerContext.java:362) 55 at io.netty.channel.AbstractChannelHandlerContext.invokeChannelReadAbstractChannelHandlerContext.java:348) 56 at io.netty.channel.AbstractChannelHandlerContext.fireChannelReadAbstractChannelHandlerContext.java:340) 57 at io.vertx.core.http.impl.Http1xOrH2CHandler.endHttp1xOrH2CHandler.java:49) 58 at io.vertx.core.http.impl.Http1xOrH2CHandler.channelReadHttp1xOrH2CHandler.java:27) 59 at io.netty.channel.AbstractChannelHandlerContext.invokeChannelReadAbstractChannelHandlerContext.java:362) 60 at io.netty.channel.AbstractChannelHandlerContext.invokeChannelReadAbstractChannelHandlerContext.java:348) 61 at io.netty.channel.AbstractChannelHandlerContext.fireChannelReadAbstractChannelHandlerContext.java:340) 62 at io.netty.handler.timeout.IdleStateHandler.channelReadIdleStateHandler.java:286) 63 at io.netty.channel.AbstractChannelHandlerContext.invokeChannelReadAbstractChannelHandlerContext.java:362) 64 at io.netty.channel.AbstractChannelHandlerContext.invokeChannelReadAbstractChannelHandlerContext.java:348) 65 at io.netty.channel.AbstractChannelHandlerContext.fireChannelReadAbstractChannelHandlerContext.java:340) 66 at io.netty.channel.DefaultChannelPipeline$HeadContext.channelReadDefaultChannelPipeline.java:1434) 67 at io.netty.channel.AbstractChannelHandlerContext.invokeChannelReadAbstractChannelHandlerContext.java:362) 68 at io.netty.channel.AbstractChannelHandlerContext.invokeChannelReadAbstractChannelHandlerContext.java:348) 69 at io.netty.channel.DefaultChannelPipeline.fireChannelReadDefaultChannelPipeline.java:965) 70 at io.netty.channel.nio.AbstractNioByteChannel$NioByteUnsafe.readAbstractNioByteChannel.java:163) 71 at io.netty.channel.nio.NioEventLoop.processSelectedKeyNioEventLoop.java:645) 72 at io.netty.channel.nio.NioEventLoop.processSelectedKeysOptimizedNioEventLoop.java:580) 73 at io.netty.channel.nio.NioEventLoop.processSelectedKeysNioEventLoop.java:497) 74 at io.netty.channel.nio.NioEventLoop.runNioEventLoop.java:459) 75 at io.netty.util.concurrent.SingleThreadEventExecutor$5.runSingleThreadEventExecutor.java:884) 76 at io.netty.util.concurrent.FastThreadLocalRunnable.runFastThreadLocalRunnable.java:30) 77 at java.lang.Thread.runThread.java:748)
此堆栈信息表示在factory-rpc中有空的controller
所谓空的controller指的是: 该controller中没有任何方法
当SwaggerUtils中的validateSwagger方法扫描到该controller,
然后通过swagger.getPaths)方法获取该controller中的函数
由于controller中没有方法, 所以paths为null, 再使用paths.values), 就会出现空指针
1 public static void validateSwaggerSwagger swagger) { 2 Map<String, Path> paths = swagger.getPaths); 3 for Path path : paths.values)) { 4 Operation operation = path.getPost); 5 if operation != null) { 6 List<Parameter> parameters = operation.getParameters); 7 for Parameter parameter : parameters) { 8 if BodyParameter.class.isInstanceparameter)) { 9 if BodyParameter) parameter).getSchema) == null) { 10 throw new ServiceCombException"swagger validator: body parameter schema is empty."); 11 } 12 } 13 } 14 } 15 } 16 }
