Skip to content

Conversation

drow724
Copy link
Contributor

@drow724 drow724 commented Jan 17, 2023

public class AvroItemReaderBuilder<T> {

	private String name = AvroItemReader.class.getSimpleName();

AvroItemReaderBuilder's name field has defalut value (AvroItemReader.class.getSimpleName)

if (this.saveState) {
	Assert.state(StringUtils.hasText(this.name), "A name is required when saveState is set to true.");
}

so that assert code is never throw error because name field has default value

and i'm adding code that initializing name field to AvroItemReader.class.getSimpleName

@drow724 drow724 changed the title Avro item reader constructor initialize remove useless assert state Jan 17, 2023
Comment on lines -173 to -176
if (this.saveState) {
Assert.state(StringUtils.hasText(this.name), "A name is required when saveState is set to true.");
}

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove useless assert state

This assertion is not useless. Here is a case where the name could end up being null or empty even with a default name in the constructor:

AvroItemReader avroItemReader = new AvroItemReaderBuilder()
		.name(getNameFromPropertiesFile())
		// set other properties
		.build();

In this example, if getNameFromPropertiesFile() returns null or an empty string, the reader will be created in an inconsistent state. That's why it is better to fail fast at the builder level.

@fmbenhassine fmbenhassine changed the title remove useless assert state Add default component name in constructor of AvroItemReader Feb 21, 2023
@fmbenhassine
Copy link
Contributor

Rebased, squashed and merged as 89e7616. I just reverted the assertion removal as I believe it is needed as explained in the comment above. Thank you for your contribution!

@fmbenhassine fmbenhassine added pr-for: enhancement in: infrastructure for: backport-to-4.3.x Issues that will be back-ported to the 4.3.x line labels Feb 21, 2023
@fmbenhassine fmbenhassine added this to the 5.0.1 milestone Feb 21, 2023
@drow724 drow724 deleted the AvroItemReader_Constructor_initialize branch February 27, 2023 09:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

for: backport-to-4.3.x Issues that will be back-ported to the 4.3.x line in: infrastructure pr-for: enhancement

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants