Skip to content

Conversation

slachiewicz
Copy link
Member

@slachiewicz slachiewicz commented Oct 10, 2025

…match in stale data cache

Problem

Starting in version 3.11.3, running mvn javadoc:javadoc twice in succession on Windows with Java 8 fails on the second run with:

java.nio.charset.MalformedInputException: Input length = 1
    at org.apache.maven.plugins.javadoc.AbstractJavadocMojo.isUpToDate(AbstractJavadocMojo.java:5008)

This regression affects Windows users running Java 8, where the default platform encoding is Cp1252.

Root Cause

The issue stems from a charset mismatch in how the stale data cache file is written versus how it's read:

  1. Write operation (StaleHelper.writeStaleData(), line 126):

    • Uses getDataCharset() which returns Charset.defaultCharset() for Java 8
    • On Windows, this is Cp1252
  2. Read operation (AbstractJavadocMojo.isUpToDate(), line 5008):

    • Always uses hardcoded StandardCharsets.UTF_8

When the second run attempts to read a file written with Cp1252 encoding using UTF-8, any non-ASCII bytes cause a MalformedInputException.

Solution

Changed StaleHelper to always save in StandardCharsets.UTF_8 instead of platform-dependent charset. This ensures:

  • Consistent encoding across all platforms (Windows, macOS, Linux)
  • Consistent encoding across all Java versions (8, 11, 17, 21, etc.)
  • Write and read operations use the same charset

Fixes: #1273 #1264

@slachiewicz slachiewicz added the bug Something isn't working label Oct 10, 2025
…match in stale data cache

Changed StaleHelper to always save in UTF-8 instead of
platform-dependent default charset. This ensures consistency with
AbstractJavadocMojo.isUpToDate() which reads the stale data file using UTF-8.

Previously on Windows with Java 8:
- First run: file written with Cp1252 (default charset)
- Second run: file read with UTF-8, causing MalformedInputException
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Regression starting in 3.11.3: java.nio.charset.MalformedInputException: Input length = 1

1 participant