Skip to content

Commit 8b17a52

Browse files
Support Proto 3 and 4 (#2383)
Support Proto 3 and 4
1 parent c51e5d1 commit 8b17a52

File tree

22 files changed

+61
-50
lines changed

22 files changed

+61
-50
lines changed

README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,12 @@ or to *build.gradle*:
3838

3939
compile group: 'io.temporal', name: 'temporal-sdk', version: 'N.N.N'
4040

41+
## Protobuf 3.x vs 4.x
42+
43+
The Temporal Java SDK currently supports `protobuf-java` 3.x and 4.x. To support these, the Temporal Java SDK allows any protobuf library >= 3.25.
44+
Temporal strongly recommends using the latest `protobuf-java` 4.x library unless you absolutely cannot.
45+
If you cannot use protobuf-java 3.25 >=, you can try `temporal-shaded` which includes a shaded version of the `protobuf-java` library.
46+
4147
## Contributing
4248

4349
We'd love your help in improving the Temporal Java SDK. Please review our [contribution guidelines](CONTRIBUTING.md).

build.gradle

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ buildscript {
55
}
66

77
plugins {
8-
id 'net.ltgt.errorprone' version '4.0.1' apply false
8+
id 'net.ltgt.errorprone' version '4.1.0' apply false
99
id 'org.cadixdev.licenser' version '0.6.1'
1010
id 'com.palantir.git-version' version "${palantirGitVersionVersion}" apply false
1111
id 'io.github.gradle-nexus.publish-plugin' version '1.3.0'
@@ -29,7 +29,7 @@ allprojects {
2929

3030
ext {
3131
// Platforms
32-
grpcVersion = '1.54.1' // [1.38.0,) Needed for io.grpc.protobuf.services.HealthStatusManager
32+
grpcVersion = '1.58.1' // [1.38.0,) Needed for io.grpc.protobuf.services.HealthStatusManager
3333
jacksonVersion = '2.14.2' // [2.9.0,)
3434
nexusVersion = '0.3.0-alpha'
3535
// we don't upgrade to 1.10.x because it requires kotlin 1.6. Users may use 1.10.x in their environments though.
@@ -38,12 +38,13 @@ ext {
3838
// stay on 1.x for a while to don't use any APIs from 2.x which may break our users which still stay on 1.x
3939
// also slf4j 2.x is not compatible with spring boot 2.x
4040
slf4jVersion = project.hasProperty("edgeDepsTest") ? '2.0.16' : '1.7.36' // [1.4.0,)
41-
// [3.12.0,)
42-
// 3.12 is brought by min gRPC 1.38.
43-
// We can't move pass 3.22.0 because 3.22.2 deprecates some methods used by generated code produced by
44-
// the old protoc we keep for compatibility of our generated code with old protobuf-java versions.
45-
// Which leads to build failure because of -Werror.
46-
protoVersion = '3.22.0'
41+
// [3.25.5,)
42+
// 3.25.5 is required because of our protoc compiler 25.x. The proto version must be the same or greater then the protoc version.
43+
// We use this version of protoc because it will generate code that is compatible with protobuf-java 3.x and 4.x.
44+
// We don't move past 3.25.x because the next version is a major version bump and we don't want to break our users.
45+
//
46+
// For more information see: https://github.com/grpc/grpc-java/issues/11015#issuecomment-2560196695
47+
protoVersion = '3.25.5'
4748
annotationApiVersion = '1.3.2'
4849
guavaVersion = '32.0.1-jre' // [10.0,)
4950
tallyVersion = '0.13.0' // [0.4.0,)

temporal-sdk/build.gradle

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,10 @@ dependencies {
2929
testImplementation "org.mockito:mockito-core:${mockitoVersion}"
3030
testImplementation 'pl.pragmatists:JUnitParams:1.1.1'
3131
testImplementation group: 'ch.qos.logback', name: 'logback-classic', version: "${logbackVersion}"
32+
if (project.hasProperty("edgeDepsTest")) {
33+
testRuntimeOnly "com.google.protobuf:protobuf-java:4.29.3"
34+
testRuntimeOnly "com.google.protobuf:protobuf-java-util:4.29.3"
35+
}
3236
}
3337

3438
// Temporal SDK supports Java 8 or later so to support virtual threads

temporal-sdk/src/main/java/io/temporal/client/WorkflowStubImpl.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -499,7 +499,7 @@ public WorkflowStub newInstance(WorkflowOptions options) {
499499
}
500500

501501
private void checkStarted() {
502-
if (execution.get() == null || execution.get().getWorkflowId() == null) {
502+
if (execution.get() == null) {
503503
throw new IllegalStateException("Null workflowId. Was workflow started?");
504504
}
505505
}

temporal-sdk/src/main/java/io/temporal/internal/client/ScheduleProtoUtil.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -341,8 +341,7 @@ public io.temporal.client.schedules.ScheduleSpec protoToScheduleSpec(
341341
Objects.requireNonNull(scheduleSpec);
342342
io.temporal.client.schedules.ScheduleSpec.Builder specBuilder =
343343
io.temporal.client.schedules.ScheduleSpec.newBuilder()
344-
.setTimeZoneName(
345-
scheduleSpec.getTimezoneName() == null ? "" : scheduleSpec.getTimezoneName());
344+
.setTimeZoneName(scheduleSpec.getTimezoneName());
346345

347346
if (scheduleSpec.hasJitter()) {
348347
specBuilder.setJitter(ProtobufTimeUtils.toJavaDuration(scheduleSpec.getJitter()));
@@ -450,7 +449,7 @@ public io.temporal.client.schedules.ScheduleAction protoToAction(@Nonnull Schedu
450449
wfOptionsBuilder.setWorkflowTaskTimeout(
451450
ProtobufTimeUtils.toJavaDuration(startWfAction.getWorkflowTaskTimeout()));
452451

453-
if (startWfAction.getRetryPolicy() != null) {
452+
if (startWfAction.hasRetryPolicy()) {
454453
wfOptionsBuilder.setRetryOptions(
455454
RetryOptionsUtils.toRetryOptions(startWfAction.getRetryPolicy()));
456455
}

temporal-sdk/src/main/java/io/temporal/internal/common/WorkflowExecutionHistory.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ public static WorkflowExecutionHistory fromJson(String serialized) {
7171

7272
private static void checkHistory(History history) {
7373
List<HistoryEvent> events = history.getEventsList();
74-
if (events == null || events.size() == 0) {
74+
if (events.size() == 0) {
7575
throw new IllegalArgumentException("Empty history");
7676
}
7777
HistoryEvent startedEvent = events.get(0);

temporal-sdk/src/main/java/io/temporal/internal/common/WorkflowExecutionUtils.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -265,9 +265,8 @@ public static String prettyPrintCommands(Iterable<Command> commands) {
265265
}
266266

267267
/** Pretty prints a proto message. */
268-
@SuppressWarnings("deprecation")
269268
public static String prettyPrintObject(MessageOrBuilder object) {
270-
return TextFormat.printToString(object);
269+
return TextFormat.printer().printToString(object);
271270
}
272271

273272
public static boolean containsEvent(List<HistoryEvent> history, EventType eventType) {

temporal-sdk/src/main/java/io/temporal/internal/replay/ReplayWorkflowExecutor.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,7 @@ public void handleWorkflowExecutionUpdated(UpdateMessage updateMessage) {
217217
Message protocolMessage = updateMessage.getMessage();
218218
Request update = protocolMessage.getBody().unpack(Request.class);
219219
Input input = update.getInput();
220-
Optional<Payloads> args = Optional.ofNullable(input.getArgs());
220+
Optional<Payloads> args = Optional.of(input.getArgs());
221221
this.workflow.handleUpdate(
222222
input.getName(),
223223
update.getMeta().getUpdateId(),

temporal-sdk/src/main/java/io/temporal/internal/sync/SyncWorkflowContext.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -385,8 +385,7 @@ public WorkflowMetadata getWorkflowMetadata() {
385385
WorkflowMetadata.Builder workflowMetadata = WorkflowMetadata.newBuilder();
386386
WorkflowDefinition.Builder workflowDefinition = WorkflowDefinition.newBuilder();
387387
// Set the workflow type
388-
if (replayContext.getWorkflowType() != null
389-
&& replayContext.getWorkflowType().getName() != null) {
388+
if (replayContext.getWorkflowType() != null) {
390389
workflowDefinition.setType(replayContext.getWorkflowType().getName());
391390
}
392391
// Set built in queries

temporal-sdk/src/test/java/io/temporal/internal/statemachines/TestHistoryBuilder.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -434,8 +434,8 @@ private HistoryEvent newAttributes(EventType type, Object attributes) {
434434
} else if (attributes instanceof Number) {
435435
attributes = newAttributes(type, ((Number) attributes).intValue());
436436
}
437-
if (attributes instanceof com.google.protobuf.GeneratedMessageV3.Builder) {
438-
attributes = ((com.google.protobuf.GeneratedMessageV3.Builder) attributes).build();
437+
if (attributes instanceof com.google.protobuf.Message.Builder) {
438+
attributes = ((com.google.protobuf.Message.Builder) attributes).build();
439439
}
440440
HistoryEvent.Builder result =
441441
HistoryEvent.newBuilder()

0 commit comments

Comments
 (0)