Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,10 @@ public class TypeValidation implements ValidationExtension {
@Override
public Optional<Function<JsonValue, Stream<ValidationError>>> create(final ValidationContext model) {
final JsonValue value = model.getSchema().get("type");
if (value instanceof JsonString) {
if (value instanceof JsonString jsonString) {
return Optional
.of(new Impl(model.toPointer(), model.getValueProvider(),
mapType((JsonString) value).toArray(JsonValue.ValueType[]::new)));
mapType(jsonString).toArray(JsonValue.ValueType[]::new)));
}
if (value instanceof JsonArray) {
return Optional
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,10 @@
return builder;
}

private JsonSchema buildSchema(final Field field) {

Check failure on line 64 in component-form/component-form-model/src/main/java/org/talend/sdk/component/form/model/jsonschema/PojoJsonSchemaBuilder.java

View check run for this annotation

sonar-rnd / SonarQube Code Analysis

component-form/component-form-model/src/main/java/org/talend/sdk/component/form/model/jsonschema/PojoJsonSchemaBuilder.java#L64

Refactor this method to reduce its Cognitive Complexity from 24 to the 15 allowed.
final Type genericType = field.getGenericType();

if ((genericType instanceof Class && CharSequence.class.isAssignableFrom((Class) genericType))
if ((genericType instanceof Class clazz && CharSequence.class.isAssignableFrom(clazz))

Check warning on line 67 in component-form/component-form-model/src/main/java/org/talend/sdk/component/form/model/jsonschema/PojoJsonSchemaBuilder.java

View check run for this annotation

sonar-rnd / SonarQube Code Analysis

component-form/component-form-model/src/main/java/org/talend/sdk/component/form/model/jsonschema/PojoJsonSchemaBuilder.java#L67

Provide the parametrized type for this generic.
|| genericType == char.class || genericType == Character.class) {
return schemas.computeIfAbsent((Class) genericType, k -> jsonSchema().withType("string").build());
} else if (genericType == long.class || genericType == Long.class || genericType == int.class
Expand All @@ -76,15 +76,14 @@
} else if (genericType == boolean.class || genericType == Boolean.class) {
return schemas
.computeIfAbsent((Class) genericType, k -> jsonSchema().withType("boolean").build());
} else if (genericType instanceof Class) {
final Class<?> clazz = (Class) genericType;
} else if (genericType instanceof Class classVal) {

Check warning on line 79 in component-form/component-form-model/src/main/java/org/talend/sdk/component/form/model/jsonschema/PojoJsonSchemaBuilder.java

View check run for this annotation

sonar-rnd / SonarQube Code Analysis

component-form/component-form-model/src/main/java/org/talend/sdk/component/form/model/jsonschema/PojoJsonSchemaBuilder.java#L79

Provide the parametrized type for this generic.
final Class<?> clazz = classVal;
return ofNullable(schemas.get(clazz)).orElseGet(() -> {
final JsonSchema jsonSchema = create(clazz).build();
schemas.put(clazz, jsonSchema);
return jsonSchema;
});
} else if (genericType instanceof ParameterizedType) {
final ParameterizedType pt = (ParameterizedType) genericType;
} else if (genericType instanceof ParameterizedType pt) {
final Type rawType = pt.getRawType();
if (!(rawType instanceof Class)) {
throw new IllegalArgumentException("Unsupported raw type: " + pt + ", this must be a Class");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,8 @@ abstract class BaseProcessorFn<O> extends DoFn<Record, O> {

BaseProcessorFn(final Processor processor) {
this.processor = processor;
if (processor instanceof ProcessorImpl) {
((ProcessorImpl) processor)
if (processor instanceof ProcessorImpl processorImpl) {
processorImpl
.getInternalConfiguration()
.entrySet()
.stream()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,8 @@ public static Base<PBegin, PCollection<Record>, Mapper> read(final Mapper mapper
String maxRecords = null;
String maxDurationMs = null;
boolean hasInternalConfParams = false;
if (mapper instanceof PartitionMapperImpl) {
Map<String, String> conf = ((PartitionMapperImpl) mapper).getInternalConfiguration();
if (mapper instanceof PartitionMapperImpl partitionMapperImpl) {
Map<String, String> conf = partitionMapperImpl.getInternalConfiguration();
hasInternalConfParams = conf.keySet()
.stream()
.filter(k -> k.equals("$maxRecords") || k.equals("$maxDurationMs"))
Expand Down Expand Up @@ -164,8 +164,8 @@ private static class InfiniteRead extends Base<PBegin, PCollection<Record>, Mapp
private InfiniteRead(final Mapper delegate, final long maxRecordCount, final long maxDuration) {
super(delegate);
// ensure we consider localConfiguration
final Map<String, String> internalConf = delegate instanceof PartitionMapperImpl
? ((PartitionMapperImpl) delegate).getInternalConfiguration()
final Map<String, String> internalConf = delegate instanceof PartitionMapperImpl partitionMapper
? partitionMapper.getInternalConfiguration()
: emptyMap();
StopConfiguration fromLocalConf =
(StopConfiguration) Streaming.loadStopStrategy(delegate.plugin(), internalConf);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ public JsonObject decode(final InputStream inputStream) throws IOException {

@Override
public boolean equals(final Object obj) {
return obj instanceof JsonpJsonObjectCoder && ((JsonpJsonObjectCoder) obj).isValid();
return obj instanceof JsonpJsonObjectCoder coder && coder.isValid();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -164,14 +164,13 @@
if (String.class == type) { // fast path
return v;
}
if (type instanceof Class && ((Class) type).isInstance(v)) {
if (type instanceof Class clazz && (clazz.isInstance(v))) {

Check warning on line 167 in component-runtime-beam/src/main/java/org/talend/sdk/component/runtime/beam/factory/service/AutoValueFluentApiFactory.java

View check run for this annotation

sonar-rnd / SonarQube Code Analysis

component-runtime-beam/src/main/java/org/talend/sdk/component/runtime/beam/factory/service/AutoValueFluentApiFactory.java#L167

Provide the parametrized type for this generic.
return v;
}
if (type instanceof ParameterizedType) {
final ParameterizedType pt = (ParameterizedType) type;
if (type instanceof ParameterizedType pt) {
final Type raw = pt.getRawType();
// we know what we do if we use that
if (raw instanceof Class && ((Class) raw).isInstance(v)) {
if (raw instanceof Class clazz && clazz.isInstance(v)) {

Check warning on line 173 in component-runtime-beam/src/main/java/org/talend/sdk/component/runtime/beam/factory/service/AutoValueFluentApiFactory.java

View check run for this annotation

sonar-rnd / SonarQube Code Analysis

component-runtime-beam/src/main/java/org/talend/sdk/component/runtime/beam/factory/service/AutoValueFluentApiFactory.java#L173

Provide the parametrized type for this generic.
return v;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,10 +66,10 @@
@Override
public <T> T unwrap(final Class<T> type, final Object... args) {
if ("org.talend.sdk.component.design.extension.flows.FlowsFactory".equals(type.getName()) && args != null
&& args.length == 1 && args[0] instanceof ComponentFamilyMeta.BaseMeta) {
&& args.length == 1 && args[0] instanceof ComponentFamilyMeta.BaseMeta baseMeta) {

Check warning on line 69 in component-runtime-beam/src/main/java/org/talend/sdk/component/runtime/beam/spi/BeamComponentExtension.java

View check run for this annotation

sonar-rnd / SonarQube Code Analysis

component-runtime-beam/src/main/java/org/talend/sdk/component/runtime/beam/spi/BeamComponentExtension.java#L69

Provide the parametrized type for this generic.
if (args[0] instanceof ComponentFamilyMeta.ProcessorMeta) {
try {
final FlowsFactory factory = FlowsFactory.get((ComponentFamilyMeta.BaseMeta) args[0]);
final FlowsFactory factory = FlowsFactory.get(baseMeta);
factory.getOutputFlows();
return type.cast(factory);
} catch (final Exception e) { // no @ElementListener, let's default for native transforms
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,10 +65,10 @@
} catch (Exception e) {
log.warn("Component Kit Mapper instantiation failed, trying to wrap native beam mapper...");
final Object delegate = ((Delegated) mapper).getDelegate();
if (delegate instanceof PTransform) {
if (delegate instanceof PTransform pTransform) {

Check warning on line 68 in component-runtime-beam/src/main/java/org/talend/sdk/component/runtime/beam/spi/BeamProducerFinder.java

View check run for this annotation

sonar-rnd / SonarQube Code Analysis

component-runtime-beam/src/main/java/org/talend/sdk/component/runtime/beam/spi/BeamProducerFinder.java#L68

Provide the parametrized type for this generic.
final UUID uuid = UUID.randomUUID();
QUEUE.put(uuid, new ArrayBlockingQueue<>(QUEUE_SIZE, true));
return new QueueInput(delegate, familyName, inputName, familyName, (PTransform) delegate,
return new QueueInput(delegate, familyName, inputName, familyName, pTransform,
uuid);
}
throw new IllegalStateException(e);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,7 @@
}

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;
Expand Down Expand Up @@ -105,41 +104,41 @@
// 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<BigDecimal> as Array type
if (value instanceof BigDecimal) {
return ((BigDecimal) value).toString();
if (value instanceof BigDecimal bigDecimal) {
return bigDecimal.toString();
}

if (value instanceof Collection) {
return ((Collection) value).stream().map(v -> this.directMapping(v, entry)).collect(toList());
if (value instanceof Collection collection) {

Check warning on line 111 in component-runtime-beam/src/main/java/org/talend/sdk/component/runtime/beam/spi/record/AvroRecord.java

View check run for this annotation

sonar-rnd / SonarQube Code Analysis

component-runtime-beam/src/main/java/org/talend/sdk/component/runtime/beam/spi/record/AvroRecord.java#L111

Provide the parametrized type for this generic.
return collection.stream().map(v -> this.directMapping(v, entry)).collect(toList());

Check warning on line 112 in component-runtime-beam/src/main/java/org/talend/sdk/component/runtime/beam/spi/record/AvroRecord.java

View check run for this annotation

sonar-rnd / SonarQube Code Analysis

component-runtime-beam/src/main/java/org/talend/sdk/component/runtime/beam/spi/record/AvroRecord.java#L112

Replace this usage of 'Stream.collect(Collectors.toList())' with 'Stream.toList()' and ensure that the list is unmodified.
}
if (value instanceof RecordImpl) {
return new AvroRecord((Record) value).delegate;
}
if (value instanceof Record) {
return ((Unwrappable) value).unwrap(IndexedRecord.class);
}
if (value instanceof ZonedDateTime) {
return ((ZonedDateTime) value).toInstant().toEpochMilli();
if (value instanceof ZonedDateTime zonedDateTime) {
return zonedDateTime.toInstant().toEpochMilli();
}
if (value instanceof Date) {
return ((Date) value).getTime();
if (value instanceof Date date) {
return date.getTime();
}
if (value instanceof byte[]) {
return ByteBuffer.wrap((byte[]) 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);
}
Expand Down Expand Up @@ -239,18 +238,19 @@
return doMap(expectedType, unwrapUnion(fieldSchema), value);
}

private <T> T doMap(final Class<T> expectedType, final org.apache.avro.Schema fieldSchemaRaw, final Object value) {

Check failure on line 241 in component-runtime-beam/src/main/java/org/talend/sdk/component/runtime/beam/spi/record/AvroRecord.java

View check run for this annotation

sonar-rnd / SonarQube Code Analysis

component-runtime-beam/src/main/java/org/talend/sdk/component/runtime/beam/spi/record/AvroRecord.java#L241

Refactor this method to reduce its Cognitive Complexity from 59 to the 15 allowed.

if (value != null && expectedType == value.getClass() && !(value instanceof Collection)) {
return expectedType.cast(value);
}

if (value instanceof IndexedRecord && (Record.class == expectedType || Object.class == expectedType)) {
return expectedType.cast(new AvroRecord((IndexedRecord) 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) value).array());
if (value instanceof ByteBuffer byteBuffer && byte[].class == expectedType) {
return expectedType.cast(byteBuffer.array());
}

final org.apache.avro.Schema fieldSchema = unwrapUnion(fieldSchemaRaw);
Expand Down Expand Up @@ -311,8 +311,8 @@
.cast(doMapCollection(itemType, (Collection) value, fieldSchema.getElementType()));
}

if (value instanceof org.joda.time.DateTime && ZonedDateTime.class == expectedType) {
final long epochMilli = ((org.joda.time.DateTime) 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));
}

Expand All @@ -338,7 +338,7 @@
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) {

Check warning on line 341 in component-runtime-beam/src/main/java/org/talend/sdk/component/runtime/beam/spi/record/AvroRecord.java

View check run for this annotation

sonar-rnd / SonarQube Code Analysis

component-runtime-beam/src/main/java/org/talend/sdk/component/runtime/beam/spi/record/AvroRecord.java#L341

Provide the parametrized type for this generic.
final org.apache.avro.Schema elementType = fieldSchema.getElementType();
final org.apache.avro.Schema elementSchema = unwrapUnion(elementType);
Class<?> toType = Object.class;
Expand All @@ -347,7 +347,7 @@
} else if (elementSchema.getType() == org.apache.avro.Schema.Type.ARRAY) {
toType = Collection.class;
}
final Collection<?> objects = this.doMapCollection(toType, (Collection) value, elementSchema);
final Collection<?> objects = this.doMapCollection(toType, collection, elementSchema);
return expectedType.cast(objects);
}
return expectedType.cast(value);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,7 @@ public boolean equals(final Object o) {
if (o == this) {
return true;
}
if (o instanceof CustomJdbcIO.DataSourceConfiguration) {
CustomJdbcIO.DataSourceConfiguration that = (CustomJdbcIO.DataSourceConfiguration) o;
if (o instanceof CustomJdbcIO.DataSourceConfiguration that) {
return ((this.driverClassName == null) ? (that.getDriverClassName() == null)
: this.driverClassName.equals(that.getDriverClassName()))
&& ((this.url == null) ? (that.getUrl() == null) : this.url.equals(that.getUrl()))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -148,8 +148,8 @@ void coderSerialization() {
private Object newInstance(final Class<?> aClass, final ClassLoader validationLoader) {
try {
final Object instance = aClass.getConstructor().newInstance();
if (instance instanceof SetValidator) {
((SetValidator) instance)
if (instance instanceof SetValidator setValidatorVal) {
setValidatorVal
.setValidator(
() -> assertEquals(Thread.currentThread().getContextClassLoader(), validationLoader));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,8 +130,8 @@
.setId(IdGenerator
.get(plugin, c.getKey().getFamily(), c.getKey().getConfigType(), c.getKey().getConfigName()));

if (config.getJavaType() instanceof Class) {
final Class<?> clazz = (Class) config.getJavaType();
if (config.getJavaType() instanceof Class classVal) {

Check warning on line 133 in component-runtime-design-extension/src/main/java/org/talend/sdk/component/design/extension/repository/RepositoryModelBuilder.java

View check run for this annotation

sonar-rnd / SonarQube Code Analysis

component-runtime-design-extension/src/main/java/org/talend/sdk/component/design/extension/repository/RepositoryModelBuilder.java#L133

Provide the parametrized type for this generic.
final Class<?> clazz = classVal;
final Version version = clazz.getAnnotation(Version.class);
if (version != null) {
c.setVersion(version.value());
Expand Down
2 changes: 1 addition & 1 deletion component-runtime-impl/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@
<dependency>
<groupId>nl.jqno.equalsverifier</groupId>
<artifactId>equalsverifier</artifactId>
<version>3.7.2</version>
<version>4.4.2</version>
<scope>test</scope>
</dependency>
</dependencies>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,15 +42,15 @@ private static RuntimeException mapException(final Throwable targetException, fi
if (targetException == null) {
return null;
}
if (targetException instanceof ComponentException) {
return (ComponentException) targetException;
if (targetException instanceof ComponentException componentException) {
return componentException;
}
if (targetException instanceof DiscoverSchemaException) {
return (DiscoverSchemaException) targetException;
if (targetException instanceof DiscoverSchemaException discoverSchemaException) {
return discoverSchemaException;
}
if (targetException instanceof RuntimeException
if (targetException instanceof RuntimeException rte
&& targetException.getClass().getName().startsWith("java.")) {
final RuntimeException cast = (RuntimeException) targetException;
final RuntimeException cast = rte;
if (cast.getCause() == null
|| (cast.getCause() != null && cast.getCause().getClass().getName().startsWith("java."))) {
return cast;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,7 @@ public List<Mapper> split(final long desiredSize) {

@Override
public Input create() {
return input instanceof Input ? (Input) input
: new InputImpl(rootName(), name(), plugin(), input);
return input instanceof Input in ? in : new InputImpl(rootName(), name(), plugin(), input);
}

@Override
Expand Down
Loading
Loading