You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@nifi.apache.org by "superdachuan (via GitHub)" <gi...@apache.org> on 2026/04/11 11:45:40 UTC

[PR] NIFI-14572 Fix time offset issue in DateTimeAdapter#unmarshal [nifi]

superdachuan opened a new pull request, #11129:
URL: https://github.com/apache/nifi/pull/11129

   <!-- Licensed to the Apache Software Foundation (ASF) under one or more -->
   <!-- contributor license agreements.  See the NOTICE file distributed with -->
   <!-- this work for additional information regarding copyright ownership. -->
   <!-- The ASF licenses this file to You under the Apache License, Version 2.0 -->
   <!-- (the "License"); you may not use this file except in compliance with -->
   <!-- the License.  You may obtain a copy of the License at -->
   <!--     http://www.apache.org/licenses/LICENSE-2.0 -->
   <!-- Unless required by applicable law or agreed to in writing, software -->
   <!-- distributed under the License is distributed on an "AS IS" BASIS, -->
   <!-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -->
   <!-- See the License for the specific language governing permissions and -->
   <!-- limitations under the License. -->
   
   # Summary
   
   [NIFI-14572](https://issues.apache.org/jira/browse/NIFI-14572)
   
   This PR fixes a time offset issue in `DateTimeAdapter#unmarshal`. The current implementation uses `ZonedDateTime`, which can lead to ambiguous parsing of time zone abbreviations such as `CST`, resulting in incorrect offsets. This change aligns the implementation with `TimestampAdapter` by replacing `ZonedDateTime` with `LocalDateTime` and converting it using the system default time zone, avoiding such ambiguity. Although this issue may appear related to NIFI-14581, they are not the same problem and have different root causes: NIFI-14581 is caused by inconsistencies between the time zone ID returned by `TimezoneAdapter` and the server's default locale, whereas this PR addresses ambiguity in parsing time zone abbreviations. Therefore, this change focuses specifically on fixing the time offset issue in `DateTimeAdapter` and does not address NIFI-14581.
   
   # Tracking
   
   Please complete the following tracking steps prior to pull request creation.
   
   ### Issue Tracking
   
   - [Apache NiFi Jira](https://issues.apache.org/jira/browse/NIFI) issue created
   
   ### 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](https://docs.github.com/en/authentication/managing-commit-signature-verification/signing-commits) 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](https://apache.org/licenses/LICENSE-2.0) according to the [License Policy](https://www.apache.org/legal/resolved.html)
   - [ ] New dependencies are documented in applicable `LICENSE` and `NOTICE` files
   
   ### Documentation
   
   - [ ] Documentation formatting appears as expected in rendered files
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@nifi.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] NIFI-14572 Fix time offset issue in DateTimeAdapter#unmarshal [nifi]

Posted by "superdachuan (via GitHub)" <gi...@apache.org>.
superdachuan commented on PR #11129:
URL: https://github.com/apache/nifi/pull/11129#issuecomment-4265010620

   @exceptionfactory Thanks for the review and helpful suggestions. I updated the tests accordingly.
   
   My original intent in combining `marshal` and `unmarshal` was to verify round-trip consistency, since the adapter output includes a time zone and I initially wanted to avoid relying on a single fixed string. I have kept that intent as explicit round-trip tests, and also added more direct assertions for multiple time zones.
   
   I had originally avoided temporarily switching the default time zone because I was concerned about affecting other tests. After reviewing similar patterns in the codebase, I updated this test to verify behavior across multiple time zones directly.
   One detail here is that `DateTimeAdapter` initializes its `DateTimeFormatter` during class loading with `ZoneId.systemDefault()`, so changing the default time zone later does not update the formatter. For that reason, the multi-time-zone assertions reload `DateTimeAdapter` with a dedicated `ClassLoader` instead of reusing the default adapter instance from this test class.
   
   Thanks again.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@nifi.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] NIFI-14572 Fix time offset issue in DateTimeAdapter#unmarshal [nifi]

Posted by "exceptionfactory (via GitHub)" <gi...@apache.org>.
exceptionfactory merged PR #11129:
URL: https://github.com/apache/nifi/pull/11129


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@nifi.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] NIFI-14572 Fix time offset issue in DateTimeAdapter#unmarshal [nifi]

Posted by "superdachuan (via GitHub)" <gi...@apache.org>.
superdachuan commented on PR #11129:
URL: https://github.com/apache/nifi/pull/11129#issuecomment-4312595579

   The current failed jobs do not appear to be failing on the same test, and local testing with JDK 25 passed on my side, so this may be flaky CI rather than a reproducible issue with this change.
   
   I do not have permission to re-run failed jobs on this PR. Could a committer or maintainer please re-run the failed checks?
   
   If the failures persist and indicate an issue in this change, I will investigate and update the PR.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@nifi.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] NIFI-14572 Fix time offset issue in DateTimeAdapter#unmarshal [nifi]

Posted by "exceptionfactory (via GitHub)" <gi...@apache.org>.
exceptionfactory commented on code in PR #11129:
URL: https://github.com/apache/nifi/pull/11129#discussion_r3074535481


##########
nifi-framework-bundle/nifi-framework/nifi-client-dto/src/test/java/org/apache/nifi/web/api/dto/util/TestDateTimeAdapter.java:
##########
@@ -0,0 +1,43 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.nifi.web.api.dto.util;
+
+import org.junit.jupiter.api.Test;
+
+import java.time.Instant;
+import java.util.Date;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+
+public class TestDateTimeAdapter {
+
+    private static final String TEST_DATE_TIME = "2026-01-02T03:04:56Z";
+
+    @Test
+    public void testMarshal() throws Exception {
+        DateTimeAdapter adapter = new DateTimeAdapter();

Review Comment:
   The Adapter instance can be declared once at the class level



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@nifi.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] NIFI-14572 Fix time offset issue in DateTimeAdapter#unmarshal [nifi]

Posted by "exceptionfactory (via GitHub)" <gi...@apache.org>.
exceptionfactory commented on code in PR #11129:
URL: https://github.com/apache/nifi/pull/11129#discussion_r3074543766


##########
nifi-framework-bundle/nifi-framework/nifi-client-dto/src/test/java/org/apache/nifi/web/api/dto/util/TestDateTimeAdapter.java:
##########
@@ -0,0 +1,43 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.nifi.web.api.dto.util;
+
+import org.junit.jupiter.api.Test;
+
+import java.time.Instant;
+import java.util.Date;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+
+public class TestDateTimeAdapter {
+
+    private static final String TEST_DATE_TIME = "2026-01-02T03:04:56Z";
+
+    @Test
+    public void testMarshal() throws Exception {
+        DateTimeAdapter adapter = new DateTimeAdapter();
+        Date date = Date.from(Instant.parse(TEST_DATE_TIME));

Review Comment:
   It would be helpful to avoid the intermediate parsing to an `Instant`. Instead, using the `new Date(long)` constructor should provide a more narrow approach to construct a Date with a given value.



##########
nifi-framework-bundle/nifi-framework/nifi-client-dto/src/test/java/org/apache/nifi/web/api/dto/util/TestDateTimeAdapter.java:
##########
@@ -0,0 +1,43 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.nifi.web.api.dto.util;
+
+import org.junit.jupiter.api.Test;
+
+import java.time.Instant;
+import java.util.Date;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+
+public class TestDateTimeAdapter {
+
+    private static final String TEST_DATE_TIME = "2026-01-02T03:04:56Z";
+
+    @Test
+    public void testMarshal() throws Exception {
+        DateTimeAdapter adapter = new DateTimeAdapter();
+        Date date = Date.from(Instant.parse(TEST_DATE_TIME));
+        assertEquals(date, adapter.unmarshal(adapter.marshal(date)));

Review Comment:
   This is testing both `marshal` and `unmarshal` in one call. Instead, there should be an expected static final string value, matching the `long` timestamp.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@nifi.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] NIFI-14572 Fix time offset issue in DateTimeAdapter#unmarshal [nifi]

Posted by "superdachuan (via GitHub)" <gi...@apache.org>.
superdachuan commented on PR #11129:
URL: https://github.com/apache/nifi/pull/11129#issuecomment-5217426624

   Thanks @exceptionfactory, I appreciate the update and the improvement to the test coverage. I'll take a closer look at the ParameterizedTest changes so I can follow this pattern better in future contributions.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@nifi.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] NIFI-14572 Fix time offset issue in DateTimeAdapter#unmarshal [nifi]

Posted by "superdachuan (via GitHub)" <gi...@apache.org>.
superdachuan commented on PR #11129:
URL: https://github.com/apache/nifi/pull/11129#issuecomment-4286727059

   Thanks for the feedback @exceptionfactory . I reverted the custom ClassLoader-based test change and simplified the approach.
   
   In the updated revision, I removed `withZone(ZoneId.systemDefault())` from the static `DateTimeFormatter` in `DateTimeAdapter`. In this adapter, that formatter-level zone was not necessary for the existing marshal/unmarshal behavior, so removing it does not change the intended time zone handling. It does, however, avoid binding the formatter to the JVM default time zone at class initialization time.
   
   With that change in place, the tests can switch the default time zone directly without relying on class reloading or a custom ClassLoader.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@nifi.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org