diff --git a/airbyte-analytics/src/main/java/io/airbyte/analytics/TrackingIdentity.java b/airbyte-analytics/src/main/java/io/airbyte/analytics/TrackingIdentity.java index 54703c9a27e8..25fc66db8528 100644 --- a/airbyte-analytics/src/main/java/io/airbyte/analytics/TrackingIdentity.java +++ b/airbyte-analytics/src/main/java/io/airbyte/analytics/TrackingIdentity.java @@ -9,6 +9,7 @@ import java.util.Optional; import java.util.UUID; +@SuppressWarnings("PMD.CompareObjectsWithEquals") public class TrackingIdentity { private final AirbyteVersion airbyteVersion; diff --git a/airbyte-analytics/src/test/java/io/airbyte/analytics/SegmentTrackingClientTest.java b/airbyte-analytics/src/test/java/io/airbyte/analytics/SegmentTrackingClientTest.java index 2d91aba22b41..190cf60672e4 100644 --- a/airbyte-analytics/src/test/java/io/airbyte/analytics/SegmentTrackingClientTest.java +++ b/airbyte-analytics/src/test/java/io/airbyte/analytics/SegmentTrackingClientTest.java @@ -136,10 +136,11 @@ void testTrackWithMetadata() { } private static ImmutableMap filterTrackedAtProperty(final Map properties) { - assertTrue(properties.containsKey("tracked_at")); + final String trackedAtKey = "tracked_at"; + assertTrue(properties.containsKey(trackedAtKey)); final Builder builder = ImmutableMap.builder(); properties.forEach((key, value) -> { - if (!"tracked_at".equals(key)) { + if (!trackedAtKey.equals(key)) { builder.put(key, value); } }); diff --git a/airbyte-api/src/main/java/io/airbyte/api/client/PatchedLogsApi.java b/airbyte-api/src/main/java/io/airbyte/api/client/PatchedLogsApi.java index 221107722f80..10831fce4e13 100644 --- a/airbyte-api/src/main/java/io/airbyte/api/client/PatchedLogsApi.java +++ b/airbyte-api/src/main/java/io/airbyte/api/client/PatchedLogsApi.java @@ -75,7 +75,7 @@ public ApiResponse getLogsWithHttpInfo(final LogsRequestBody logsRequestBo if (memberVarResponseInterceptor != null) { memberVarResponseInterceptor.accept(localVarResponse); } - if (localVarResponse.statusCode() / 100 != 2) { + if (isErrorResponse(localVarResponse)) { throw new ApiException(localVarResponse.statusCode(), "getLogs call received non-success response", localVarResponse.headers(), @@ -100,6 +100,10 @@ public ApiResponse getLogsWithHttpInfo(final LogsRequestBody logsRequestBo } } + private Boolean isErrorResponse(final HttpResponse httpResponse) { + return httpResponse.statusCode() / 100 != 2; + } + private HttpRequest.Builder getLogsRequestBuilder(final LogsRequestBody logsRequestBody) throws ApiException { // verify the required parameter 'logsRequestBody' is set if (logsRequestBody == null) { diff --git a/airbyte-commons/src/main/java/io/airbyte/commons/io/FileTtlManager.java b/airbyte-commons/src/main/java/io/airbyte/commons/io/FileTtlManager.java index fc162bb1da56..7ab4ad7134d0 100644 --- a/airbyte-commons/src/main/java/io/airbyte/commons/io/FileTtlManager.java +++ b/airbyte-commons/src/main/java/io/airbyte/commons/io/FileTtlManager.java @@ -75,7 +75,8 @@ private void reportCacheStatus() { } }); sb.append("---\n"); - LOGGER.info(sb.toString()); + final String toLog = sb.toString(); + LOGGER.info(toLog); } } diff --git a/airbyte-commons/src/main/java/io/airbyte/commons/version/AirbyteVersion.java b/airbyte-commons/src/main/java/io/airbyte/commons/version/AirbyteVersion.java index 09845f205e52..078d40b487c2 100644 --- a/airbyte-commons/src/main/java/io/airbyte/commons/version/AirbyteVersion.java +++ b/airbyte-commons/src/main/java/io/airbyte/commons/version/AirbyteVersion.java @@ -10,6 +10,7 @@ /** * The AirbyteVersion identifies the version of the database used internally by Airbyte services. */ +@SuppressWarnings("PMD.ConstructorCallsOverridableMethod") public class AirbyteVersion { public static final String DEV_VERSION_PREFIX = "dev"; diff --git a/airbyte-config/config-models/src/main/java/io/airbyte/config/EnvConfigs.java b/airbyte-config/config-models/src/main/java/io/airbyte/config/EnvConfigs.java index 5d10b1f14ef5..c92920f641e3 100644 --- a/airbyte-config/config-models/src/main/java/io/airbyte/config/EnvConfigs.java +++ b/airbyte-config/config-models/src/main/java/io/airbyte/config/EnvConfigs.java @@ -33,7 +33,7 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; -@SuppressWarnings({"PMD.LongVariable", "PMD.CyclomaticComplexity", "PMD.AvoidReassigningParameters"}) +@SuppressWarnings({"PMD.LongVariable", "PMD.CyclomaticComplexity", "PMD.AvoidReassigningParameters", "PMD.ConstructorCallsOverridableMethod"}) public class EnvConfigs implements Configs { private static final Logger LOGGER = LoggerFactory.getLogger(EnvConfigs.class); diff --git a/airbyte-config/config-models/src/main/java/io/airbyte/config/helpers/StateMessageHelper.java b/airbyte-config/config-models/src/main/java/io/airbyte/config/helpers/StateMessageHelper.java index 257a5441c343..e5c9857b04f7 100644 --- a/airbyte-config/config-models/src/main/java/io/airbyte/config/helpers/StateMessageHelper.java +++ b/airbyte-config/config-models/src/main/java/io/airbyte/config/helpers/StateMessageHelper.java @@ -28,6 +28,7 @@ public static class AirbyteStateMessageListTypeReference extends TypeReference getTypedState(final JsonNode state, final boolean useStreamCapableState) { if (state == null) { return Optional.empty(); diff --git a/airbyte-config/config-persistence/src/main/java/io/airbyte/config/persistence/StatePersistence.java b/airbyte-config/config-persistence/src/main/java/io/airbyte/config/persistence/StatePersistence.java index 47d828c2ff32..a393bec7d4eb 100644 --- a/airbyte-config/config-persistence/src/main/java/io/airbyte/config/persistence/StatePersistence.java +++ b/airbyte-config/config-persistence/src/main/java/io/airbyte/config/persistence/StatePersistence.java @@ -217,6 +217,7 @@ static void writeStateToDb(final DSLContext ctx, * @return the StateType of the records * @throws IllegalStateException If StateRecords have inconsistent types */ + @SuppressWarnings("PMD.AvoidLiteralsInIfCondition") private static io.airbyte.db.instance.configs.jooq.generated.enums.StateType getStateType( final UUID connectionId, final List records) { diff --git a/airbyte-config/config-persistence/src/main/java/io/airbyte/config/persistence/split_secrets/VaultSecretPersistence.java b/airbyte-config/config-persistence/src/main/java/io/airbyte/config/persistence/split_secrets/VaultSecretPersistence.java index 066f06f109a6..43ee603fc8a8 100644 --- a/airbyte-config/config-persistence/src/main/java/io/airbyte/config/persistence/split_secrets/VaultSecretPersistence.java +++ b/airbyte-config/config-persistence/src/main/java/io/airbyte/config/persistence/split_secrets/VaultSecretPersistence.java @@ -31,7 +31,9 @@ public Optional read(final SecretCoordinate coordinate) { val response = vault.logical().read(pathPrefix + coordinate.getFullCoordinate()); val restResponse = response.getRestResponse(); val responseCode = restResponse.getStatus(); - if (responseCode != 200) { + final Boolean isErrorResponse = responseCode / 100 != 2; + + if (isErrorResponse) { log.error("Vault failed on read. Response code: " + responseCode); return Optional.empty(); } diff --git a/airbyte-config/config-persistence/src/test/java/io/airbyte/config/persistence/StatePersistenceTest.java b/airbyte-config/config-persistence/src/test/java/io/airbyte/config/persistence/StatePersistenceTest.java index ef0e34057f4a..925573317a97 100644 --- a/airbyte-config/config-persistence/src/test/java/io/airbyte/config/persistence/StatePersistenceTest.java +++ b/airbyte-config/config-persistence/src/test/java/io/airbyte/config/persistence/StatePersistenceTest.java @@ -275,7 +275,7 @@ void testGlobalFullReset() throws IOException { .withStreamState(null), new AirbyteStreamState() .withStreamDescriptor(new StreamDescriptor().withName("s1")) - .withStreamState(null)))));; + .withStreamState(null))))); statePersistence.updateOrCreateState(connectionId, state0); statePersistence.updateOrCreateState(connectionId, fullReset); diff --git a/airbyte-config/init/src/main/java/io/airbyte/config/init/RemoteDefinitionsProvider.java b/airbyte-config/init/src/main/java/io/airbyte/config/init/RemoteDefinitionsProvider.java index c7ff5ee68544..aaa159c37269 100644 --- a/airbyte-config/init/src/main/java/io/airbyte/config/init/RemoteDefinitionsProvider.java +++ b/airbyte-config/init/src/main/java/io/airbyte/config/init/RemoteDefinitionsProvider.java @@ -58,7 +58,7 @@ public void initialize() throws InterruptedException, IOException { @Override public StandardSourceDefinition getSourceDefinition(final UUID definitionId) throws ConfigNotFoundException { - StandardSourceDefinition definition = this.sourceDefinitions.get(definitionId); + final StandardSourceDefinition definition = this.sourceDefinitions.get(definitionId); if (definition == null) { throw new ConfigNotFoundException(SeedType.STANDARD_SOURCE_DEFINITION.name(), definitionId.toString()); } @@ -72,7 +72,7 @@ public List getSourceDefinitions() { @Override public StandardDestinationDefinition getDestinationDefinition(final UUID definitionId) throws ConfigNotFoundException { - StandardDestinationDefinition definition = this.destinationDefinitions.get(definitionId); + final StandardDestinationDefinition definition = this.destinationDefinitions.get(definitionId); if (definition == null) { throw new ConfigNotFoundException(SeedType.STANDARD_DESTINATION_DEFINITION.name(), definitionId.toString()); } @@ -84,15 +84,20 @@ public List getDestinationDefinitions() { return new ArrayList<>(this.destinationDefinitions.values()); } - private static CombinedConnectorCatalog getRemoteDefinitionCatalog(URI catalogUrl, Duration timeout) throws IOException, InterruptedException { + private static CombinedConnectorCatalog getRemoteDefinitionCatalog(final URI catalogUrl, final Duration timeout) + throws IOException, InterruptedException { final HttpRequest request = HttpRequest.newBuilder(catalogUrl).timeout(timeout).header("accept", "application/json").build(); final HttpResponse response = httpClient.send(request, HttpResponse.BodyHandlers.ofString()); - if (response.statusCode() >= 400) { + if (errorStatusCode(response)) { throw new IOException( "getRemoteDefinitionCatalog request ran into status code error: " + response.statusCode() + " with message: " + response.getClass()); } return Jsons.deserialize(response.body(), CombinedConnectorCatalog.class); } + private static Boolean errorStatusCode(final HttpResponse response) { + return response.statusCode() >= 400; + } + } diff --git a/airbyte-container-orchestrator/src/main/java/io/airbyte/container_orchestrator/ContainerOrchestratorApp.java b/airbyte-container-orchestrator/src/main/java/io/airbyte/container_orchestrator/ContainerOrchestratorApp.java index cd0570bfc535..e38e72b0929d 100644 --- a/airbyte-container-orchestrator/src/main/java/io/airbyte/container_orchestrator/ContainerOrchestratorApp.java +++ b/airbyte-container-orchestrator/src/main/java/io/airbyte/container_orchestrator/ContainerOrchestratorApp.java @@ -53,7 +53,7 @@ * future this will need to independently interact with cloud storage. */ @Slf4j -@SuppressWarnings("PMD.AvoidCatchingThrowable") +@SuppressWarnings({"PMD.AvoidCatchingThrowable", "PMD.DoNotTerminateVM"}) public class ContainerOrchestratorApp { public static final int MAX_SECONDS_TO_WAIT_FOR_FILE_COPY = 60; diff --git a/airbyte-db/db-lib/src/main/java/io/airbyte/db/DataTypeUtils.java b/airbyte-db/db-lib/src/main/java/io/airbyte/db/DataTypeUtils.java index 6e82d77a8fc4..10d83e1a3bb3 100644 --- a/airbyte-db/db-lib/src/main/java/io/airbyte/db/DataTypeUtils.java +++ b/airbyte-db/db-lib/src/main/java/io/airbyte/db/DataTypeUtils.java @@ -66,6 +66,7 @@ public static String toISO8601StringWithMicroseconds(final Instant instant) { return dateWithMilliseconds.substring(0, 23) + calculateMicrosecondsString(instant.getNano()) + dateWithMilliseconds.substring(23); } + @SuppressWarnings("PMD.AvoidLiteralsInIfCondition") private static String calculateMicrosecondsString(final int nano) { final var microSeconds = (nano / 1000) % 1000; final String result; diff --git a/airbyte-db/db-lib/src/main/java/io/airbyte/db/IncrementalUtils.java b/airbyte-db/db-lib/src/main/java/io/airbyte/db/IncrementalUtils.java index db3b10ef1547..6a73a03cc6bb 100644 --- a/airbyte-db/db-lib/src/main/java/io/airbyte/db/IncrementalUtils.java +++ b/airbyte-db/db-lib/src/main/java/io/airbyte/db/IncrementalUtils.java @@ -11,6 +11,7 @@ public class IncrementalUtils { private static final String PROPERTIES = "properties"; + @SuppressWarnings("PMD.AvoidLiteralsInIfCondition") public static String getCursorField(final ConfiguredAirbyteStream stream) { if (stream.getCursorField().size() == 0) { throw new IllegalStateException("No cursor field specified for stream attempting to do incremental."); diff --git a/airbyte-db/db-lib/src/main/java/io/airbyte/db/bigquery/BigQuerySourceOperations.java b/airbyte-db/db-lib/src/main/java/io/airbyte/db/bigquery/BigQuerySourceOperations.java index af8a4d1c923f..fd1f36877e27 100644 --- a/airbyte-db/db-lib/src/main/java/io/airbyte/db/bigquery/BigQuerySourceOperations.java +++ b/airbyte-db/db-lib/src/main/java/io/airbyte/db/bigquery/BigQuerySourceOperations.java @@ -99,7 +99,7 @@ private void setJsonField(final Field field, final FieldValue fieldValue, final } } } catch (final UnsupportedOperationException e) { - LOGGER.error("Failed to parse Object field with name: ", fieldName, e.getMessage()); + LOGGER.error("Failed to parse Object field with name: {}, {}", fieldName, e.getMessage()); } } } diff --git a/airbyte-db/db-lib/src/main/java/io/airbyte/db/instance/configs/migrations/V0_30_22_001__Store_last_sync_state.java b/airbyte-db/db-lib/src/main/java/io/airbyte/db/instance/configs/migrations/V0_30_22_001__Store_last_sync_state.java index 412c7d974ee9..667db91594bf 100644 --- a/airbyte-db/db-lib/src/main/java/io/airbyte/db/instance/configs/migrations/V0_30_22_001__Store_last_sync_state.java +++ b/airbyte-db/db-lib/src/main/java/io/airbyte/db/instance/configs/migrations/V0_30_22_001__Store_last_sync_state.java @@ -106,6 +106,7 @@ static void copyData(final DSLContext ctx, final Set standard * data from the job database). */ @VisibleForTesting + @SuppressWarnings("PMD.AvoidLiteralsInIfCondition") static Optional getJobsDatabase(final String databaseUser, final String databasePassword, final String databaseUrl) { try { if (databaseUrl == null || "".equals(databaseUrl.trim())) { diff --git a/airbyte-db/db-lib/src/main/java/io/airbyte/db/instance/jobs/migrations/V0_35_40_001__MigrateFailureReasonEnumValues.java b/airbyte-db/db-lib/src/main/java/io/airbyte/db/instance/jobs/migrations/V0_35_40_001__MigrateFailureReasonEnumValues.java index b8b96aad7908..88ea9b915919 100644 --- a/airbyte-db/db-lib/src/main/java/io/airbyte/db/instance/jobs/migrations/V0_35_40_001__MigrateFailureReasonEnumValues.java +++ b/airbyte-db/db-lib/src/main/java/io/airbyte/db/instance/jobs/migrations/V0_35_40_001__MigrateFailureReasonEnumValues.java @@ -24,6 +24,7 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; +@SuppressWarnings({"PMD.AvoidLiteralsInIfCondition", "PMD.CompareObjectsWithEquals"}) public class V0_35_40_001__MigrateFailureReasonEnumValues extends BaseJavaMigration { private static final Logger LOGGER = LoggerFactory.getLogger(V0_35_40_001__MigrateFailureReasonEnumValues.class); diff --git a/airbyte-db/db-lib/src/main/java/io/airbyte/db/jdbc/JdbcUtils.java b/airbyte-db/db-lib/src/main/java/io/airbyte/db/jdbc/JdbcUtils.java index 3ff4a6ac1b20..2e1aea25d215 100644 --- a/airbyte-db/db-lib/src/main/java/io/airbyte/db/jdbc/JdbcUtils.java +++ b/airbyte-db/db-lib/src/main/java/io/airbyte/db/jdbc/JdbcUtils.java @@ -87,6 +87,7 @@ public static Map parseJdbcParameters(final String jdbcPropertie return parseJdbcParameters(jdbcPropertiesString, "&"); } + @SuppressWarnings("PMD.AvoidLiteralsInIfCondition") public static Map parseJdbcParameters(final String jdbcPropertiesString, final String delimiter) { final Map parameters = new HashMap<>(); if (!jdbcPropertiesString.isBlank()) { diff --git a/airbyte-db/db-lib/src/main/java/io/airbyte/db/jdbc/streaming/BaseSizeEstimator.java b/airbyte-db/db-lib/src/main/java/io/airbyte/db/jdbc/streaming/BaseSizeEstimator.java index 4892576b9e87..f736d5c4a0b6 100644 --- a/airbyte-db/db-lib/src/main/java/io/airbyte/db/jdbc/streaming/BaseSizeEstimator.java +++ b/airbyte-db/db-lib/src/main/java/io/airbyte/db/jdbc/streaming/BaseSizeEstimator.java @@ -52,6 +52,7 @@ public static long getEstimatedByteSize(final Object rowData) { * This method ensures that the fetch size is between {@code minFetchSize} and {@code maxFetchSize}, * inclusively. */ + @SuppressWarnings("PMD.AvoidLiteralsInIfCondition") protected int getBoundedFetchSize() { if (maxRowByteSize <= 0.0) { return defaultFetchSize; diff --git a/airbyte-db/db-lib/src/main/java/io/airbyte/db/mongodb/MongoDatabase.java b/airbyte-db/db-lib/src/main/java/io/airbyte/db/mongodb/MongoDatabase.java index 680008b0c29b..6a0eccef589b 100644 --- a/airbyte-db/db-lib/src/main/java/io/airbyte/db/mongodb/MongoDatabase.java +++ b/airbyte-db/db-lib/src/main/java/io/airbyte/db/mongodb/MongoDatabase.java @@ -117,7 +117,7 @@ public Stream read(final String collectionName, final List col }); } catch (final Exception e) { - LOGGER.error("Exception attempting to read data from collection: ", collectionName, e.getMessage()); + LOGGER.error("Exception attempting to read data from collection: {}, {}", collectionName, e.getMessage()); throw new RuntimeException(e); } } diff --git a/airbyte-db/db-lib/src/main/java/io/airbyte/db/mongodb/MongoUtils.java b/airbyte-db/db-lib/src/main/java/io/airbyte/db/mongodb/MongoUtils.java index d4a3e20a2702..ab6d24ba8a85 100644 --- a/airbyte-db/db-lib/src/main/java/io/airbyte/db/mongodb/MongoUtils.java +++ b/airbyte-db/db-lib/src/main/java/io/airbyte/db/mongodb/MongoUtils.java @@ -278,6 +278,7 @@ private static List getTypes(final MongoCollection collection, return listOfTypes; } + @SuppressWarnings("PMD.AvoidLiteralsInIfCondition") private static BsonType getUniqueType(final List types) { if (types.size() != 1) { return BsonType.STRING; diff --git a/airbyte-protocol/protocol-models/src/main/java/io/airbyte/protocol/models/CatalogHelpers.java b/airbyte-protocol/protocol-models/src/main/java/io/airbyte/protocol/models/CatalogHelpers.java index e781d8586ced..f1b779757f8f 100644 --- a/airbyte-protocol/protocol-models/src/main/java/io/airbyte/protocol/models/CatalogHelpers.java +++ b/airbyte-protocol/protocol-models/src/main/java/io/airbyte/protocol/models/CatalogHelpers.java @@ -287,7 +287,7 @@ private static boolean isOneOfField(final JsonNode schema) { } private static boolean isObjectWithSubFields(final Field field) { - return field.getType() == JsonSchemaType.OBJECT && field.getSubFields() != null && !field.getSubFields().isEmpty(); + return field.getType().equals(JsonSchemaType.OBJECT) && field.getSubFields() != null && !field.getSubFields().isEmpty(); } public static StreamDescriptor extractStreamDescriptor(final AirbyteStream airbyteStream) { diff --git a/airbyte-protocol/protocol-models/src/main/java/io/airbyte/protocol/models/CommonField.java b/airbyte-protocol/protocol-models/src/main/java/io/airbyte/protocol/models/CommonField.java index 4c12fa5b986b..c5b096f786d4 100644 --- a/airbyte-protocol/protocol-models/src/main/java/io/airbyte/protocol/models/CommonField.java +++ b/airbyte-protocol/protocol-models/src/main/java/io/airbyte/protocol/models/CommonField.java @@ -20,7 +20,7 @@ public CommonField(final String name, final T type) { this.properties = null; } - public CommonField(final String name, final T type, List> properties) { + public CommonField(final String name, final T type, final List> properties) { this.name = name; this.type = type; this.properties = properties; @@ -45,7 +45,7 @@ public boolean equals(final Object o) { final CommonField field = (CommonField) o; return name.equals(field.name) && - type == field.type && Objects.equals(properties, field.properties); + type.equals(field.type) && Objects.equals(properties, field.properties); } @Override diff --git a/airbyte-scheduler/scheduler-models/src/main/java/io/airbyte/scheduler/models/Job.java b/airbyte-scheduler/scheduler-models/src/main/java/io/airbyte/scheduler/models/Job.java index ed2f1de729d9..9447e5713d81 100644 --- a/airbyte-scheduler/scheduler-models/src/main/java/io/airbyte/scheduler/models/Job.java +++ b/airbyte-scheduler/scheduler-models/src/main/java/io/airbyte/scheduler/models/Job.java @@ -91,6 +91,7 @@ public long getUpdatedAtInSecond() { return updatedAtInSecond; } + @SuppressWarnings("PMD.AvoidLiteralsInIfCondition") public Optional getSuccessfulAttempt() { final List successfulAttempts = getAttempts() .stream() diff --git a/airbyte-scheduler/scheduler-persistence/src/main/java/io/airbyte/scheduler/persistence/DefaultJobPersistence.java b/airbyte-scheduler/scheduler-persistence/src/main/java/io/airbyte/scheduler/persistence/DefaultJobPersistence.java index a909c49f85a6..98e3fe2fac61 100644 --- a/airbyte-scheduler/scheduler-persistence/src/main/java/io/airbyte/scheduler/persistence/DefaultJobPersistence.java +++ b/airbyte-scheduler/scheduler-persistence/src/main/java/io/airbyte/scheduler/persistence/DefaultJobPersistence.java @@ -643,7 +643,7 @@ public void setDeployment(final UUID deployment) throws IOException { .orElse(deployment); // if no record was returned that means that the new deployment id was used. if (!deployment.equals(committedDeploymentId)) { - LOGGER.warn("Attempted to set a deployment id %s, but deployment id %s already set. Retained original value."); + LOGGER.warn("Attempted to set a deployment id {}, but deployment id {} already set. Retained original value.", deployment, deployment); } } diff --git a/airbyte-scheduler/scheduler-persistence/src/main/java/io/airbyte/scheduler/persistence/JobCleaner.java b/airbyte-scheduler/scheduler-persistence/src/main/java/io/airbyte/scheduler/persistence/JobCleaner.java index 2002fa92f3ab..f4f4d470fc5d 100644 --- a/airbyte-scheduler/scheduler-persistence/src/main/java/io/airbyte/scheduler/persistence/JobCleaner.java +++ b/airbyte-scheduler/scheduler-persistence/src/main/java/io/airbyte/scheduler/persistence/JobCleaner.java @@ -84,6 +84,7 @@ private void deleteOldFiles() throws IOException { }); } + @SuppressWarnings("PMD.AvoidLiteralsInIfCondition") private void deleteOnSize() throws IOException { final Set nonTerminalJobIds = new HashSet<>(); final Sets.SetView nonTerminalStatuses = Sets.difference(Set.of(JobStatus.values()), JobStatus.TERMINAL_STATUSES); diff --git a/airbyte-scheduler/scheduler-persistence/src/main/java/io/airbyte/scheduler/persistence/job_error_reporter/SentryExceptionHelper.java b/airbyte-scheduler/scheduler-persistence/src/main/java/io/airbyte/scheduler/persistence/job_error_reporter/SentryExceptionHelper.java index 076eabe06a79..28846a841682 100644 --- a/airbyte-scheduler/scheduler-persistence/src/main/java/io/airbyte/scheduler/persistence/job_error_reporter/SentryExceptionHelper.java +++ b/airbyte-scheduler/scheduler-persistence/src/main/java/io/airbyte/scheduler/persistence/job_error_reporter/SentryExceptionHelper.java @@ -20,6 +20,7 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; +@SuppressWarnings("PMD.AvoidLiteralsInIfCondition") public class SentryExceptionHelper { private static final Logger LOGGER = LoggerFactory.getLogger(SentryExceptionHelper.class); diff --git a/airbyte-server/src/main/java/io/airbyte/server/ServerApp.java b/airbyte-server/src/main/java/io/airbyte/server/ServerApp.java index f3b3264c50fe..dde9592ab6d5 100644 --- a/airbyte-server/src/main/java/io/airbyte/server/ServerApp.java +++ b/airbyte-server/src/main/java/io/airbyte/server/ServerApp.java @@ -100,6 +100,7 @@ public ServerApp(final AirbyteVersion airbyteVersion, } @Override + @SuppressWarnings("PMD.InvalidLogMessageFormat") public void start() throws Exception { final Server server = new Server(PORT); @@ -138,7 +139,7 @@ public void start() throws Exception { Runtime.getRuntime().addShutdownHook(new Thread(() -> { try { server.stop(); - } catch (Exception ex) { + } catch (final Exception ex) { // silently fail at this stage because server is terminating. LOGGER.warn("exception: " + ex); } diff --git a/airbyte-server/src/main/java/io/airbyte/server/handlers/ConnectionsHandler.java b/airbyte-server/src/main/java/io/airbyte/server/handlers/ConnectionsHandler.java index cfda5cdf69cb..7c8faa9fa766 100644 --- a/airbyte-server/src/main/java/io/airbyte/server/handlers/ConnectionsHandler.java +++ b/airbyte-server/src/main/java/io/airbyte/server/handlers/ConnectionsHandler.java @@ -317,12 +317,8 @@ public Set getConfigurationDiff(final AirbyteCatalog oldCatalo newStreams.forEach(((streamDescriptor, airbyteStreamConfiguration) -> { final AirbyteStreamConfiguration oldConfig = oldStreams.get(streamDescriptor); - if (oldConfig == null) { - // The stream is a new one, the config has not change and it needs to be in the schema change list. - } else { - if (haveConfigChange(oldConfig, airbyteStreamConfiguration)) { - streamWithDifferentConf.add(streamDescriptor); - } + if (oldConfig != null && haveConfigChange(oldConfig, airbyteStreamConfiguration)) { + streamWithDifferentConf.add(streamDescriptor); } })); diff --git a/airbyte-server/src/main/java/io/airbyte/server/handlers/OperationsHandler.java b/airbyte-server/src/main/java/io/airbyte/server/handlers/OperationsHandler.java index 3ea292642276..ae6ab3be08b7 100644 --- a/airbyte-server/src/main/java/io/airbyte/server/handlers/OperationsHandler.java +++ b/airbyte-server/src/main/java/io/airbyte/server/handlers/OperationsHandler.java @@ -74,12 +74,12 @@ private static StandardSyncOperation toStandardSyncOperation(final OperationCrea .withName(operationCreate.getName()) .withOperatorType(Enums.convertTo(operationCreate.getOperatorConfiguration().getOperatorType(), OperatorType.class)) .withTombstone(false); - if (operationCreate.getOperatorConfiguration().getOperatorType() == io.airbyte.api.model.generated.OperatorType.NORMALIZATION) { + if ((io.airbyte.api.model.generated.OperatorType.NORMALIZATION).equals(operationCreate.getOperatorConfiguration().getOperatorType())) { Preconditions.checkArgument(operationCreate.getOperatorConfiguration().getNormalization() != null); standardSyncOperation.withOperatorNormalization(new OperatorNormalization() .withOption(Enums.convertTo(operationCreate.getOperatorConfiguration().getNormalization().getOption(), Option.class))); } - if (operationCreate.getOperatorConfiguration().getOperatorType() == io.airbyte.api.model.generated.OperatorType.DBT) { + if ((io.airbyte.api.model.generated.OperatorType.DBT).equals(operationCreate.getOperatorConfiguration().getOperatorType())) { Preconditions.checkArgument(operationCreate.getOperatorConfiguration().getDbt() != null); standardSyncOperation.withOperatorDbt(new OperatorDbt() .withGitRepoUrl(operationCreate.getOperatorConfiguration().getDbt().getGitRepoUrl()) @@ -91,10 +91,10 @@ private static StandardSyncOperation toStandardSyncOperation(final OperationCrea } private void validateOperation(final OperatorConfiguration operatorConfiguration) { - if (operatorConfiguration.getOperatorType() == io.airbyte.api.model.generated.OperatorType.NORMALIZATION) { + if ((io.airbyte.api.model.generated.OperatorType.NORMALIZATION).equals(operatorConfiguration.getOperatorType())) { Preconditions.checkArgument(operatorConfiguration.getNormalization() != null); } - if (operatorConfiguration.getOperatorType() == io.airbyte.api.model.generated.OperatorType.DBT) { + if ((io.airbyte.api.model.generated.OperatorType.DBT).equals(operatorConfiguration.getOperatorType())) { Preconditions.checkArgument(operatorConfiguration.getDbt() != null); } } @@ -115,14 +115,14 @@ public static StandardSyncOperation updateOperation(final OperationUpdate operat standardSyncOperation .withName(operationUpdate.getName()) .withOperatorType(Enums.convertTo(operationUpdate.getOperatorConfiguration().getOperatorType(), OperatorType.class)); - if (operationUpdate.getOperatorConfiguration().getOperatorType() == io.airbyte.api.model.generated.OperatorType.NORMALIZATION) { + if ((io.airbyte.api.model.generated.OperatorType.NORMALIZATION).equals(operationUpdate.getOperatorConfiguration().getOperatorType())) { Preconditions.checkArgument(operationUpdate.getOperatorConfiguration().getNormalization() != null); standardSyncOperation.withOperatorNormalization(new OperatorNormalization() .withOption(Enums.convertTo(operationUpdate.getOperatorConfiguration().getNormalization().getOption(), Option.class))); } else { standardSyncOperation.withOperatorNormalization(null); } - if (operationUpdate.getOperatorConfiguration().getOperatorType() == io.airbyte.api.model.generated.OperatorType.DBT) { + if ((io.airbyte.api.model.generated.OperatorType.DBT).equals(operationUpdate.getOperatorConfiguration().getOperatorType())) { Preconditions.checkArgument(operationUpdate.getOperatorConfiguration().getDbt() != null); standardSyncOperation.withOperatorDbt(new OperatorDbt() .withGitRepoUrl(operationUpdate.getOperatorConfiguration().getDbt().getGitRepoUrl()) @@ -174,7 +174,7 @@ public void deleteOperationsForConnection(final StandardSync standardSync, final boolean sharedOperation = false; for (final StandardSync sync : configRepository.listStandardSyncsUsingOperation(operationId)) { // Check if other connections are using the same operation - if (sync.getConnectionId() != standardSync.getConnectionId()) { + if (!sync.getConnectionId().equals(standardSync.getConnectionId())) { sharedOperation = true; break; } @@ -216,12 +216,12 @@ private OperationRead buildOperationRead(final UUID operationId) private static OperationRead buildOperationRead(final StandardSyncOperation standardSyncOperation) { final OperatorConfiguration operatorConfiguration = new OperatorConfiguration() .operatorType(Enums.convertTo(standardSyncOperation.getOperatorType(), io.airbyte.api.model.generated.OperatorType.class)); - if (standardSyncOperation.getOperatorType() == OperatorType.NORMALIZATION) { + if ((OperatorType.NORMALIZATION).equals(standardSyncOperation.getOperatorType())) { Preconditions.checkArgument(standardSyncOperation.getOperatorNormalization() != null); operatorConfiguration.normalization(new io.airbyte.api.model.generated.OperatorNormalization() .option(Enums.convertTo(standardSyncOperation.getOperatorNormalization().getOption(), OptionEnum.class))); } - if (standardSyncOperation.getOperatorType() == OperatorType.DBT) { + if ((OperatorType.DBT).equals(standardSyncOperation.getOperatorType())) { Preconditions.checkArgument(standardSyncOperation.getOperatorDbt() != null); operatorConfiguration.dbt(new io.airbyte.api.model.generated.OperatorDbt() .gitRepoUrl(standardSyncOperation.getOperatorDbt().getGitRepoUrl()) diff --git a/airbyte-server/src/main/java/io/airbyte/server/services/AirbyteGithubStore.java b/airbyte-server/src/main/java/io/airbyte/server/services/AirbyteGithubStore.java index b9683acd7b6d..7c252dee1df9 100644 --- a/airbyte-server/src/main/java/io/airbyte/server/services/AirbyteGithubStore.java +++ b/airbyte-server/src/main/java/io/airbyte/server/services/AirbyteGithubStore.java @@ -81,7 +81,8 @@ String getFile(final String filePathWithSlashPrefix) throws IOException, Interru .header("accept", "*/*") // accept any file type .build(); final var resp = httpClient.send(request, BodyHandlers.ofString()); - if (resp.statusCode() >= 400) { + final Boolean isErrorResponse = resp.statusCode() / 100 != 2; + if (isErrorResponse) { throw new IOException("getFile request ran into status code error: " + resp.statusCode() + "with message: " + resp.getClass()); } return resp.body(); diff --git a/airbyte-server/src/test/java/io/airbyte/server/handlers/ArchiveHandlerTest.java b/airbyte-server/src/test/java/io/airbyte/server/handlers/ArchiveHandlerTest.java index 02e80e50082d..808bb438e2ec 100644 --- a/airbyte-server/src/test/java/io/airbyte/server/handlers/ArchiveHandlerTest.java +++ b/airbyte-server/src/test/java/io/airbyte/server/handlers/ArchiveHandlerTest.java @@ -135,7 +135,7 @@ void setup() throws Exception { jsonSecretsProcessor = JsonSecretsProcessor.builder() .maskSecrets(false) .copySecrets(false) - .build();; + .build(); configPersistence = new DatabaseConfigPersistence(jobDatabase, jsonSecretsProcessor); configPersistence.replaceAllConfigs(Collections.emptyMap(), false); configPersistence.loadData(seedPersistence); diff --git a/airbyte-tests/src/acceptanceTests/java/io/airbyte/test/acceptance/CdcAcceptanceTests.java b/airbyte-tests/src/acceptanceTests/java/io/airbyte/test/acceptance/CdcAcceptanceTests.java index bb2bd5c349d8..429652c2a0c5 100644 --- a/airbyte-tests/src/acceptanceTests/java/io/airbyte/test/acceptance/CdcAcceptanceTests.java +++ b/airbyte-tests/src/acceptanceTests/java/io/airbyte/test/acceptance/CdcAcceptanceTests.java @@ -505,6 +505,7 @@ private SourceRead createCdcSource() throws ApiException { Jsons.jsonNode(sourceDbConfigMap)); } + @SuppressWarnings("PMD.AvoidLiteralsInIfCondition") private void assertDestinationMatches(final String streamName, final List expectedDestRecordMatchers) throws Exception { final List destRecords = testHarness.retrieveRawDestinationRecords(new SchemaTableNamePair(SCHEMA_NAME, streamName)); diff --git a/airbyte-tests/src/automaticMigrationAcceptanceTest/java/io/airbyte/test/automaticMigrationAcceptance/ImportApi.java b/airbyte-tests/src/automaticMigrationAcceptanceTest/java/io/airbyte/test/automaticMigrationAcceptance/ImportApi.java index 6a614e76b353..0b00ba9d7543 100644 --- a/airbyte-tests/src/automaticMigrationAcceptanceTest/java/io/airbyte/test/automaticMigrationAcceptance/ImportApi.java +++ b/airbyte-tests/src/automaticMigrationAcceptanceTest/java/io/airbyte/test/automaticMigrationAcceptance/ImportApi.java @@ -62,7 +62,7 @@ public ApiResponse importArchiveWithHttpInfo(final File body) throws if (memberVarResponseInterceptor != null) { memberVarResponseInterceptor.accept(localVarResponse); } - if (localVarResponse.statusCode() / 100 != 2) { + if (errorResponse(localVarResponse)) { throw new ApiException(localVarResponse.statusCode(), "importArchive call received non-success response", localVarResponse.headers(), @@ -81,6 +81,10 @@ public ApiResponse importArchiveWithHttpInfo(final File body) throws } } + private Boolean errorResponse(final HttpResponse localVarResponse) { + return localVarResponse.statusCode() / 100 != 2; + } + private HttpRequest.Builder importArchiveRequestBuilder(final File body) throws ApiException { // verify the required parameter 'body' is set if (body == null) { diff --git a/airbyte-workers/src/main/java/io/airbyte/workers/general/DefaultGetSpecWorker.java b/airbyte-workers/src/main/java/io/airbyte/workers/general/DefaultGetSpecWorker.java index 711ce2ca18b7..745b1ccbaf37 100644 --- a/airbyte-workers/src/main/java/io/airbyte/workers/general/DefaultGetSpecWorker.java +++ b/airbyte-workers/src/main/java/io/airbyte/workers/general/DefaultGetSpecWorker.java @@ -73,7 +73,7 @@ public ConnectorJobOutput run(final JobGetSpecConfig config, final Path jobRoot) final Optional spec = messagesByType .getOrDefault(Type.SPEC, new ArrayList<>()).stream() .map(AirbyteMessage::getSpec) - .findFirst();; + .findFirst(); final int exitCode = process.exitValue(); if (exitCode == 0) { diff --git a/airbyte-workers/src/main/java/io/airbyte/workers/general/DefaultReplicationWorker.java b/airbyte-workers/src/main/java/io/airbyte/workers/general/DefaultReplicationWorker.java index b91cde3c4c64..28be935591ed 100644 --- a/airbyte-workers/src/main/java/io/airbyte/workers/general/DefaultReplicationWorker.java +++ b/airbyte-workers/src/main/java/io/airbyte/workers/general/DefaultReplicationWorker.java @@ -307,6 +307,7 @@ else if (hasFailed.get()) { } + @SuppressWarnings("PMD.AvoidInstanceofChecksInCatchClause") private static Runnable getReplicationRunnable(final AirbyteSource source, final AirbyteDestination destination, final AtomicBoolean cancelled, @@ -419,6 +420,7 @@ private static void validateSchema(final RecordSchemaValidator recordSchemaValid } } + @SuppressWarnings("PMD.AvoidInstanceofChecksInCatchClause") private static Runnable getDestinationOutputRunnable(final AirbyteDestination destination, final AtomicBoolean cancelled, final MessageTracker messageTracker, diff --git a/airbyte-workers/src/main/java/io/airbyte/workers/helper/EntrypointEnvChecker.java b/airbyte-workers/src/main/java/io/airbyte/workers/helper/EntrypointEnvChecker.java index b4e360f3437f..9b59867ada27 100644 --- a/airbyte-workers/src/main/java/io/airbyte/workers/helper/EntrypointEnvChecker.java +++ b/airbyte-workers/src/main/java/io/airbyte/workers/helper/EntrypointEnvChecker.java @@ -27,6 +27,7 @@ public class EntrypointEnvChecker { * @return the entrypoint in the env variable AIRBYTE_ENTRYPOINT * @throws RuntimeException if there is ambiguous output from the container */ + @SuppressWarnings("PMD.AvoidLiteralsInIfCondition") public static String getEntrypointEnvVariable(final ProcessFactory processFactory, final String jobId, final int jobAttempt, diff --git a/airbyte-workers/src/main/java/io/airbyte/workers/internal/DefaultAirbyteStreamFactory.java b/airbyte-workers/src/main/java/io/airbyte/workers/internal/DefaultAirbyteStreamFactory.java index ecf4f993476c..d871755ec67d 100644 --- a/airbyte-workers/src/main/java/io/airbyte/workers/internal/DefaultAirbyteStreamFactory.java +++ b/airbyte-workers/src/main/java/io/airbyte/workers/internal/DefaultAirbyteStreamFactory.java @@ -25,6 +25,7 @@ * AirbyteMessage will still be parsed. If there are multiple AirbyteMessage records on the same * line, only the first will be parsed. */ +@SuppressWarnings("PMD.MoreThanOneLogger") public class DefaultAirbyteStreamFactory implements AirbyteStreamFactory { private static final Logger LOGGER = LoggerFactory.getLogger(DefaultAirbyteStreamFactory.class); diff --git a/airbyte-workers/src/main/java/io/airbyte/workers/internal/StateMetricsTracker.java b/airbyte-workers/src/main/java/io/airbyte/workers/internal/StateMetricsTracker.java index 30ad22ccd2a0..fe33d638ea72 100644 --- a/airbyte-workers/src/main/java/io/airbyte/workers/internal/StateMetricsTracker.java +++ b/airbyte-workers/src/main/java/io/airbyte/workers/internal/StateMetricsTracker.java @@ -101,6 +101,7 @@ void addStateMessageToStreamToStateHashTimestampTracker(final AirbyteStateMessag remainingCapacity -= 1; } + @SuppressWarnings("PMD.AvoidLiteralsInIfCondition") void updateMaxAndMeanSeconds(final LocalDateTime startingTime, final LocalDateTime timeCommitted) { final Long secondsUntilCommit = calculateSecondsBetweenStateEmittedAndCommitted(startingTime, timeCommitted); if (maxSecondsBetweenStateMessageEmittedandCommitted < secondsUntilCommit) { diff --git a/airbyte-workers/src/main/java/io/airbyte/workers/normalization/DefaultNormalizationRunner.java b/airbyte-workers/src/main/java/io/airbyte/workers/normalization/DefaultNormalizationRunner.java index 0b5e3fa813f4..2e1b88349f18 100644 --- a/airbyte-workers/src/main/java/io/airbyte/workers/normalization/DefaultNormalizationRunner.java +++ b/airbyte-workers/src/main/java/io/airbyte/workers/normalization/DefaultNormalizationRunner.java @@ -126,6 +126,7 @@ public boolean normalize(final String jobId, "--catalog", WorkerConstants.DESTINATION_CATALOG_JSON_FILENAME); } + @SuppressWarnings("PMD.AvoidLiteralsInIfCondition") private boolean runProcess(final String jobId, final int attempt, final Path jobRoot, @@ -160,7 +161,7 @@ private boolean runProcess(final String jobId, dbtErrorStack = String.join("\n", streamFactory.getDbtErrors()); if (!"".equals(dbtErrorStack)) { - AirbyteMessage dbtTraceMessage = new AirbyteMessage() + final AirbyteMessage dbtTraceMessage = new AirbyteMessage() .withType(Type.TRACE) .withTrace(new AirbyteTraceMessage() .withType(AirbyteTraceMessage.Type.ERROR) @@ -213,7 +214,7 @@ public Stream getTraceMessages() { } private String buildInternalErrorMessageFromDbtStackTrace() { - Map errorMap = SentryExceptionHelper.getUsefulErrorMessageAndTypeFromDbtError(dbtErrorStack); + final Map errorMap = SentryExceptionHelper.getUsefulErrorMessageAndTypeFromDbtError(dbtErrorStack); return errorMap.get(SentryExceptionHelper.ERROR_MAP_KEYS.ERROR_MAP_MESSAGE_KEY); } diff --git a/airbyte-workers/src/main/java/io/airbyte/workers/normalization/NormalizationAirbyteStreamFactory.java b/airbyte-workers/src/main/java/io/airbyte/workers/normalization/NormalizationAirbyteStreamFactory.java index 451af9bd46f3..3cd8385fdd4f 100644 --- a/airbyte-workers/src/main/java/io/airbyte/workers/normalization/NormalizationAirbyteStreamFactory.java +++ b/airbyte-workers/src/main/java/io/airbyte/workers/normalization/NormalizationAirbyteStreamFactory.java @@ -29,6 +29,7 @@ * AirbyteMessage will still be parsed. If there are multiple AirbyteMessage records on the same * line, only the first will be parsed. */ +@SuppressWarnings("PMD.MoreThanOneLogger") public class NormalizationAirbyteStreamFactory implements AirbyteStreamFactory { private static final Logger LOGGER = LoggerFactory.getLogger(NormalizationAirbyteStreamFactory.class); @@ -64,7 +65,7 @@ public Stream create(final BufferedReader bufferedReader) { }); } - private Stream filterOutAndHandleNonJsonLines(String line) { + private Stream filterOutAndHandleNonJsonLines(final String line) { final Optional jsonLine = Jsons.tryDeserialize(line); if (jsonLine.isEmpty()) { // we log as info all the lines that are not valid json. @@ -81,7 +82,7 @@ private Stream filterOutAndHandleNonJsonLines(String line) { return jsonLine.stream(); } - private Stream filterOutAndHandleNonAirbyteMessageLines(JsonNode jsonLine) { + private Stream filterOutAndHandleNonAirbyteMessageLines(final JsonNode jsonLine) { final Optional m = Jsons.tryObject(jsonLine, AirbyteMessage.class); if (m.isEmpty()) { // valid JSON but not an AirbyteMessage, so we assume this is a dbt json log @@ -106,7 +107,7 @@ private Stream filterOutAndHandleNonAirbyteMessageLines(JsonNode return m.stream(); } - private void logAndCollectErrorMessage(String logMsg) { + private void logAndCollectErrorMessage(final String logMsg) { logger.error(logMsg); dbtErrors.add(logMsg); } diff --git a/airbyte-workers/src/main/java/io/airbyte/workers/process/KubePodProcess.java b/airbyte-workers/src/main/java/io/airbyte/workers/process/KubePodProcess.java index 649dcd3afbec..793b0f0dc47b 100644 --- a/airbyte-workers/src/main/java/io/airbyte/workers/process/KubePodProcess.java +++ b/airbyte-workers/src/main/java/io/airbyte/workers/process/KubePodProcess.java @@ -346,6 +346,7 @@ private Toleration[] buildPodTolerations(final List tolerations) .toArray(Toleration[]::new); } + @SuppressWarnings("PMD.InvalidLogMessageFormat") public KubePodProcess(final boolean isOrchestrator, final String processRunnerHost, final KubernetesClient fabricClient, diff --git a/airbyte-workers/src/main/java/io/airbyte/workers/run/WorkerRun.java b/airbyte-workers/src/main/java/io/airbyte/workers/run/WorkerRun.java index bf46faaaa30d..33dd11a69306 100644 --- a/airbyte-workers/src/main/java/io/airbyte/workers/run/WorkerRun.java +++ b/airbyte-workers/src/main/java/io/airbyte/workers/run/WorkerRun.java @@ -19,6 +19,7 @@ * outputs are passed to the selected worker. It also makes sure that the outputs of the worker are * persisted to the db. */ +@SuppressWarnings("PMD.AvoidFieldNameMatchingTypeName") public class WorkerRun implements Callable> { private static final Logger LOGGER = LoggerFactory.getLogger(WorkerRun.class); diff --git a/tools/gradle/pmd/rules.xml b/tools/gradle/pmd/rules.xml index 1d2244ca3d3c..982518c448f5 100644 --- a/tools/gradle/pmd/rules.xml +++ b/tools/gradle/pmd/rules.xml @@ -101,20 +101,8 @@ - - - - - - - - - - - -