java.lang.noclassdeffounderror反序列化protobuf消息时出错

s71maibg  于 2021-07-13  发布在  Java
关注(0)|答案(1)|浏览(552)

我在dataflow作业中使用protobuf生成的java类来处理消息。我一直在尝试运行一些东西,但是依赖项(jar hell)存在一些问题,导致反序列化失败,出现以下异常:

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文件是用以下配置编译的(使用gradleprotobuf插件)

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无法找到它,这意味着它正在寻找该类的其他实现。是否有我遗漏的东西或我可以用来找出失败的原因/原因的东西?

x33g5p2x

x33g5p2x1#

您似乎将dataflowsdkforjava版本1.5.0与protocolbuffers运行时版本混合在一起 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 ,并包括使用该版本的代码生成工具编译的代码。因此,将其与当前使用的版本进行混合和匹配是相当复杂的。
不幸的是,最好的方法是匹配dataflowsdk使用的版本。希望将来我们能够在数据流方面做得更好——可能在这些库达到完全稳定性和通用性的时候。

相关问题