You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tika.apache.org by "THausherr (via GitHub)" <gi...@apache.org> on 2026/04/09 09:56:15 UTC
[PR] [TIKA-4327] set TZ because of metadata-extractor change [tika]
THausherr opened a new pull request, #2753:
URL: https://github.com/apache/tika/pull/2753
Add setup and teardown methods for timezone management in JpegParserTest.
<!--
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.
-->
Thanks for your contribution to [Apache Tika](https://tika.apache.org/)! Your help is appreciated!
Before opening the pull request, please verify that
* there is an open issue on the [Tika issue tracker](https://issues.apache.org/jira/projects/TIKA) which describes the problem or the improvement. We cannot accept pull requests without an issue because the change wouldn't be listed in the release notes.
* the issue ID (`TIKA-XXXX`)
- is referenced in the title of the pull request
- and placed in front of your commit messages surrounded by square brackets (`[TIKA-XXXX] Issue or pull request title`)
* commits are squashed into a single one (or few commits for larger changes)
* Tika is successfully built and unit tests pass by running `./mvnw clean test`
* there should be no conflicts when merging the pull request branch into the *recent* `main` branch. If there are conflicts, please try to rebase the pull request branch on top of a freshly pulled `main` branch
* if you add new module that downstream users will depend upon add it to relevant group in `tika-bom/pom.xml`.
We will be able to faster integrate your pull request if these conditions are met. If you have any questions how to fix your problem or about using Tika in general, please sign up for the [Tika mailing list](http://tika.apache.org/mail-lists.html). Thanks!
--
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: dev-unsubscribe@tika.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [TIKA-4327] set TZ because of metadata-extractor change in update [tika]
Posted by "Copilot (via GitHub)" <gi...@apache.org>.
Copilot commented on code in PR #2753:
URL: https://github.com/apache/tika/pull/2753#discussion_r3057102215
##########
tika-parsers/tika-parsers-standard/tika-parsers-standard-modules/tika-parser-image-module/src/test/java/org/apache/tika/parser/image/JpegParserTest.java:
##########
@@ -38,10 +41,24 @@
import org.apache.tika.parser.ParseContext;
import org.apache.tika.parser.Parser;
+@Isolated
Review Comment:
`TimeZone.setDefault(...)` mutates JVM-global state; `@Isolated` reduces risk when JUnit parallel execution is enabled, but it may not fully protect against concurrent access from other tests running in the same JVM (or background threads spawned by tests). Consider additionally using JUnit’s resource locking (e.g., a `@ResourceLock` on a dedicated “timezone” resource or system properties) to explicitly prevent concurrent execution around this global mutation and document the intent more clearly.
##########
tika-parsers/tika-parsers-standard/tika-parsers-standard-modules/tika-parser-image-module/src/test/java/org/apache/tika/parser/image/JpegParserTest.java:
##########
@@ -25,7 +25,10 @@
import java.util.List;
import java.util.TimeZone;
+import org.junit.jupiter.api.AfterAll;
+import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.parallel.Isolated;
Review Comment:
`TimeZone.setDefault(...)` mutates JVM-global state; `@Isolated` reduces risk when JUnit parallel execution is enabled, but it may not fully protect against concurrent access from other tests running in the same JVM (or background threads spawned by tests). Consider additionally using JUnit’s resource locking (e.g., a `@ResourceLock` on a dedicated “timezone” resource or system properties) to explicitly prevent concurrent execution around this global mutation and document the intent more clearly.
##########
tika-parsers/tika-parsers-standard/tika-parsers-standard-modules/tika-parser-image-module/src/test/java/org/apache/tika/parser/image/JpegParserTest.java:
##########
@@ -38,10 +41,24 @@
import org.apache.tika.parser.ParseContext;
import org.apache.tika.parser.Parser;
+@Isolated
public class JpegParserTest extends TikaTest {
static TimeZone CURR_TIME_ZONE = TimeZone.getDefault();
private final Parser parser = new JpegParser();
+ private static TimeZone originalTimeZone;
+
+ @BeforeAll
+ static void init() {
+ // metadata-extractor 2.20.0 started making these parsed dates depend on the JVM default time zone;
+ // force GMT so the assertions remain deterministic across environments
+ originalTimeZone = TimeZone.getDefault();
+ TimeZone.setDefault(TimeZone.getTimeZone("GMT"));
+ }
+ @AfterAll
+ static void tearDown() {
+ TimeZone.setDefault(originalTimeZone);
+ }
Review Comment:
`CURR_TIME_ZONE` and `originalTimeZone` both capture the pre-test default timezone but via different mechanisms (class initialization vs. `@BeforeAll`). This duplication increases the chance of confusion and makes future edits error-prone. Prefer keeping a single “original timezone” field (ideally `private static final` if feasible, or `private static` set once) and using it consistently for restore logic (and any assertions that use the original value).
--
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: dev-unsubscribe@tika.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [TIKA-4327] set TZ because of metadata-extractor change in update [tika]
Posted by "Copilot (via GitHub)" <gi...@apache.org>.
Copilot commented on code in PR #2753:
URL: https://github.com/apache/tika/pull/2753#discussion_r3057060620
##########
tika-parsers/tika-parsers-standard/tika-parsers-standard-modules/tika-parser-image-module/src/test/java/org/apache/tika/parser/image/JpegParserTest.java:
##########
@@ -38,10 +41,24 @@
import org.apache.tika.parser.ParseContext;
import org.apache.tika.parser.Parser;
+@Isolated
public class JpegParserTest extends TikaTest {
static TimeZone CURR_TIME_ZONE = TimeZone.getDefault();
private final Parser parser = new JpegParser();
+ static private TimeZone timezone;
+
+ @BeforeAll
+ static void init() {
+ // metadata-extractor 2.20.0 started making these parsed dates depend on the JVM default time zone;
+ // force GMT so the assertions remain deterministic across environments
+ timezone = TimeZone.getDefault();
+ TimeZone.setDefault(TimeZone.getTimeZone("GMT"));
+ }
+ @AfterAll
+ static void tearDown() {
+ TimeZone.setDefault(timezone);
Review Comment:
The field name `timezone` is ambiguous (it’s specifically the original/default timezone being saved for restoration). Renaming it to something like `originalTimeZone` (and using standard modifier order `private static`) would make the intent clearer and reduce the chance of incorrect future use.
```suggestion
private static TimeZone originalTimeZone;
@BeforeAll
static void init() {
// metadata-extractor 2.20.0 started making these parsed dates depend on the JVM default time zone;
// force GMT so the assertions remain deterministic across environments
originalTimeZone = TimeZone.getDefault();
TimeZone.setDefault(TimeZone.getTimeZone("GMT"));
}
@AfterAll
static void tearDown() {
TimeZone.setDefault(originalTimeZone);
```
##########
tika-parsers/tika-parsers-standard/tika-parsers-standard-modules/tika-parser-image-module/src/test/java/org/apache/tika/parser/image/JpegParserTest.java:
##########
@@ -38,10 +41,24 @@
import org.apache.tika.parser.ParseContext;
import org.apache.tika.parser.Parser;
+@Isolated
public class JpegParserTest extends TikaTest {
static TimeZone CURR_TIME_ZONE = TimeZone.getDefault();
private final Parser parser = new JpegParser();
+ static private TimeZone timezone;
+
+ @BeforeAll
+ static void init() {
+ // metadata-extractor 2.20.0 started making these parsed dates depend on the JVM default time zone;
+ // force GMT so the assertions remain deterministic across environments
+ timezone = TimeZone.getDefault();
+ TimeZone.setDefault(TimeZone.getTimeZone("GMT"));
+ }
+ @AfterAll
+ static void tearDown() {
+ TimeZone.setDefault(timezone);
Review Comment:
This test now has two separate static fields holding the default timezone (`CURR_TIME_ZONE` and `timezone`). That duplication makes it easy for the restore logic to diverge over time. Consider consolidating to a single field (e.g., keep one 'original default TZ' variable) and, if it never changes after capture, declare it `private static final` where possible.
```suggestion
private static final TimeZone ORIGINAL_DEFAULT_TIME_ZONE = TimeZone.getDefault();
private final Parser parser = new JpegParser();
@BeforeAll
static void init() {
// metadata-extractor 2.20.0 started making these parsed dates depend on the JVM default time zone;
// force GMT so the assertions remain deterministic across environments
TimeZone.setDefault(TimeZone.getTimeZone("GMT"));
}
@AfterAll
static void tearDown() {
TimeZone.setDefault(ORIGINAL_DEFAULT_TIME_ZONE);
```
##########
tika-parsers/tika-parsers-standard/tika-parsers-standard-modules/tika-parser-image-module/src/test/java/org/apache/tika/parser/image/JpegParserTest.java:
##########
@@ -38,10 +41,24 @@
import org.apache.tika.parser.ParseContext;
import org.apache.tika.parser.Parser;
+@Isolated
public class JpegParserTest extends TikaTest {
static TimeZone CURR_TIME_ZONE = TimeZone.getDefault();
private final Parser parser = new JpegParser();
+ static private TimeZone timezone;
+
+ @BeforeAll
+ static void init() {
+ // metadata-extractor 2.20.0 started making these parsed dates depend on the JVM default time zone;
+ // force GMT so the assertions remain deterministic across environments
+ timezone = TimeZone.getDefault();
+ TimeZone.setDefault(TimeZone.getTimeZone("GMT"));
+ }
+ @AfterAll
+ static void tearDown() {
+ TimeZone.setDefault(timezone);
Review Comment:
The field name `timezone` is ambiguous (it’s specifically the original/default timezone being saved for restoration). Renaming it to something like `originalTimeZone` (and using standard modifier order `private static`) would make the intent clearer and reduce the chance of incorrect future use.
```suggestion
private static TimeZone originalTimeZone;
@BeforeAll
static void init() {
// metadata-extractor 2.20.0 started making these parsed dates depend on the JVM default time zone;
// force GMT so the assertions remain deterministic across environments
originalTimeZone = TimeZone.getDefault();
TimeZone.setDefault(TimeZone.getTimeZone("GMT"));
}
@AfterAll
static void tearDown() {
TimeZone.setDefault(originalTimeZone);
```
##########
tika-parsers/tika-parsers-standard/tika-parsers-standard-modules/tika-parser-image-module/src/test/java/org/apache/tika/parser/image/JpegParserTest.java:
##########
@@ -38,10 +41,24 @@
import org.apache.tika.parser.ParseContext;
import org.apache.tika.parser.Parser;
+@Isolated
public class JpegParserTest extends TikaTest {
static TimeZone CURR_TIME_ZONE = TimeZone.getDefault();
private final Parser parser = new JpegParser();
+ static private TimeZone timezone;
+
+ @BeforeAll
+ static void init() {
+ // metadata-extractor 2.20.0 started making these parsed dates depend on the JVM default time zone;
+ // force GMT so the assertions remain deterministic across environments
+ timezone = TimeZone.getDefault();
+ TimeZone.setDefault(TimeZone.getTimeZone("GMT"));
+ }
+ @AfterAll
+ static void tearDown() {
+ TimeZone.setDefault(timezone);
Review Comment:
The field name `timezone` is ambiguous (it’s specifically the original/default timezone being saved for restoration). Renaming it to something like `originalTimeZone` (and using standard modifier order `private static`) would make the intent clearer and reduce the chance of incorrect future use.
```suggestion
private static TimeZone originalTimeZone;
@BeforeAll
static void init() {
// metadata-extractor 2.20.0 started making these parsed dates depend on the JVM default time zone;
// force GMT so the assertions remain deterministic across environments
originalTimeZone = TimeZone.getDefault();
TimeZone.setDefault(TimeZone.getTimeZone("GMT"));
}
@AfterAll
static void tearDown() {
TimeZone.setDefault(originalTimeZone);
```
--
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: dev-unsubscribe@tika.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [TIKA-4327] set TZ because of metadata-extractor change in update [tika]
Posted by "THausherr (via GitHub)" <gi...@apache.org>.
THausherr merged PR #2753:
URL: https://github.com/apache/tika/pull/2753
--
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: dev-unsubscribe@tika.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [TIKA-4327] set TZ because of metadata-extractor change in update [tika]
Posted by "Copilot (via GitHub)" <gi...@apache.org>.
Copilot commented on code in PR #2753:
URL: https://github.com/apache/tika/pull/2753#discussion_r3056987349
##########
tika-parsers/tika-parsers-standard/tika-parsers-standard-modules/tika-parser-image-module/src/test/java/org/apache/tika/parser/image/JpegParserTest.java:
##########
@@ -42,6 +44,17 @@ public class JpegParserTest extends TikaTest {
static TimeZone CURR_TIME_ZONE = TimeZone.getDefault();
private final Parser parser = new JpegParser();
+ static private TimeZone timezone;
+
+ @BeforeAll
+ static void init() {
+ timezone = TimeZone.getDefault();
+ TimeZone.setDefault(TimeZone.getTimeZone("GMT")); // need to set TZ since extractor 2.20.0, PR# 651
+ }
+ @AfterAll
+ static void tearDown() {
+ TimeZone.setDefault(timezone);
+ }
Review Comment:
Changing the JVM default timezone is a global mutation and can make the build flaky if tests are executed in parallel across classes/modules (other tests may observe GMT mid-run). If the project runs JUnit 5 tests in parallel, consider isolating this test class (e.g., JUnit Jupiter `@Isolated` or a `@ResourceLock` guarding timezone/global state) or otherwise ensuring this module/class is excluded from parallel execution.
##########
tika-parsers/tika-parsers-standard/tika-parsers-standard-modules/tika-parser-image-module/src/test/java/org/apache/tika/parser/image/JpegParserTest.java:
##########
@@ -42,6 +44,17 @@ public class JpegParserTest extends TikaTest {
static TimeZone CURR_TIME_ZONE = TimeZone.getDefault();
private final Parser parser = new JpegParser();
+ static private TimeZone timezone;
+
+ @BeforeAll
+ static void init() {
+ timezone = TimeZone.getDefault();
+ TimeZone.setDefault(TimeZone.getTimeZone("GMT")); // need to set TZ since extractor 2.20.0, PR# 651
Review Comment:
The inline comment isn’t very actionable (\"PR# 651\" is ambiguous without a link/repo context). Consider referencing the concrete upstream change (link to the metadata-extractor PR/release note) and/or the local tracking issue (e.g., TIKA-4327) so future maintainers can understand why GMT is required here.
```suggestion
TimeZone.setDefault(TimeZone.getTimeZone("GMT")); // metadata-extractor 2.20.0 started making these parsed dates depend on the JVM default time zone; force GMT so the assertions remain deterministic across environments
```
##########
tika-parsers/tika-parsers-standard/tika-parsers-standard-modules/tika-parser-image-module/src/test/java/org/apache/tika/parser/image/JpegParserTest.java:
##########
@@ -42,6 +44,17 @@ public class JpegParserTest extends TikaTest {
static TimeZone CURR_TIME_ZONE = TimeZone.getDefault();
private final Parser parser = new JpegParser();
+ static private TimeZone timezone;
+
+ @BeforeAll
+ static void init() {
+ timezone = TimeZone.getDefault();
+ TimeZone.setDefault(TimeZone.getTimeZone("GMT")); // need to set TZ since extractor 2.20.0, PR# 651
+ }
+ @AfterAll
+ static void tearDown() {
+ TimeZone.setDefault(timezone);
+ }
Review Comment:
Timezone is captured twice (`CURR_TIME_ZONE` at class initialization and `timezone` in `@BeforeAll`), which is redundant and can be confusing about which value is authoritative. Consider consolidating to a single field captured in `@BeforeAll` (or reuse `CURR_TIME_ZONE` and remove `timezone`) and keep the modifier order conventional (e.g., `private static TimeZone timezone;`) to align with typical Java style.
--
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: dev-unsubscribe@tika.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org