反序列化protobuf消息时的java.lang.NoClassDefFoundError

时间:2016-03-28 07:13:22

标签: java google-cloud-dataflow protocol-buffers

我在我的数据流作业中使用protobuf生成的java类用于消息。我一直试图让事情运行但是依赖性(jar地狱)存在一些问题,导致反序列化失败并出现以下异常:

java.lang.NoClassDefFoundError: Could not initialize class com.brightcove.rna.model.Metadata$MetadataDefaultEntryHolder
    at com.brightcove.rna.model.Metadata.(Metadata.java:50)
    at com.brightcove.rna.model.Metadata.(Metadata.java:13)
    at com.brightcove.rna.model.Metadata$1.parsePartialFrom(Metadata.java:444)
    at com.brightcove.rna.model.Metadata$1.parsePartialFrom(Metadata.java:438)
    at com.google.protobuf.CodedInputStream.readMessage(CodedInputStream.java:495)
    at com.brightcove.rna.model.Row.(Row.java:79)
    at com.brightcove.rna.model.Row.(Row.java:13)
    at com.brightcove.rna.model.Row$1.parsePartialFrom(Row.java:987)
    at com.brightcove.rna.model.Row$1.parsePartialFrom(Row.java:981)
    at com.google.protobuf.AbstractParser.parsePartialFrom(AbstractParser.java:192)
    at com.google.protobuf.AbstractParser.parseFrom(AbstractParser.java:210)
    at com.google.protobuf.AbstractParser.parseFrom(AbstractParser.java:49)
    at com.google.cloud.dataflow.sdk.coders.protobuf.ProtoCoder.decode(ProtoCoder.java:198)
    at com.google.cloud.dataflow.sdk.coders.protobuf.ProtoCoder.decode(ProtoCoder.java:114)
    at com.google.cloud.dataflow.sdk.runners.worker.WindmillKeyedWorkItem$3.apply(WindmillKeyedWorkItem.java:144)
    at com.google.cloud.dataflow.sdk.runners.worker.WindmillKeyedWorkItem$3.apply(WindmillKeyedWorkItem.java:133)
    at com.google.cloud.dataflow.worker.repackaged.com.google.common.collect.Iterators$8.transform(Iterators.java:817)
    at com.google.cloud.dataflow.worker.repackaged.com.google.common.collect.TransformedIterator.next(TransformedIterator.java:48)
    at com.google.cloud.dataflow.sdk.repackaged.com.google.common.collect.TransformedIterator.next(TransformedIterator.java:48)
    at com.google.cloud.dataflow.sdk.repackaged.com.google.common.collect.TransformedIterator.next(TransformedIterator.java:48)
    at com.google.cloud.dataflow.sdk.repackaged.com.google.common.collect.Iterators$5.hasNext(Iterators.java:569)
    at com.google.cloud.dataflow.sdk.repackaged.com.google.common.collect.Iterators$7.computeNext(Iterators.java:673)
    at com.google.cloud.dataflow.sdk.repackaged.com.google.common.collect.AbstractIterator.tryToComputeNext(AbstractIterator.java:143)
    at com.google.cloud.dataflow.sdk.repackaged.com.google.common.collect.AbstractIterator.hasNext(AbstractIterator.java:138)
    at com.google.cloud.dataflow.sdk.util.ReduceFnRunner.processElements(ReduceFnRunner.java:281)
    at com.google.cloud.dataflow.sdk.util.GroupAlsoByWindowViaWindowSetDoFn.processElement(GroupAlsoByWindowViaWindowSetDoFn.java:83)
    at com.google.cloud.dataflow.sdk.util.SimpleDoFnRunner.invokeProcessElement(SimpleDoFnRunner.java:49)
    at com.google.cloud.dataflow.sdk.util.DoFnRunnerBase.processElement(DoFnRunnerBase.java:138)
    at com.google.cloud.dataflow.sdk.util.LateDataDroppingDoFnRunner.processElement(LateDataDroppingDoFnRunner.java:67)
    at com.google.cloud.dataflow.sdk.runners.worker.SimpleParDoFn.processElement(SimpleParDoFn.java:191)
    at com.google.cloud.dataflow.sdk.runners.worker.ForwardingParDoFn.processElement(ForwardingParDoFn.java:42)
    at com.google.cloud.dataflow.sdk.runners.worker.DataflowWorkerLoggingParDoFn.processElement(DataflowWorkerLoggingParDoFn.java:47)
    at com.google.cloud.dataflow.sdk.util.common.worker.ParDoOperation.process(ParDoOperation.java:53)
    at com.google.cloud.dataflow.sdk.util.common.worker.OutputReceiver.process(OutputReceiver.java:52)
    at com.google.cloud.dataflow.sdk.util.common.worker.ReadOperation.runReadLoop(ReadOperation.java:223)
    at com.google.cloud.dataflow.sdk.util.common.worker.ReadOperation.start(ReadOperation.java:169)
    at com.google.cloud.dataflow.sdk.util.common.worker.MapTaskExecutor.execute(MapTaskExecutor.java:69)
    at com.google.cloud.dataflow.sdk.runners.worker.StreamingDataflowWorker.process(StreamingDataflowWorker.java:645)
    at com.google.cloud.dataflow.sdk.runners.worker.StreamingDataflowWorker.access$500(StreamingDataflowWorker.java:86)
    at com.google.cloud.dataflow.sdk.runners.worker.StreamingDataflowWorker$6.run(StreamingDataflowWorker.java:488)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
    at java.lang.Thread.run(Thread.java:745)

