gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-29 04:48:40 26 4
gpt4 key购买 nike

我在我的数据流作业中使用 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 文件是使用以下配置编译的(使用 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.5.0 版 Java 数据流 SDK 与 Protocol Buffers 运行时版本 3.0.0-beta-2 和 gRPC 版本 0.13.2 混合使用.

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

Dataflow SDK for Java,版本 1.5.0,依赖于 Protocol Buffers 版本 3.0.0-beta-1 和 gRPC 版本 0.12.0,并包含以下代码使用该版本的代码生成工具编译。因此,将其与您当前使用的版本混合搭配会非常复杂。

不幸的是,最好的方法是匹配 Dataflow SDK 正在使用的版本。希望我们将来能够在 Dataflow 方面做得更好——可能在这些库达到完全稳定性和普遍可用性的时候。

关于反序列化 protobuf 消息时出现 java.lang.NoClassDefFoundError,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36257708/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com