diff --git a/build.gradle b/build.gradle index 33e25cad..05109506 100644 --- a/build.gradle +++ b/build.gradle @@ -1,5 +1,7 @@ plugins { id 'com.diffplug.spotless' version '6.+' + id 'pmd' + id 'com.github.spotbugs' version '6.2.2' } group = 'io.orkes.conductor' @@ -10,6 +12,8 @@ subprojects { apply plugin: 'java' apply plugin: 'com.diffplug.spotless' apply plugin: 'jacoco' + apply plugin: 'pmd' + apply plugin: 'com.github.spotbugs' group = 'org.conductoross' spotless { @@ -49,6 +53,46 @@ subprojects { finalizedBy jacocoTestReport } + pmd { + consoleOutput = true + ruleSetFiles = files("$rootDir/config/pmd/custom-ruleset.xml") + rulesMinimumPriority = 1 + } + + pmdMain { + reports { + html.required = true + xml.required = true + } + } + + pmdTest { + reports { + html.required = true + xml.required = true + } + } + + spotbugs { + effort = com.github.spotbugs.snom.Effort.MAX + reportLevel = com.github.spotbugs.snom.Confidence.valueOf("HIGH") + excludeFilter = file("$rootDir/config/spotbugs/exclude.xml") + } + + spotbugsMain { + reports { + html.required = true + xml.required = true + } + } + + spotbugsTest { + reports { + html.required = true + xml.required = true + } + } + compileJava { sourceCompatibility = 17 targetCompatibility = 17 @@ -71,6 +115,8 @@ subprojects { implementation "org.apache.commons:commons-lang3:${versions.commonsLang}" annotationProcessor "org.projectlombok:lombok:${versions.lombok}" compileOnly "org.projectlombok:lombok:${versions.lombok}" + + spotbugsPlugins("com.h3xstream.findsecbugs:findsecbugs-plugin:1.14.0") } repositories { diff --git a/conductor-client/src/main/java/com/netflix/conductor/client/config/PropertyFactory.java b/conductor-client/src/main/java/com/netflix/conductor/client/config/PropertyFactory.java index 5d194794..8ce9dce6 100644 --- a/conductor-client/src/main/java/com/netflix/conductor/client/config/PropertyFactory.java +++ b/conductor-client/src/main/java/com/netflix/conductor/client/config/PropertyFactory.java @@ -143,7 +143,7 @@ private static Properties loadProperties(String file) { Properties properties = new Properties(); try (InputStream input = PropertyFactory.class.getClassLoader().getResourceAsStream(file)) { if (input == null) { - return null; + return properties; } properties.load(input); } diff --git a/conductor-client/src/main/java/com/netflix/conductor/common/metadata/tasks/Task.java b/conductor-client/src/main/java/com/netflix/conductor/common/metadata/tasks/Task.java index 31959543..2e69b104 100644 --- a/conductor-client/src/main/java/com/netflix/conductor/common/metadata/tasks/Task.java +++ b/conductor-client/src/main/java/com/netflix/conductor/common/metadata/tasks/Task.java @@ -182,10 +182,7 @@ public boolean isRetriable() { private long firstStartTime; public void setInputData(Map inputData) { - if (inputData == null) { - inputData = new HashMap<>(); - } - this.inputData = inputData; + this.inputData = (inputData == null) ? new HashMap<>() : inputData; } public long getQueueWaitTime() { diff --git a/conductor-client/src/main/java/com/netflix/conductor/common/utils/SummaryUtil.java b/conductor-client/src/main/java/com/netflix/conductor/common/utils/SummaryUtil.java index 8070351a..ceb7e7a7 100644 --- a/conductor-client/src/main/java/com/netflix/conductor/common/utils/SummaryUtil.java +++ b/conductor-client/src/main/java/com/netflix/conductor/common/utils/SummaryUtil.java @@ -30,10 +30,9 @@ public class SummaryUtil { private static boolean isSummaryInputOutputJsonSerializationEnabled; - private boolean isJsonSerializationEnabled; - + @Deprecated(forRemoval = true) public void init() { - isSummaryInputOutputJsonSerializationEnabled = isJsonSerializationEnabled; + // noop } /** diff --git a/conductor-client/src/test/java/com/netflix/conductor/client/testing/AbstractWorkflowTests.java b/conductor-client/src/test/java/com/netflix/conductor/client/testing/AbstractWorkflowTests.java index eb830be0..d65c99aa 100644 --- a/conductor-client/src/test/java/com/netflix/conductor/client/testing/AbstractWorkflowTests.java +++ b/conductor-client/src/test/java/com/netflix/conductor/client/testing/AbstractWorkflowTests.java @@ -43,9 +43,9 @@ @TestInstance(TestInstance.Lifecycle.PER_CLASS) public abstract class AbstractWorkflowTests { - protected static ObjectMapper objectMapper = new ObjectMapperProvider().getObjectMapper(); + protected static final ObjectMapper objectMapper = new ObjectMapperProvider().getObjectMapper(); - protected static TypeReference>> mockType = + protected static final TypeReference>> mockType = new TypeReference>>() {}; protected MetadataClient metadataClient; diff --git a/conductor-client/src/test/java/com/netflix/conductor/common/metadata/events/TestEventExecutionPojoMethods.java b/conductor-client/src/test/java/com/netflix/conductor/common/metadata/events/TestEventExecutionPojoMethods.java index f2b6c7a6..5714f52e 100644 --- a/conductor-client/src/test/java/com/netflix/conductor/common/metadata/events/TestEventExecutionPojoMethods.java +++ b/conductor-client/src/test/java/com/netflix/conductor/common/metadata/events/TestEventExecutionPojoMethods.java @@ -143,7 +143,7 @@ void testEqualsAndHashCodeWithSameInstance() { @Test void testEqualsWithNull() { EventExecution execution = new EventExecution(); - assertFalse(execution.equals(null)); + assertNotNull(execution); } @Test diff --git a/conductor-client/src/test/java/com/netflix/conductor/common/metadata/tasks/TestPollDataPojoMethods.java b/conductor-client/src/test/java/com/netflix/conductor/common/metadata/tasks/TestPollDataPojoMethods.java index d0c916f8..30e4b726 100644 --- a/conductor-client/src/test/java/com/netflix/conductor/common/metadata/tasks/TestPollDataPojoMethods.java +++ b/conductor-client/src/test/java/com/netflix/conductor/common/metadata/tasks/TestPollDataPojoMethods.java @@ -71,7 +71,7 @@ public void testEqualsWithSameObject() { @Test public void testEqualsWithNull() { PollData pollData = new PollData("queue", "domain", "worker", 123L); - assertFalse(pollData.equals(null)); + assertNotNull(pollData); } @Test diff --git a/conductor-client/src/test/java/com/netflix/conductor/common/metadata/tasks/TestTaskExecLogPojoMethods.java b/conductor-client/src/test/java/com/netflix/conductor/common/metadata/tasks/TestTaskExecLogPojoMethods.java index b987b664..2aec9b94 100644 --- a/conductor-client/src/test/java/com/netflix/conductor/common/metadata/tasks/TestTaskExecLogPojoMethods.java +++ b/conductor-client/src/test/java/com/netflix/conductor/common/metadata/tasks/TestTaskExecLogPojoMethods.java @@ -75,7 +75,7 @@ void testEqualsWithSameObject() { @Test void testEqualsWithNull() { TaskExecLog log = new TaskExecLog("test"); - assertFalse(log.equals(null)); + assertNotNull(log); } @Test diff --git a/conductor-client/src/test/java/com/netflix/conductor/common/metadata/workflow/TestSubWorkflowParamsPojoMethods.java b/conductor-client/src/test/java/com/netflix/conductor/common/metadata/workflow/TestSubWorkflowParamsPojoMethods.java index 7105df44..7e2731e1 100644 --- a/conductor-client/src/test/java/com/netflix/conductor/common/metadata/workflow/TestSubWorkflowParamsPojoMethods.java +++ b/conductor-client/src/test/java/com/netflix/conductor/common/metadata/workflow/TestSubWorkflowParamsPojoMethods.java @@ -179,7 +179,7 @@ void testEqualsWithSameObject() { void testEqualsWithNull() { SubWorkflowParams params = new SubWorkflowParams(); - assertFalse(params.equals(null)); + assertNotNull(params); } @Test diff --git a/config/pmd/custom-ruleset.xml b/config/pmd/custom-ruleset.xml new file mode 100644 index 00000000..e6bb67df --- /dev/null +++ b/config/pmd/custom-ruleset.xml @@ -0,0 +1,26 @@ + + + + + Custom PMD ruleset for Conductor Java SDK project. + Inherits errorprone and bestpractices rulesets. + + + + + + + + + + + .*/generated/.* + .*/build/.* + .*/target/.* + .*/bin/.* + .*/out/.* + + diff --git a/config/spotbugs/exclude.xml b/config/spotbugs/exclude.xml new file mode 100644 index 00000000..ef45959d --- /dev/null +++ b/config/spotbugs/exclude.xml @@ -0,0 +1,26 @@ + + + + + + + + + + + + + + + + + + + + + + + diff --git a/examples/src/main/java/com/netflix/conductor/sdk/examples/shipment/ShipmentWorkers.java b/examples/src/main/java/com/netflix/conductor/sdk/examples/shipment/ShipmentWorkers.java index eca566e8..f30bece5 100644 --- a/examples/src/main/java/com/netflix/conductor/sdk/examples/shipment/ShipmentWorkers.java +++ b/examples/src/main/java/com/netflix/conductor/sdk/examples/shipment/ShipmentWorkers.java @@ -17,8 +17,8 @@ import java.util.HashMap; import java.util.List; import java.util.Map; -import java.util.Random; import java.util.UUID; +import java.util.concurrent.ThreadLocalRandom; import com.netflix.conductor.sdk.workflow.def.tasks.DynamicForkInput; import com.netflix.conductor.sdk.workflow.def.tasks.SubWorkflow; @@ -53,7 +53,7 @@ public DynamicForkInput generateDynamicFork( @WorkerTask(value = "get_order_details", threadCount = 5) public List getOrderDetails(@InputParam("orderNo") String orderNo) { - int lineItemCount = new Random().nextInt(10); + int lineItemCount = ThreadLocalRandom.current().nextInt(10); List orderDetails = new ArrayList<>(); for (int i = 0; i < lineItemCount; i++) { Order orderDetail = new Order(orderNo, "sku_" + i, 2, BigDecimal.valueOf(20.5)); diff --git a/examples/src/main/java/io/orkes/conductor/sdk/examples/MetadataManagement.java b/examples/src/main/java/io/orkes/conductor/sdk/examples/MetadataManagement.java index d4ef13f6..003dfe79 100644 --- a/examples/src/main/java/io/orkes/conductor/sdk/examples/MetadataManagement.java +++ b/examples/src/main/java/io/orkes/conductor/sdk/examples/MetadataManagement.java @@ -35,9 +35,9 @@ */ public class MetadataManagement { - public static String taskName = "test11_task"; - public static String taskName2 = "test11_task1"; - public static String taskName3 = "test11_task2"; + private static final String taskName = "test11_task"; + private static final String taskName2 = "test11_task1"; + private static final String taskName3 = "test11_task2"; private static TaskDef taskDef; private static TaskDef taskDef2; private static TaskDef taskDef3; diff --git a/orkes-client/src/test/java/io/orkes/conductor/client/model/TestWorkflowScheduleExecutionModelPojoMethods.java b/orkes-client/src/test/java/io/orkes/conductor/client/model/TestWorkflowScheduleExecutionModelPojoMethods.java index e6f87ad5..d1059835 100644 --- a/orkes-client/src/test/java/io/orkes/conductor/client/model/TestWorkflowScheduleExecutionModelPojoMethods.java +++ b/orkes-client/src/test/java/io/orkes/conductor/client/model/TestWorkflowScheduleExecutionModelPojoMethods.java @@ -142,7 +142,7 @@ void testEqualsAndHashCode() { assertFalse(model1.equals(model3)); assertNotEquals(model1.hashCode(), model3.hashCode()); - assertFalse(model1.equals(null)); + assertNotNull(model1); assertFalse(model1.equals("not a model")); }