Skip to content

Commit d12c080

Browse files
authored
Added errorprone checks (#121)
Added errorprone plugin. Fixed all errors and warnings that it reported.
1 parent 1a9b92d commit d12c080

34 files changed

+270
-176
lines changed

build.gradle

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ buildscript {
77
plugins {
88
id 'net.minecrell.licenser' version '0.3'
99
id "com.github.sherter.google-java-format" version "0.6"
10+
id "net.ltgt.errorprone" version "0.0.13"
1011
}
1112

1213
repositories {
@@ -52,7 +53,8 @@ license {
5253

5354
compileJava {
5455
options.encoding = 'UTF-8'
55-
options.compilerArgs << "-Xlint:unchecked" << "-Xlint:deprecation"
56+
options.compilerArgs << "-Xlint:unchecked" << "-Xlint:deprecation" << "-XepExcludedPaths:" +
57+
".*/generated-sources/.*"
5658
}
5759

5860
license {
@@ -63,7 +65,8 @@ license {
6365

6466
compileTestJava {
6567
options.encoding = 'UTF-8'
66-
options.compilerArgs << "-Xlint:unchecked" << "-Xlint:deprecation"
68+
options.compilerArgs << "-Xlint:unchecked" << "-Xlint:deprecation" << "-XepExcludedPaths:" +
69+
".*/generated-sources/.*"
6770
}
6871

6972
if (JavaVersion.current().isJava8Compatible()) {

src/main/java/com/uber/cadence/converter/JsonDataConverter.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -237,6 +237,7 @@ private StackTraceElement[] parseStackTrace(JsonObject object) {
237237
return new StackTraceElement[0];
238238
}
239239
try {
240+
@SuppressWarnings("StringSplitter")
240241
String[] lines = stackTrace.split("\n");
241242
StackTraceElement[] result = new StackTraceElement[lines.length];
242243
for (int i = 0; i < lines.length; i++) {

src/main/java/com/uber/cadence/internal/common/StartWorkflowExecutionParameters.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
import com.uber.cadence.WorkflowIdReusePolicy;
2222
import com.uber.cadence.WorkflowType;
2323
import com.uber.cadence.client.WorkflowOptions;
24+
import java.nio.charset.StandardCharsets;
2425

2526
public class StartWorkflowExecutionParameters {
2627

@@ -291,14 +292,14 @@ public String toString() {
291292
sb.append("WorkflowId: " + workflowId + ", ");
292293
sb.append("WorkflowType: " + workflowType + ", ");
293294
sb.append("TaskList: " + taskList + ", ");
294-
sb.append("Input: " + input + ", ");
295+
sb.append("Input: " + new String(input, 0, 512, StandardCharsets.UTF_8) + ", ");
295296
sb.append("StartToCloseTimeout: " + executionStartToCloseTimeoutSeconds + ", ");
296297
sb.append("ChildPolicy: " + childPolicy + ", ");
297298
sb.append("}");
298299
return sb.toString();
299300
}
300301

301-
public StartWorkflowExecutionParameters clone() {
302+
public StartWorkflowExecutionParameters copy() {
302303
StartWorkflowExecutionParameters result = new StartWorkflowExecutionParameters();
303304
result.setInput(input);
304305
result.setExecutionStartToCloseTimeoutSeconds(executionStartToCloseTimeoutSeconds);

src/main/java/com/uber/cadence/internal/common/WorkflowExecutionUtils.java

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -174,12 +174,13 @@ public static HistoryEvent getInstanceCloseEvent(
174174
}
175175

176176
public static boolean isWorkflowExecutionCompletedEvent(HistoryEvent event) {
177-
return ((event != null) && event.getEventType() == EventType.WorkflowExecutionCompleted
178-
|| event.getEventType() == EventType.WorkflowExecutionCanceled
179-
|| event.getEventType() == EventType.WorkflowExecutionFailed
180-
|| event.getEventType() == EventType.WorkflowExecutionTimedOut
181-
|| event.getEventType() == EventType.WorkflowExecutionContinuedAsNew
182-
|| event.getEventType() == EventType.WorkflowExecutionTerminated);
177+
return ((event != null)
178+
&& (event.getEventType() == EventType.WorkflowExecutionCompleted
179+
|| event.getEventType() == EventType.WorkflowExecutionCanceled
180+
|| event.getEventType() == EventType.WorkflowExecutionFailed
181+
|| event.getEventType() == EventType.WorkflowExecutionTimedOut
182+
|| event.getEventType() == EventType.WorkflowExecutionContinuedAsNew
183+
|| event.getEventType() == EventType.WorkflowExecutionTerminated));
183184
}
184185

185186
public static boolean isActivityTaskClosedEvent(HistoryEvent event) {
@@ -479,7 +480,7 @@ public static String prettyPrintHistory(History history, boolean showWorkflowTas
479480

480481
public static String prettyPrintHistory(
481482
Iterator<HistoryEvent> events, boolean showWorkflowTasks) {
482-
StringBuffer result = new StringBuffer();
483+
StringBuilder result = new StringBuilder();
483484
result.append("{");
484485
boolean first = true;
485486
while (events.hasNext()) {
@@ -500,7 +501,7 @@ public static String prettyPrintHistory(
500501
}
501502

502503
public static String prettyPrintDecisions(Iterable<Decision> decisions) {
503-
StringBuffer result = new StringBuffer();
504+
StringBuilder result = new StringBuilder();
504505
result.append("{");
505506
boolean first = true;
506507
for (Decision decision : decisions) {
@@ -523,7 +524,7 @@ public static String prettyPrintDecisions(Iterable<Decision> decisions) {
523524
*/
524525
public static String prettyPrintHistoryEvent(HistoryEvent event) {
525526
String eventType = event.getEventType().toString();
526-
StringBuffer result = new StringBuffer();
527+
StringBuilder result = new StringBuilder();
527528
result.append(event.getEventId());
528529
result.append(": ");
529530
result.append(eventType);
@@ -562,7 +563,7 @@ private static String prettyPrintObject(
562563
String indentation,
563564
boolean skipLevel,
564565
boolean printTypeName) {
565-
StringBuffer result = new StringBuffer();
566+
StringBuilder result = new StringBuilder();
566567
if (object == null) {
567568
return "null";
568569
}

src/main/java/com/uber/cadence/internal/external/GenericWorkflowClientExternalImpl.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ public GenericWorkflowClientExternalImpl(WorkflowService.Iface service, String d
4747
this.domain = domain;
4848
}
4949

50+
@Override
5051
public String getDomain() {
5152
return domain;
5253
}

src/main/java/com/uber/cadence/internal/replay/ChildWorkflowDecisionStateMachine.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ public void handleStartedEvent(HistoryEvent event) {
7777
case CANCELED_AFTER_INITIATED:
7878
state = DecisionState.CANCELED_AFTER_STARTED;
7979
break;
80+
default:
8081
}
8182
stateHistory.add(state.toString());
8283
}

src/main/java/com/uber/cadence/internal/replay/CompleteWorkflowStateMachine.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ public CompleteWorkflowStateMachine(DecisionId id, Decision decision) {
3030
this.decision = decision;
3131
}
3232

33+
@Override
3334
public DecisionId getId() {
3435
return id;
3536
}

src/main/java/com/uber/cadence/internal/replay/ContinueAsNewWorkflowExecutionParameters.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
package com.uber.cadence.internal.replay;
1919

2020
import com.uber.cadence.ChildPolicy;
21+
import java.nio.charset.StandardCharsets;
2122

2223
public final class ContinueAsNewWorkflowExecutionParameters {
2324

@@ -100,15 +101,15 @@ public ContinueAsNewWorkflowExecutionParameters withTaskStartToCloseTimeoutSecon
100101
public String toString() {
101102
StringBuilder sb = new StringBuilder();
102103
sb.append("{");
103-
sb.append("Input: " + input + ", ");
104+
sb.append("Input: " + new String(input, 0, 512, StandardCharsets.UTF_8) + ", ");
104105
sb.append("ExecutionStartToCloseTimeout: " + executionStartToCloseTimeoutSeconds + ", ");
105106
sb.append("TaskStartToCloseTimeout: " + taskStartToCloseTimeoutSeconds + ", ");
106107
sb.append("TaskList: " + taskList + ", ");
107108
sb.append("}");
108109
return sb.toString();
109110
}
110111

111-
public ContinueAsNewWorkflowExecutionParameters clone() {
112+
public ContinueAsNewWorkflowExecutionParameters copy() {
112113
ContinueAsNewWorkflowExecutionParameters result =
113114
new ContinueAsNewWorkflowExecutionParameters();
114115
result.setExecutionStartToCloseTimeoutSeconds(executionStartToCloseTimeoutSeconds);

src/main/java/com/uber/cadence/internal/replay/DecisionContextImpl.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,7 @@ public Consumer<Exception> startChildWorkflow(
128128
return workflowClient.startChildWorkflow(parameters, executionCallback, callback);
129129
}
130130

131+
@Override
131132
public Consumer<Exception> signalWorkflowExecution(
132133
SignalExternalWorkflowParameters signalParameters, BiConsumer<Void, Exception> callback) {
133134
return workflowClient.signalWorkflowExecution(signalParameters, callback);

src/main/java/com/uber/cadence/internal/replay/DecisionStateMachineBase.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,10 +41,12 @@ protected DecisionStateMachineBase(DecisionId id, DecisionState state) {
4141
stateHistory.add(state.toString());
4242
}
4343

44+
@Override
4445
public DecisionState getState() {
4546
return state;
4647
}
4748

49+
@Override
4850
public DecisionId getId() {
4951
return id;
5052
}
@@ -63,6 +65,7 @@ public void handleDecisionTaskStartedEvent() {
6365
state = DecisionState.DECISION_SENT;
6466
stateHistory.add(state.toString());
6567
break;
68+
default:
6669
}
6770
}
6871

0 commit comments

Comments
 (0)