我在gradle项目中使用以下依赖项:

compile 'com.google.cloud.dataflow:google-cloud-dataflow-java-sdk-all:1.5.0'
compile 'com.google.protobuf:protobuf-java:3.0.0-beta-2'
compile 'io.grpc:grpc-all:0.13.2'

使用以下配置编译protobuf文件(使用gradle protobuf插件)

protobuf {
    protoc {
        artifact = 'com.google.protobuf:protoc:3.0.0-beta-2'
    }
    plugins {
        grpc {
            artifact = 'io.grpc:protoc-gen-grpc-java:0.13.2'
        }
    }
    generateProtoTasks {
        all()*.plugins {
            grpc {}
        }
    }
}

更新

找到一个可能有用的堆栈跟踪:

java.lang.NoSuchMethodError: com.google.protobuf.DescriptorProtos$FieldDescriptorProto.hasJsonName()Z
at com.google.protobuf.Descriptors$FieldDescriptor.<init>(Descriptors.java:1208)
at com.google.protobuf.Descriptors$FieldDescriptor.<init>(Descriptors.java:867)
at com.google.protobuf.Descriptors$Descriptor.<init>(Descriptors.java:804)
at com.google.protobuf.Descriptors$Descriptor.<init>(Descriptors.java:568)
at com.google.protobuf.Descriptors$FileDescriptor.<init>(Descriptors.java:474)
at com.google.protobuf.Descriptors$FileDescriptor.buildFrom(Descriptors.java:290)
at com.google.protobuf.Descriptors$FileDescriptor.internalBuildGeneratedFileFrom(Descriptors.java:336)
at com.brightcove.rna.model.Messages.<clinit>(Messages.java:133)
at com.brightcove.rna.model.DimensionSet$Builder.getDescriptorForType(DimensionSet.java:897)
at com.brightcove.rna.model.TransformEvents.populateMessage(TransformEvents.java:28)
at com.brightcove.rna.transforms.StreamingAdditions$1.processElement(StreamingAdditions.java:46)
at com.google.cloud.dataflow.sdk.util.SimpleDoFnRunner.invokeProcessElement(SimpleDoFnRunner.java:49)
at com.google.cloud.dataflow.sdk.util.DoFnRunnerBase.processElement(DoFnRunnerBase.java:138)
at com.google.cloud.dataflow.sdk.runners.worker.SimpleParDoFn.processElement(SimpleParDoFn.java:191)
at com.google.cloud.dataflow.sdk.runners.worker.ForwardingParDoFn.processElement(ForwardingParDoFn.java:42)
at com.google.cloud.dataflow.sdk.runners.worker.DataflowWorkerLoggingParDoFn.processElement(DataflowWorkerLoggingParDoFn.java:47)
at com.google.cloud.dataflow.sdk.util.common.worker.ParDoOperation.process(ParDoOperation.java:53)
at com.google.cloud.dataflow.sdk.util.common.worker.OutputReceiver.process(OutputReceiver.java:52)
at com.google.cloud.dataflow.sdk.runners.worker.SimpleParDoFn$1.output(SimpleParDoFn.java:161)
at com.google.cloud.dataflow.sdk.util.DoFnRunnerBase$DoFnContext.outputWindowedValue(DoFnRunnerBase.java:288)
at com.google.cloud.dataflow.sdk.util.DoFnRunnerBase$DoFnContext.outputWindowedValue(DoFnRunnerBase.java:284)
at com.google.cloud.dataflow.sdk.util.DoFnRunnerBase$DoFnProcessContext.outputWithTimestamp(DoFnRunnerBase.java:456)
at com.brightcove.rna.transforms.functions.ExtractRawLog.processElement(ExtractRawLog.java:35)
at com.google.cloud.dataflow.sdk.util.SimpleDoFnRunner.invokeProcessElement(SimpleDoFnRunner.java:49)
at com.google.cloud.dataflow.sdk.util.DoFnRunnerBase.processElement(DoFnRunnerBase.java:138)
at com.google.cloud.dataflow.sdk.runners.worker.SimpleParDoFn.processElement(SimpleParDoFn.java:191)
at com.google.cloud.dataflow.sdk.runners.worker.ForwardingParDoFn.processElement(ForwardingParDoFn.java:42)
at com.google.cloud.dataflow.sdk.runners.worker.DataflowWorkerLoggingParDoFn.processElement(DataflowWorkerLoggingParDoFn.java:47)
at com.google.cloud.dataflow.sdk.util.common.worker.ParDoOperation.process(ParDoOperation.java:53)
at com.google.cloud.dataflow.sdk.util.common.worker.OutputReceiver.process(OutputReceiver.java:52)
at com.google.cloud.dataflow.sdk.runners.worker.SimpleParDoFn$1.output(SimpleParDoFn.java:161)
at com.google.cloud.dataflow.sdk.util.DoFnRunnerBase$DoFnContext.outputWindowedValue(DoFnRunnerBase.java:288)
at com.google.cloud.dataflow.sdk.util.DoFnRunnerBase$DoFnProcessContext.output(DoFnRunnerBase.java:450)
at com.google.cloud.dataflow.sdk.transforms.FlatMapElements$3.processElement(FlatMapElements.java:140)
at com.google.cloud.dataflow.sdk.util.SimpleDoFnRunner.invokeProcessElement(SimpleDoFnRunner.java:49)
at com.google.cloud.dataflow.sdk.util.DoFnRunnerBase.processElement(DoFnRunnerBase.java:138)
at com.google.cloud.dataflow.sdk.runners.worker.SimpleParDoFn.processElement(SimpleParDoFn.java:191)
at com.google.cloud.dataflow.sdk.runners.worker.ForwardingParDoFn.processElement(ForwardingParDoFn.java:42)
at com.google.cloud.dataflow.sdk.runners.worker.DataflowWorkerLoggingParDoFn.processElement(DataflowWorkerLoggingParDoFn.java:47)
at com.google.cloud.dataflow.sdk.util.common.worker.ParDoOperation.process(ParDoOperation.java:53)
at com.google.cloud.dataflow.sdk.util.common.worker.OutputReceiver.process(OutputReceiver.java:52)
at com.google.cloud.dataflow.sdk.runners.worker.SimpleParDoFn$1.output(SimpleParDoFn.java:161)
at com.google.cloud.dataflow.sdk.util.DoFnRunnerBase$DoFnContext.outputWindowedValue(DoFnRunnerBase.java:288)
at com.google.cloud.dataflow.sdk.util.DoFnRunnerBase$DoFnProcessContext.output(DoFnRunnerBase.java:450)
at com.brightcove.rna.transforms.functions.DecompressDataFn.processElement(DecompressDataFn.java:19)
at com.google.cloud.dataflow.sdk.util.SimpleDoFnRunner.invokeProcessElement(SimpleDoFnRunner.java:49)
at com.google.cloud.dataflow.sdk.util.DoFnRunnerBase.processElement(DoFnRunnerBase.java:138)
at com.google.cloud.dataflow.sdk.runners.worker.SimpleParDoFn.processElement(SimpleParDoFn.java:191)
at com.google.cloud.dataflow.sdk.runners.worker.ForwardingParDoFn.processElement(ForwardingParDoFn.java:42)
at com.google.cloud.dataflow.sdk.runners.worker.DataflowWorkerLoggingParDoFn.processElement(DataflowWorkerLoggingParDoFn.java:47)
at com.google.cloud.dataflow.sdk.util.common.worker.ParDoOperation.process(ParDoOperation.java:53)
at com.google.cloud.dataflow.sdk.util.common.worker.OutputReceiver.process(OutputReceiver.java:52)
at com.google.cloud.dataflow.sdk.util.common.worker.ReadOperation.runReadLoop(ReadOperation.java:223)
at com.google.cloud.dataflow.sdk.util.common.worker.ReadOperation.start(ReadOperation.java:169)
at com.google.cloud.dataflow.sdk.util.common.worker.MapTaskExecutor.execute(MapTaskExecutor.java:69)
at com.google.cloud.dataflow.sdk.runners.worker.StreamingDataflowWorker.process(StreamingDataflowWorker.java:645)
at com.google.cloud.dataflow.sdk.runners.worker.StreamingDataflowWorker.access$500(StreamingDataflowWorker.java:86)
at com.google.cloud.dataflow.sdk.runners.worker.StreamingDataflowWorker$6.run(StreamingDataflowWorker.java:488)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at java.lang.Thread.run(Thread.java:745)

我检查了java.lang.NoSuchMethodError的源代码:com.google.protobuf.DescriptorProtos $ FieldDescriptorProto.hasJsonName()Z  它肯定是hasJsonName()方法。出于某种原因,java无法找到它,这意味着它正在查看该类的其他一些实现。是否有我遗漏的东西或我可以用来找出导致失败的原因/原因的东西?

1 个答案:

答案 0 :(得分:3)

您似乎将Dataflow SDK for Java版本1.5.0与Protocol Buffers运行时版本3.0.0-beta-2和gRPC版本0.13.2混合在一起。

一般来说,协议缓冲区和gRPC目前都不保证兼容性:您必须使用与编译时使用的代码生成工具版本完全匹配的运行时。此外,您通常只能在Java类路径上拥有一个版本。

Dataflow SDK for Java,版本1.5.0,取决于协议缓冲区版本3.0.0-beta-1和gRPC版本0.12.0,并包含使用该版本的代码生成工具编译的代码。因此,将它与您当前使用的版本混合搭配会非常复杂。

遗憾的是,最佳路径是匹配Dataflow SDK正在使用的版本。希望我们将来能够在Dataflow中做得更好 - 可能在这些库达到完全稳定性和普遍可用性的时候。