Skip to content

NIFI-14226 Corrected ClassCastException being thrown in GenerateRecord when Avro logical types time-micros and/or timestamp-millis are used.#11007

Merged
exceptionfactory merged 1 commit intoapache:mainfrom
dan-s1:NIFI-14226
Mar 13, 2026

Conversation

@dan-s1
Copy link
Contributor

@dan-s1 dan-s1 commented Mar 13, 2026

Summary

NIFI-14226

Tracking

Please complete the following tracking steps prior to pull request creation.

Issue Tracking

Pull Request Tracking

  • Pull Request title starts with Apache NiFi Jira issue number, such as NIFI-00000
  • Pull Request commit message starts with Apache NiFi Jira issue number, as such NIFI-00000
  • Pull request contains commits signed with a registered key indicating Verified status

Pull Request Formatting

  • Pull Request based on current revision of the main branch
  • Pull Request refers to a feature branch with one commit containing changes

Verification

Please indicate the verification steps performed prior to pull request creation.

Build

  • Build completed using ./mvnw clean install -P contrib-check
    • JDK 21
    • JDK 25

Licensing

  • New dependencies are compatible with the Apache License 2.0 according to the License Policy
  • New dependencies are documented in applicable LICENSE and NOTICE files

Documentation

  • Documentation formatting appears as expected in rendered files

…d when Avro logical types time-micros and/or timestamp-millis are used.
@dan-s1
Copy link
Contributor Author

dan-s1 commented Mar 13, 2026

@exceptionfactory For the case of TIME before the change I proposed of returning an instance of LocalTime, I tried the following

Instant fakeInstant = (Instant) FakerUtils.getFakeData(DEFAULT_DATE_PROPERTY_NAME, faker);
                LocalTime fakeLocalTime = fakeInstant.atZone(ZoneId.systemDefault()).toLocalTime();
                yield fakeLocalTime.format(DateTimeFormatter.ISO_LOCAL_TIME);

but it caused exceptions in the JSON and XML tests. Stack traces below:
JSON

org.apache.nifi.serialization.record.field.FieldConversionException: Conversion failed for [12:25:48.032] named [eventTime] to [java.time.LocalTime] [java.lang.NumberFormatException] For input string: "12:25:48.032"
	at org.apache.nifi.serialization.record.field.ObjectLocalTimeFieldConverter.convertField(ObjectLocalTimeFieldConverter.java:92)
	at org.apache.nifi.serialization.record.field.ObjectTimeFieldConverter.convertField(ObjectTimeFieldConverter.java:45)
	at org.apache.nifi.serialization.record.field.ObjectTimeFieldConverter.convertField(ObjectTimeFieldConverter.java:31)
	at org.apache.nifi.serialization.record.util.DataTypeUtils.convertType(DataTypeUtils.java:224)
	at org.apache.nifi.serialization.record.util.DataTypeUtils.convertType(DataTypeUtils.java:174)
	at org.apache.nifi.json.WriteJsonResult.writeValue(WriteJsonResult.java:347)
	at org.apache.nifi.json.WriteJsonResult.writeRecord(WriteJsonResult.java:231)
	at org.apache.nifi.json.WriteJsonResult.writeRecord(WriteJsonResult.java:155)
	at org.apache.nifi.serialization.AbstractRecordSetWriter.write(AbstractRecordSetWriter.java:59)
	at org.apache.nifi.processors.standard.GenerateRecord.lambda$onTrigger$0(GenerateRecord.java:336)

XML

Caused by: org.apache.nifi.serialization.record.field.FieldConversionException: Conversion failed for [10:47:08.59] named [eventTime] to [java.time.LocalTime] [java.lang.NumberFormatException] For input string: "10:47:08.59"
	at org.apache.nifi.serialization.record.field.ObjectLocalTimeFieldConverter.convertField(ObjectLocalTimeFieldConverter.java:92)
	at org.apache.nifi.serialization.record.field.ObjectTimeFieldConverter.convertField(ObjectTimeFieldConverter.java:45)
	at org.apache.nifi.serialization.record.field.ObjectTimeFieldConverter.convertField(ObjectTimeFieldConverter.java:31)
	at org.apache.nifi.serialization.record.util.DataTypeUtils.convertType(DataTypeUtils.java:224)
	at org.apache.nifi.serialization.record.util.DataTypeUtils.convertType(DataTypeUtils.java:174)
	at org.apache.nifi.xml.WriteXMLResult.iterateThroughRecordUsingSchema(WriteXMLResult.java:230)
	at org.apache.nifi.xml.WriteXMLResult.writeRecord(WriteXMLResult.java:208)
	at org.apache.nifi.serialization.AbstractRecordSetWriter.write(AbstractRecordSetWriter.java:59)
	at org.apache.nifi.processors.standard.GenerateRecord.lambda$onTrigger$0(GenerateRecord.java:336)

I am puzzled why that fails since the string is local time.

@exceptionfactory
Copy link
Contributor

@exceptionfactory For the case of TIME before the change I proposed of returning an instance of LocalTime, I tried the following

Instant fakeInstant = (Instant) FakerUtils.getFakeData(DEFAULT_DATE_PROPERTY_NAME, faker);
                LocalTime fakeLocalTime = fakeInstant.atZone(ZoneId.systemDefault()).toLocalTime();
                yield fakeLocalTime.format(DateTimeFormatter.ISO_LOCAL_TIME);

but it caused exceptions in the JSON and XML tests. Stack traces below: JSON

org.apache.nifi.serialization.record.field.FieldConversionException: Conversion failed for [12:25:48.032] named [eventTime] to [java.time.LocalTime] [java.lang.NumberFormatException] For input string: "12:25:48.032"
	at org.apache.nifi.serialization.record.field.ObjectLocalTimeFieldConverter.convertField(ObjectLocalTimeFieldConverter.java:92)
	at org.apache.nifi.serialization.record.field.ObjectTimeFieldConverter.convertField(ObjectTimeFieldConverter.java:45)
	at org.apache.nifi.serialization.record.field.ObjectTimeFieldConverter.convertField(ObjectTimeFieldConverter.java:31)
	at org.apache.nifi.serialization.record.util.DataTypeUtils.convertType(DataTypeUtils.java:224)
	at org.apache.nifi.serialization.record.util.DataTypeUtils.convertType(DataTypeUtils.java:174)
	at org.apache.nifi.json.WriteJsonResult.writeValue(WriteJsonResult.java:347)
	at org.apache.nifi.json.WriteJsonResult.writeRecord(WriteJsonResult.java:231)
	at org.apache.nifi.json.WriteJsonResult.writeRecord(WriteJsonResult.java:155)
	at org.apache.nifi.serialization.AbstractRecordSetWriter.write(AbstractRecordSetWriter.java:59)
	at org.apache.nifi.processors.standard.GenerateRecord.lambda$onTrigger$0(GenerateRecord.java:336)

XML

Caused by: org.apache.nifi.serialization.record.field.FieldConversionException: Conversion failed for [10:47:08.59] named [eventTime] to [java.time.LocalTime] [java.lang.NumberFormatException] For input string: "10:47:08.59"
	at org.apache.nifi.serialization.record.field.ObjectLocalTimeFieldConverter.convertField(ObjectLocalTimeFieldConverter.java:92)
	at org.apache.nifi.serialization.record.field.ObjectTimeFieldConverter.convertField(ObjectTimeFieldConverter.java:45)
	at org.apache.nifi.serialization.record.field.ObjectTimeFieldConverter.convertField(ObjectTimeFieldConverter.java:31)
	at org.apache.nifi.serialization.record.util.DataTypeUtils.convertType(DataTypeUtils.java:224)
	at org.apache.nifi.serialization.record.util.DataTypeUtils.convertType(DataTypeUtils.java:174)
	at org.apache.nifi.xml.WriteXMLResult.iterateThroughRecordUsingSchema(WriteXMLResult.java:230)
	at org.apache.nifi.xml.WriteXMLResult.writeRecord(WriteXMLResult.java:208)
	at org.apache.nifi.serialization.AbstractRecordSetWriter.write(AbstractRecordSetWriter.java:59)
	at org.apache.nifi.processors.standard.GenerateRecord.lambda$onTrigger$0(GenerateRecord.java:336)

I am puzzled why that fails since the string is local time.

According to the stack trace, it is failing because a format pattern is not being provided, so the Converter is trying to parse the string as a number.

@dan-s1
Copy link
Contributor Author

dan-s1 commented Mar 13, 2026

Thanks for clarifying that!

Copy link
Contributor

@exceptionfactory exceptionfactory left a comment

Choose a reason for hiding this comment

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

Thanks @dan-s1, the fix and new unit test for GenerateRecord look good. +1 merging

@exceptionfactory exceptionfactory merged commit 9b92145 into apache:main Mar 13, 2026
7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants