Skip to content
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 aClass && CharSequence.class.isAssignableFrom(aClass))

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,27 +76,24 @@
} 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 clazz) {

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.
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");
}
final Class<?> rawClazz = (Class) rawType;
if (Collection.class.isAssignableFrom(rawClazz) && pt.getActualTypeArguments().length == 1) {
final Type itemType = pt.getActualTypeArguments()[0];
if (!(itemType instanceof Class)) {
if (!(itemType instanceof Class itemClass)) {

Check warning on line 93 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#L93

Provide the parametrized type for this generic.
throw new IllegalArgumentException(
"Unsupported generic type for item type: " + pt + ", this must be a Class");
}
final Class itemClass = (Class) itemType;
final JsonSchema nested = ofNullable(schemas.get(itemType)).orElseGet(() -> {
final JsonSchema jsonSchema = create(itemClass).build();
schemas.put(itemClass, jsonSchema);
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 processor1) {
processor1
.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 partitionMapper) {
Map<String, String> conf = partitionMapper.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 jsonpJsonObjectCoder && jsonpJsonObjectCoder.isValid();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,10 +131,10 @@
}

private Object createObjectValue(final Map<String, Object> config, final Type paramType, final String prefix) {
if (!(paramType instanceof Class)) {
if (!(paramType instanceof Class aClass)) {

Check warning on line 134 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#L134

Provide the parametrized type for this generic.
throw new IllegalArgumentException("Unsupported type: " + paramType);
}
final Method factory = findFactory((Class) paramType, "create");
final Method factory = findFactory(aClass, "create");
final List<Map.Entry<String, Object>> params = Stream
.of(factory.getParameters())
.map(p -> new AbstractMap.SimpleEntry<>(p.getName(),
Expand Down 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 aClass1 && aClass1.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 aClass && aClass.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 dateTime) {
return dateTime.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 l) {
String logicalType = entry.getLogicalType();
if (logicalType != null) {
if (SchemaProperty.LogicalType.DATE.key().equals(logicalType)) {
return Math.toIntExact(
Instant.ofEpochMilli((Long) value)
Instant.ofEpochMilli(l)
.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(l);
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 @@ -87,11 +87,10 @@ public BeamIOTransformer() {
@Override
public byte[] transform(final ClassLoader loader, final String className, final Class<?> classBeingRedefined,
final ProtectionDomain protectionDomain, final byte[] classfileBuffer) {
if (className == null || !(loader instanceof ConfigurableClassLoader)) {
if (className == null || !(loader instanceof ConfigurableClassLoader classLoader)) {
return classfileBuffer;
}

final ConfigurableClassLoader classLoader = (ConfigurableClassLoader) loader;
final String javaClassName = toClassName(className);
if (!KnownClassesFilter.INSTANCE.accept(javaClassName) && !canBeABeamIO(classLoader, javaClassName)) {
return classfileBuffer;
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 setValidator) {
setValidator
.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 javaTypeClass) {

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 = javaTypeClass;
final Version version = clazz.getAnnotation(Version.class);
if (version != null) {
c.setVersion(version.value());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,16 +42,15 @@
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 cast
&& targetException.getClass().getName().startsWith("java.")) {
final RuntimeException cast = (RuntimeException) targetException;
if (cast.getCause() == null

Check warning on line 53 in component-runtime-impl/src/main/java/org/talend/sdk/component/runtime/base/lang/exception/InvocationExceptionWrapper.java

View check run for this annotation

sonar-rnd / SonarQube Code Analysis

component-runtime-impl/src/main/java/org/talend/sdk/component/runtime/base/lang/exception/InvocationExceptionWrapper.java#L53

Merge this if statement with the enclosing one.
|| (cast.getCause() != null && cast.getCause().getClass().getName().startsWith("java."))) {
return cast;
} // else, let it be wrapped to ensure all the stack is serializable
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public List<Mapper> split(final long desiredSize) {

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

Expand Down
Loading
Loading