Skip to content

DateUtils.getFormatter() uses the JVM default locale for a cached storage formatter, and FileUtils.copyFile ignores transferTo so a >2GB file is silently truncated #7112

Closed

Description

@ruispereira

Two defects in shared utility code, one of which has a test that would catch it if the call were not commented out.

1. DateUtils.getFormatter() builds its statically cached formatter with the JVM default locale

engine/src/main/java/com/arcadedb/utility/DateUtils.java:558-560:

final DateTimeFormatter formatter = new DateTimeFormatterBuilder().appendPattern(format)
    .parseDefaulting(ChronoField.HOUR_OF_DAY, 0).parseDefaulting(ChronoField.MINUTE_OF_HOUR, 0)
    .parseDefaulting(ChronoField.SECOND_OF_MINUTE, 0).toFormatter();

The no-arg toFormatter() is specified to use Locale.getDefault(Locale.Category.FORMAT). So a schema date/time pattern containing a textual field renders and parses differently depending on the server's locale.

Impact: with -Duser.language=it -Duser.country=IT, a pattern with MMM or EEE produces Italian month and day names. Two nodes of the same cluster with different locales then write and read different textual forms for the same schema pattern, and a value written by one fails to parse on the other. The formatter is also cached statically, so the first caller's locale fixes it for the process.

Fix: end the chain with .toFormatter(Locale.ENGLISH), matching the fixed locale a storage format needs. A numeric-only pattern is unaffected either way, so this cannot regress the common case.

2. FileUtils.copyFile ignores transferTo's return value, so a file over ~2GB is silently truncated

engine/src/main/java/com/arcadedb/utility/FileUtils.java:237-243:

try (final FileInputStream fis = new FileInputStream(source); final FileOutputStream fos = new FileOutputStream(destination)) {
  final FileChannel sourceChannel = fis.getChannel();
  final FileChannel targetChannel = fos.getChannel();
  sourceChannel.transferTo(0, sourceChannel.size(), targetChannel);
}

FileChannel.transferTo is documented to transfer at most the requested count, and on most platforms caps a single call at ~2GB. The return value says how much moved; here it is discarded, so a larger file yields a short destination with no exception.

Reached from copyDirectory (:252), so a directory copy containing one large file silently loses its tail.

The test that would catch this exists but is disabled - engine/src/test/java/com/arcadedb/utility/FileUtilsTest.java:259:

//    FileUtils.copyFile(source.toFile(), dest.toFile());

in a method named copyFile(). Worth uncommenting as part of the fix, since a passing test named for the method is exactly what makes a defect like this invisible.

Fix: Files.copy(source.toPath(), destination.toPath(), REPLACE_EXISTING), or loop on transferTo until size() bytes have moved and fail if progress stalls.

Scope / confidence

High on both mechanisms, quoted above. Severity is bounded: part 1 needs a textual date pattern in the schema and a non-English server locale; part 2 needs a file over ~2GB through this specific helper. Neither is exotic in a database, but neither is the default path either.

Activity

  1. added
    engine
    on Sep 3, 2026
  2. added this to the 26.9.1 milestone on Sep 3, 2026
  3. added
    in progress
    on Sep 3, 2026
  4. self-assigned this
    on Sep 3, 2026
  5. added a commit that references this issue on Sep 3, 2026
  6. removed
    in progress
    on Sep 3, 2026
  7. lvca commented on Sep 3, 2026

    @lvca
    Member

    Fixed in #7117 (milestone 26.9.1).

    Schema date and datetime patterns now render and parse with a fixed English locale, so a pattern with month or day names (MMM, EEE) produces the same value on every server regardless of the JVM locale. A copy through FileUtils.copyFile is complete for any file size. The remaining places that build a formatter from a schema pattern with the JVM locale are tracked in #7144.


    ❤️ Thanks for helping make ArcadeDB better! ArcadeDB is free and open source, sustained by its community. If it's useful to you or your company, please consider becoming a sponsor to keep development going.

  8. added a commit that references this issue on Sep 6, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

bugengine

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions