From ce697d215d6035a40904c74db8bb9515177e4870 Mon Sep 17 00:00:00 2001 From: Emmanuel GALLOIS Date: Thu, 21 May 2026 17:56:10 +0200 Subject: [PATCH 1/2] chore(QTDI-2893): use pattern matching for instanceof (S6201) Replace `instanceof` + manual cast patterns with Java 17 pattern matching for instanceof to reduce Sonar warnings (java:S6201). Both `(X) value` and `X.class.cast(value)` cast forms are handled. Excluded cases: - Conditions combined with `||` (pattern matching incompatible with alternation): AvroSchemaCache, SchemaConverter (Double||Float). - ParameterSetter#set: target variable declared outside the `if` block (would require restructuring). - Casts to a type different from the `instanceof` check (not S6201). --- .../beam/spi/record/AvroEntryBuilder.java | 3 +- .../runtime/beam/spi/record/AvroRecord.java | 46 +++++++++---------- .../beam/spi/record/AvroSchemaCache.java | 3 +- .../component/runtime/record/RecordImpl.java | 20 ++++---- .../runtime/manager/ComponentManager.java | 6 +-- .../manager/service/ServiceHelper.java | 4 +- .../xbean/converter/SchemaConverter.java | 32 ++++++------- .../service/ProducerFinderImplTest.java | 4 +- .../internal/impl/DefaultResponseLocator.java | 3 +- .../component/runtime/di/OutputsHandler.java | 8 ++-- .../runtime/di/schema/TaCoKitGuessSchema.java | 40 ++++++++-------- .../di/studio/AfterVariableExtracter.java | 4 +- .../runtime/di/studio/ParameterSetter.java | 4 +- .../di/studio/RuntimeContextInjector.java | 4 +- .../tools/validator/ActionValidator.java | 4 +- 15 files changed, 89 insertions(+), 96 deletions(-) diff --git a/component-runtime-beam/src/main/java/org/talend/sdk/component/runtime/beam/spi/record/AvroEntryBuilder.java b/component-runtime-beam/src/main/java/org/talend/sdk/component/runtime/beam/spi/record/AvroEntryBuilder.java index 64eaee291f903..69e96ba8792ab 100644 --- a/component-runtime-beam/src/main/java/org/talend/sdk/component/runtime/beam/spi/record/AvroEntryBuilder.java +++ b/component-runtime-beam/src/main/java/org/talend/sdk/component/runtime/beam/spi/record/AvroEntryBuilder.java @@ -22,8 +22,7 @@ public class AvroEntryBuilder extends SchemaImpl.EntryImpl.BuilderImpl { @Override public Schema.Entry.Builder withElementSchema(final Schema schema) { - if (schema instanceof AvroSchema) { - final AvroSchema innerSchema = (AvroSchema) schema; + if (schema instanceof AvroSchema innerSchema) { AvroSchema avroSchema = this.authorizeNull(innerSchema); return super.withElementSchema(avroSchema); } diff --git a/component-runtime-beam/src/main/java/org/talend/sdk/component/runtime/beam/spi/record/AvroRecord.java b/component-runtime-beam/src/main/java/org/talend/sdk/component/runtime/beam/spi/record/AvroRecord.java index 40fda0d05c3cc..14958d3ffe2f1 100644 --- a/component-runtime-beam/src/main/java/org/talend/sdk/component/runtime/beam/spi/record/AvroRecord.java +++ b/component-runtime-beam/src/main/java/org/talend/sdk/component/runtime/beam/spi/record/AvroRecord.java @@ -74,8 +74,7 @@ public AvroRecord(final IndexedRecord record) { } public AvroRecord(final Record record) { - if (record instanceof AvroRecord) { - final AvroRecord avr = (AvroRecord) record; + if (record instanceof AvroRecord avr) { this.delegate = avr.delegate; this.schema = avr.schema; return; @@ -105,12 +104,12 @@ private Object directMapping(final Object value, final Schema.Entry entry) { // RecordImpl store BigDecimal directly, no any convert as not necessary, so here need to convert to string for // beam's AvroCoder which cloud platform use // also here for any Collection as Array type - if (value instanceof BigDecimal) { - return BigDecimal.class.cast(value).toString(); + if (value instanceof BigDecimal bigDecimal) { + return bigDecimal.toString(); } - if (value instanceof Collection) { - return Collection.class.cast(value).stream().map(v -> this.directMapping(v, entry)).collect(toList()); + if (value instanceof Collection collection) { + return collection.stream().map(v -> this.directMapping(v, entry)).collect(toList()); } if (value instanceof RecordImpl) { return new AvroRecord((Record) value).delegate; @@ -118,28 +117,28 @@ private Object directMapping(final Object value, final Schema.Entry entry) { if (value instanceof Record) { return Unwrappable.class.cast(value).unwrap(IndexedRecord.class); } - if (value instanceof ZonedDateTime) { - return ZonedDateTime.class.cast(value).toInstant().toEpochMilli(); + if (value instanceof ZonedDateTime zonedDateTime) { + return zonedDateTime.toInstant().toEpochMilli(); } - if (value instanceof Date) { - return Date.class.cast(value).getTime(); + if (value instanceof Date date) { + return date.getTime(); } - if (value instanceof byte[]) { - return ByteBuffer.wrap(byte[].class.cast(value)); + if (value instanceof byte[] bytes) { + return ByteBuffer.wrap(bytes); } - if (value instanceof Long) { + if (value instanceof Long longValue) { String logicalType = entry.getLogicalType(); if (logicalType != null) { if (SchemaProperty.LogicalType.DATE.key().equals(logicalType)) { return Math.toIntExact( - Instant.ofEpochMilli((Long) value) + Instant.ofEpochMilli(longValue) .atZone(UTC) .toLocalDate() .toEpochDay()); // Avro stores dates as int } else if (LogicalType.TIME.key().equals(logicalType)) { // QTDI-1252: Avro time-millis logical type stores int milliseconds from 0:00:00 not from Unix Epoch - final Instant instant = Instant.ofEpochMilli((Long) value); + final Instant instant = Instant.ofEpochMilli(longValue); final ZonedDateTime zonedDateTime = instant.atZone(UTC); return Math.toIntExact(zonedDateTime.toLocalTime().toNanoOfDay() / 1_000_000); } @@ -245,12 +244,13 @@ private T doMap(final Class expectedType, final org.apache.avro.Schema fi return expectedType.cast(value); } - if (value instanceof IndexedRecord && (Record.class == expectedType || Object.class == expectedType)) { - return expectedType.cast(new AvroRecord(IndexedRecord.class.cast(value))); + if (value instanceof IndexedRecord indexedRecord + && (Record.class == expectedType || Object.class == expectedType)) { + return expectedType.cast(new AvroRecord(indexedRecord)); } - if (value instanceof ByteBuffer && byte[].class == expectedType) { - return expectedType.cast(ByteBuffer.class.cast(value).array()); + if (value instanceof ByteBuffer byteBuffer && byte[].class == expectedType) { + return expectedType.cast(byteBuffer.array()); } final org.apache.avro.Schema fieldSchema = unwrapUnion(fieldSchemaRaw); @@ -311,8 +311,8 @@ private T doMap(final Class expectedType, final org.apache.avro.Schema fi .cast(doMapCollection(itemType, Collection.class.cast(value), fieldSchema.getElementType())); } - if (value instanceof org.joda.time.DateTime && ZonedDateTime.class == expectedType) { - final long epochMilli = org.joda.time.DateTime.class.cast(value).getMillis(); + if (value instanceof org.joda.time.DateTime dateTime && ZonedDateTime.class == expectedType) { + final long epochMilli = dateTime.getMillis(); return expectedType.cast(ZonedDateTime.ofInstant(java.time.Instant.ofEpochMilli(epochMilli), UTC)); } @@ -338,7 +338,7 @@ private T doMap(final Class expectedType, final org.apache.avro.Schema fi if (value instanceof Utf8 && Object.class == expectedType) { return expectedType.cast(value.toString()); } - if (Collection.class.isAssignableFrom(expectedType) && value instanceof Collection) { + if (Collection.class.isAssignableFrom(expectedType) && value instanceof Collection collection) { final org.apache.avro.Schema elementType = fieldSchema.getElementType(); final org.apache.avro.Schema elementSchema = unwrapUnion(elementType); Class toType = Object.class; @@ -347,7 +347,7 @@ private T doMap(final Class expectedType, final org.apache.avro.Schema fi } else if (elementSchema.getType() == org.apache.avro.Schema.Type.ARRAY) { toType = Collection.class; } - final Collection objects = this.doMapCollection(toType, Collection.class.cast(value), elementSchema); + final Collection objects = this.doMapCollection(toType, collection, elementSchema); return expectedType.cast(objects); } return expectedType.cast(value); diff --git a/component-runtime-beam/src/main/java/org/talend/sdk/component/runtime/beam/spi/record/AvroSchemaCache.java b/component-runtime-beam/src/main/java/org/talend/sdk/component/runtime/beam/spi/record/AvroSchemaCache.java index 965e7611fd08a..14eaaadf53664 100644 --- a/component-runtime-beam/src/main/java/org/talend/sdk/component/runtime/beam/spi/record/AvroSchemaCache.java +++ b/component-runtime-beam/src/main/java/org/talend/sdk/component/runtime/beam/spi/record/AvroSchemaCache.java @@ -42,8 +42,7 @@ public AvroSchema find(final Schema schema) { if (schema == null || schema instanceof AvroSchema) { return (AvroSchema) schema; } - if (schema instanceof SchemaImpl) { - final SchemaImpl realSchema = (SchemaImpl) schema; + if (schema instanceof SchemaImpl realSchema) { if ((!this.cache.containsKey(realSchema)) && this.cache.size() >= AvroSchemaCache.MAX_SIZE) { this.removeOldest(); diff --git a/component-runtime-impl/src/main/java/org/talend/sdk/component/runtime/record/RecordImpl.java b/component-runtime-impl/src/main/java/org/talend/sdk/component/runtime/record/RecordImpl.java index f56961dfca2ff..1602d11f66641 100644 --- a/component-runtime-impl/src/main/java/org/talend/sdk/component/runtime/record/RecordImpl.java +++ b/component-runtime-impl/src/main/java/org/talend/sdk/component/runtime/record/RecordImpl.java @@ -193,16 +193,16 @@ public Builder with(final Entry entry, final Object value) { if (entry.getType() == Schema.Type.DATETIME) { if (value == null) { withDateTime(entry, (ZonedDateTime) value); - } else if (value instanceof Long) { - withTimestamp(entry, (Long) value); - } else if (value instanceof Date) { - withDateTime(entry, (Date) value); - } else if (value instanceof ZonedDateTime) { - withDateTime(entry, (ZonedDateTime) value); - } else if (value instanceof Instant) { - withInstant(entry, (Instant) value); - } else if (value instanceof Temporal) { - withTimestamp(entry, ((Temporal) value).get(ChronoField.INSTANT_SECONDS) * 1000L); + } else if (value instanceof Long longValue) { + withTimestamp(entry, longValue); + } else if (value instanceof Date date) { + withDateTime(entry, date); + } else if (value instanceof ZonedDateTime zonedDateTime) { + withDateTime(entry, zonedDateTime); + } else if (value instanceof Instant instant) { + withInstant(entry, instant); + } else if (value instanceof Temporal temporal) { + withTimestamp(entry, temporal.get(ChronoField.INSTANT_SECONDS) * 1000L); } return this; } else { diff --git a/component-runtime-manager/src/main/java/org/talend/sdk/component/runtime/manager/ComponentManager.java b/component-runtime-manager/src/main/java/org/talend/sdk/component/runtime/manager/ComponentManager.java index b510ffffd1ecb..5f718f65c919b 100644 --- a/component-runtime-manager/src/main/java/org/talend/sdk/component/runtime/manager/ComponentManager.java +++ b/component-runtime-manager/src/main/java/org/talend/sdk/component/runtime/manager/ComponentManager.java @@ -781,14 +781,12 @@ public ParameterMeta findDatastoreParameterMeta(final String plugin, final Strin */ public static Map jsonToMap(final JsonValue jsonValue, final String path) { final Map result = new HashMap<>(); - if (jsonValue instanceof JsonObject) { - JsonObject jsonObj = (JsonObject) jsonValue; + if (jsonValue instanceof JsonObject jsonObj) { for (String key : jsonObj.keySet()) { String newPath = path.isEmpty() ? key : path + "." + key; result.putAll(jsonToMap(jsonObj.get(key), newPath)); } - } else if (jsonValue instanceof JsonArray) { - JsonArray jsonArray = (JsonArray) jsonValue; + } else if (jsonValue instanceof JsonArray jsonArray) { for (int i = 0; i < jsonArray.size(); i++) { String newPath = path + "[" + i + "]"; result.putAll(jsonToMap(jsonArray.get(i), newPath)); diff --git a/component-runtime-manager/src/main/java/org/talend/sdk/component/runtime/manager/service/ServiceHelper.java b/component-runtime-manager/src/main/java/org/talend/sdk/component/runtime/manager/service/ServiceHelper.java index df71b68221c60..0afa6685d1bca 100644 --- a/component-runtime-manager/src/main/java/org/talend/sdk/component/runtime/manager/service/ServiceHelper.java +++ b/component-runtime-manager/src/main/java/org/talend/sdk/component/runtime/manager/service/ServiceHelper.java @@ -57,8 +57,8 @@ public Object createServiceInstance(final ClassLoader loader, final String conta .initialize(instance, new InterceptorHandlerFacade(serviceClass.getConstructor().newInstance(), allServices)); } - if (instance instanceof BaseService) { - this.updateService((BaseService) instance, containerId, serviceClass.getName()); + if (instance instanceof BaseService baseService) { + this.updateService(baseService, containerId, serviceClass.getName()); } return instance; } catch (final InstantiationException | IllegalAccessException e) { diff --git a/component-runtime-manager/src/main/java/org/talend/sdk/component/runtime/manager/xbean/converter/SchemaConverter.java b/component-runtime-manager/src/main/java/org/talend/sdk/component/runtime/manager/xbean/converter/SchemaConverter.java index 8f51b1dc4fd2a..c6231dc3a4179 100644 --- a/component-runtime-manager/src/main/java/org/talend/sdk/component/runtime/manager/xbean/converter/SchemaConverter.java +++ b/component-runtime-manager/src/main/java/org/talend/sdk/component/runtime/manager/xbean/converter/SchemaConverter.java @@ -98,8 +98,8 @@ private Schema toSchema(final JsonObject json) { this.addProps(builder::withProp, json); final JsonValue orderValue = json.get("order"); - if (orderValue instanceof JsonString) { - final Schema.EntriesOrder order = Schema.EntriesOrder.of(((JsonString) orderValue).getString()); + if (orderValue instanceof JsonString jsonString) { + final Schema.EntriesOrder order = Schema.EntriesOrder.of(jsonString.getString()); return builder.build(order); } else { return builder.build(); @@ -109,11 +109,11 @@ private Schema toSchema(final JsonObject json) { private void treatElementSchema(final JsonObject json, final Consumer setter) { final JsonValue elementSchema = json.get(ELEMENT_SCHEMA); - if (elementSchema instanceof JsonObject) { - final Schema schema = this.toSchema((JsonObject) elementSchema); + if (elementSchema instanceof JsonObject jsonObject) { + final Schema schema = this.toSchema(jsonObject); setter.accept(schema); - } else if (elementSchema instanceof JsonString) { - final Schema.Type innerType = Schema.Type.valueOf(((JsonString) elementSchema).getString()); + } else if (elementSchema instanceof JsonString jsonString) { + final Schema.Type innerType = Schema.Type.valueOf(jsonString.getString()); setter.accept(this.factory.newSchemaBuilder(innerType).build()); } } @@ -276,17 +276,17 @@ private JsonValue toValue(final Object object) { if (object == null) { return JsonValue.NULL; } - if (object instanceof Integer) { - return Json.createValue((Integer) object); + if (object instanceof Integer i) { + return Json.createValue(i); } - if (object instanceof Long) { - return Json.createValue((Long) object); + if (object instanceof Long l) { + return Json.createValue(l); } if (object instanceof Double || object instanceof Float) { return Json.createValue((Double) object); } - if (object instanceof BigInteger) { - return Json.createValue((BigInteger) object); + if (object instanceof BigInteger bi) { + return Json.createValue(bi); } if (object instanceof Boolean) { if (object == Boolean.TRUE) { @@ -294,11 +294,11 @@ private JsonValue toValue(final Object object) { } return JsonValue.FALSE; } - if (object instanceof BigDecimal) { - return Json.createValue((BigDecimal) object); + if (object instanceof BigDecimal bd) { + return Json.createValue(bd); } - if (object instanceof String) { - return Json.createValue((String) object); + if (object instanceof String s) { + return Json.createValue(s); } return null; diff --git a/component-runtime-manager/src/test/java/org/talend/sdk/component/runtime/manager/service/ProducerFinderImplTest.java b/component-runtime-manager/src/test/java/org/talend/sdk/component/runtime/manager/service/ProducerFinderImplTest.java index 79034d8e80770..6b229189412f6 100644 --- a/component-runtime-manager/src/test/java/org/talend/sdk/component/runtime/manager/service/ProducerFinderImplTest.java +++ b/component-runtime-manager/src/test/java/org/talend/sdk/component/runtime/manager/service/ProducerFinderImplTest.java @@ -77,8 +77,8 @@ void findException() { } private Record toRecord(final Object object) { - if (object instanceof Record) { - return (Record) object; + if (object instanceof Record rcd) { + return rcd; } return null; } diff --git a/component-runtime-testing/component-runtime-http-junit/src/main/java/org/talend/sdk/component/junit/http/internal/impl/DefaultResponseLocator.java b/component-runtime-testing/component-runtime-http-junit/src/main/java/org/talend/sdk/component/junit/http/internal/impl/DefaultResponseLocator.java index 8b4a82dd85e6c..e0481145dbdf3 100644 --- a/component-runtime-testing/component-runtime-http-junit/src/main/java/org/talend/sdk/component/junit/http/internal/impl/DefaultResponseLocator.java +++ b/component-runtime-testing/component-runtime-http-junit/src/main/java/org/talend/sdk/component/junit/http/internal/impl/DefaultResponseLocator.java @@ -254,8 +254,7 @@ public int hashCode() { public boolean equals(final Object obj) { if (this == obj) { return true; - } else if (obj instanceof ParameterizedType) { - final ParameterizedType that = (ParameterizedType) obj; + } else if (obj instanceof ParameterizedType that) { final Type thatRawType = that.getRawType(); return that.getOwnerType() == null && (rawType == null ? thatRawType == null : rawType.equals(thatRawType)) diff --git a/component-studio/component-runtime-di/src/main/java/org/talend/sdk/component/runtime/di/OutputsHandler.java b/component-studio/component-runtime-di/src/main/java/org/talend/sdk/component/runtime/di/OutputsHandler.java index 5d9a30e1c07d4..1f49e1554244d 100644 --- a/component-studio/component-runtime-di/src/main/java/org/talend/sdk/component/runtime/di/OutputsHandler.java +++ b/component-studio/component-runtime-di/src/main/java/org/talend/sdk/component/runtime/di/OutputsHandler.java @@ -46,8 +46,8 @@ public OutputFactory asOutputFactory() { if (ref != null && value != null) { if (value instanceof javax.json.JsonValue) { ref.add(jsonb.fromJson(value.toString(), ref.getType())); - } else if (value instanceof Record) { - ref.add(registry.find(ref.getType()).newInstance(Record.class.cast(value))); + } else if (value instanceof Record rcd) { + ref.add(registry.find(ref.getType()).newInstance(rcd)); } else { ref.add(jsonb.fromJson(jsonb.toJson(value), ref.getType())); } @@ -67,8 +67,8 @@ public OutputFactory asOutputFactoryForGuessSchema() { if (ref != null && value != null) { if (value instanceof javax.json.JsonValue) { ref.add(jsonb.fromJson(value.toString(), ref.getType())); - } else if (value instanceof Record) { - ref.add(((Record) value).getSchema()); + } else if (value instanceof Record rcd) { + ref.add(rcd.getSchema()); } else if (value instanceof Schema) { ref.add(value); } else { diff --git a/component-studio/component-runtime-di/src/main/java/org/talend/sdk/component/runtime/di/schema/TaCoKitGuessSchema.java b/component-studio/component-runtime-di/src/main/java/org/talend/sdk/component/runtime/di/schema/TaCoKitGuessSchema.java index 9c72735b566d5..6e36e7afea1dd 100644 --- a/component-studio/component-runtime-di/src/main/java/org/talend/sdk/component/runtime/di/schema/TaCoKitGuessSchema.java +++ b/component-studio/component-runtime-di/src/main/java/org/talend/sdk/component/runtime/di/schema/TaCoKitGuessSchema.java @@ -174,10 +174,10 @@ private void initClass2JavaTypeMap() { private DiscoverSchemaException transformException(final Exception e) { DiscoverSchemaException discoverSchemaException; - if (e instanceof DiscoverSchemaException) { - discoverSchemaException = DiscoverSchemaException.class.cast(e); - } else if (e instanceof ComponentException) { - discoverSchemaException = new DiscoverSchemaException((ComponentException) e); + if (e instanceof DiscoverSchemaException dse) { + discoverSchemaException = dse; + } else if (e instanceof ComponentException ce) { + discoverSchemaException = new DiscoverSchemaException(ce); } else { discoverSchemaException = new DiscoverSchemaException(e.getMessage(), e.getStackTrace(), EXCEPTION); } @@ -253,12 +253,11 @@ private void executeDiscoverSchemaExtendedAction(final Schema schema, final Stri } final Object schemaResult = actionRef.getInvoker().apply(buildActionConfig(actionRef, configuration, schema, branch)); - if (schemaResult instanceof Schema) { - final Schema result = (Schema) schemaResult; + if (schemaResult instanceof Schema result) { if (result.getEntries().isEmpty()) { throw new DiscoverSchemaException(ERROR_NO_AVAILABLE_SCHEMA_FOUND, EXCEPTION); } else { - fromSchema(Schema.class.cast(schemaResult)); + fromSchema(result); } } } @@ -468,8 +467,8 @@ public boolean guessSchemaThroughAction(final Schema schema) { : buildActionConfig(actionRef, configuration, schema, "INPUT"); final Object schemaResult = actionRef.getInvoker().apply(actionConfiguration); - if (schemaResult instanceof Schema) { - return fromSchema(Schema.class.cast(schemaResult)); + if (schemaResult instanceof Schema resultSchema) { + return fromSchema(resultSchema); } else { log.error(ERROR_INSTANCE_SCHEMA); @@ -501,8 +500,7 @@ private boolean fromSchema(final Schema schema) { public Collection getFixedSchema(final String execute) { SchemaConverter sc = new SchemaConverter(); Object o = sc.toObjectImpl(execute); - if (o instanceof Schema) { - final Schema schema = Schema.class.cast(o); + if (o instanceof Schema schema) { final Collection entries = schema.getEntries(); if (entries == null || entries.isEmpty()) { log.info(NO_COLUMN_FOUND_BY_GUESS_SCHEMA); @@ -675,10 +673,10 @@ private boolean guessInputComponentSchemaThroughResult() throws Exception { if (rowObject == null) { return false; } - if (rowObject instanceof Record) { - return fromSchema(Record.class.cast(rowObject).getSchema()); - } else if (rowObject instanceof java.util.Map) { - return guessInputSchemaThroughResults(input, (java.util.Map) rowObject); + if (rowObject instanceof Record record) { + return fromSchema(record.getSchema()); + } else if (rowObject instanceof java.util.Map map) { + return guessInputSchemaThroughResults(input, map); } else if (rowObject instanceof java.util.Collection) { throw new Exception("Can't guess schema from a Collection"); } else { @@ -707,12 +705,12 @@ private boolean guessInputComponentSchemaThroughResult() throws Exception { * @return true if completed; false if one more result row is needed. */ public boolean guessSchemaThroughResult(final Object rowObject) throws Exception { - if (rowObject instanceof java.util.Map) { - return guessSchemaThroughResult((java.util.Map) rowObject); - } else if (rowObject instanceof Schema) { - return fromSchema(Schema.class.cast(rowObject)); - } else if (rowObject instanceof Record) { - return fromSchema(Record.class.cast(rowObject).getSchema()); + if (rowObject instanceof java.util.Map map) { + return guessSchemaThroughResult(map); + } else if (rowObject instanceof Schema schema) { + return fromSchema(schema); + } else if (rowObject instanceof Record record) { + return fromSchema(record.getSchema()); } else if (rowObject instanceof java.util.Collection) { throw new Exception("Can't guess schema from a Collection"); } else { diff --git a/component-studio/component-runtime-di/src/main/java/org/talend/sdk/component/runtime/di/studio/AfterVariableExtracter.java b/component-studio/component-runtime-di/src/main/java/org/talend/sdk/component/runtime/di/studio/AfterVariableExtracter.java index 37f2e428857fb..8062b181e84ee 100644 --- a/component-studio/component-runtime-di/src/main/java/org/talend/sdk/component/runtime/di/studio/AfterVariableExtracter.java +++ b/component-studio/component-runtime-di/src/main/java/org/talend/sdk/component/runtime/di/studio/AfterVariableExtracter.java @@ -40,8 +40,8 @@ public class AfterVariableExtracter { * @return map with after variables. */ public static Map extractAfterVariables(final Lifecycle lifecycle) { - if (lifecycle instanceof Delegated) { - final Object delegate = ((Delegated) lifecycle).getDelegate(); + if (lifecycle instanceof Delegated delegated) { + final Object delegate = delegated.getDelegate(); final ClassLoader classloader = ReflectionUtils.getClassLoader(lifecycle); diff --git a/component-studio/component-runtime-di/src/main/java/org/talend/sdk/component/runtime/di/studio/ParameterSetter.java b/component-studio/component-runtime-di/src/main/java/org/talend/sdk/component/runtime/di/studio/ParameterSetter.java index b0461c4ed8757..adc60ff9c15d2 100644 --- a/component-studio/component-runtime-di/src/main/java/org/talend/sdk/component/runtime/di/studio/ParameterSetter.java +++ b/component-studio/component-runtime-di/src/main/java/org/talend/sdk/component/runtime/di/studio/ParameterSetter.java @@ -92,8 +92,8 @@ public void change(final String path, final Object value) { try { target = field.get(target); if (arrayLocation > -1) { - if (target instanceof List) { - target = List.class.cast(target).get(arrayLocation); + if (target instanceof List list) { + target = list.get(arrayLocation); } else { log.warn("expect a list, but not"); return; diff --git a/component-studio/component-runtime-di/src/main/java/org/talend/sdk/component/runtime/di/studio/RuntimeContextInjector.java b/component-studio/component-runtime-di/src/main/java/org/talend/sdk/component/runtime/di/studio/RuntimeContextInjector.java index 9370724f2b2ac..cace2e87e06b0 100644 --- a/component-studio/component-runtime-di/src/main/java/org/talend/sdk/component/runtime/di/studio/RuntimeContextInjector.java +++ b/component-studio/component-runtime-di/src/main/java/org/talend/sdk/component/runtime/di/studio/RuntimeContextInjector.java @@ -35,8 +35,8 @@ public class RuntimeContextInjector { * @see Lifecycle */ public static void injectLifecycle(final Lifecycle lifecycle, final RuntimeContextHolder runtimeContext) { - if (lifecycle instanceof Delegated) { - final Object delegate = ((Delegated) lifecycle).getDelegate(); + if (lifecycle instanceof Delegated delegated) { + final Object delegate = delegated.getDelegate(); Class currentClass = delegate.getClass(); while (currentClass != null && currentClass != Object.class) { diff --git a/component-tools/src/main/java/org/talend/sdk/component/tools/validator/ActionValidator.java b/component-tools/src/main/java/org/talend/sdk/component/tools/validator/ActionValidator.java index ef20ebc84b7fa..a6abe6bb6f84f 100644 --- a/component-tools/src/main/java/org/talend/sdk/component/tools/validator/ActionValidator.java +++ b/component-tools/src/main/java/org/talend/sdk/component/tools/validator/ActionValidator.java @@ -470,8 +470,8 @@ private boolean hasCorrectReturnType(final Method method) { private boolean hasStringInList(final Method method) { if (List.class.isAssignableFrom(method.getReturnType()) - && method.getGenericReturnType() instanceof ParameterizedType) { - Type[] actualTypeArguments = ((ParameterizedType) method.getGenericReturnType()).getActualTypeArguments(); + && method.getGenericReturnType() instanceof ParameterizedType parameterizedType) { + Type[] actualTypeArguments = parameterizedType.getActualTypeArguments(); if (actualTypeArguments.length > 0) { return "java.lang.String".equals(actualTypeArguments[0].getTypeName()); } From e6240c614ee7dd746fa217526956d5719c096835 Mon Sep 17 00:00:00 2001 From: Emmanuel GALLOIS Date: Thu, 21 May 2026 18:40:56 +0200 Subject: [PATCH 2/2] chore(QTDI-2893): rename pattern match --- .../component/runtime/di/schema/TaCoKitGuessSchema.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/component-studio/component-runtime-di/src/main/java/org/talend/sdk/component/runtime/di/schema/TaCoKitGuessSchema.java b/component-studio/component-runtime-di/src/main/java/org/talend/sdk/component/runtime/di/schema/TaCoKitGuessSchema.java index 6e36e7afea1dd..4783e851def3b 100644 --- a/component-studio/component-runtime-di/src/main/java/org/talend/sdk/component/runtime/di/schema/TaCoKitGuessSchema.java +++ b/component-studio/component-runtime-di/src/main/java/org/talend/sdk/component/runtime/di/schema/TaCoKitGuessSchema.java @@ -673,8 +673,8 @@ private boolean guessInputComponentSchemaThroughResult() throws Exception { if (rowObject == null) { return false; } - if (rowObject instanceof Record record) { - return fromSchema(record.getSchema()); + if (rowObject instanceof Record rcd) { + return fromSchema(rcd.getSchema()); } else if (rowObject instanceof java.util.Map map) { return guessInputSchemaThroughResults(input, map); } else if (rowObject instanceof java.util.Collection) { @@ -709,8 +709,8 @@ public boolean guessSchemaThroughResult(final Object rowObject) throws Exception return guessSchemaThroughResult(map); } else if (rowObject instanceof Schema schema) { return fromSchema(schema); - } else if (rowObject instanceof Record record) { - return fromSchema(record.getSchema()); + } else if (rowObject instanceof Record rcd) { + return fromSchema(rcd.getSchema()); } else if (rowObject instanceof java.util.Collection) { throw new Exception("Can't guess schema from a Collection"); } else {