Skip to content

Conversation

@lefou
Copy link
Member

@lefou lefou commented Nov 28, 2025

Deprecate all static final fields of OutFiles and define those values in non-static final fields inside a singleton.

The Problem

Constants that might change in subsequent releases or even between subseqent runs of Mill should not be hold by static final fields in Java.

Since the compiler is allowed to inline those fields in their call sites, downstream bytecode may use stale values. This often happens unnoticed, but it can lead to incorrect behavior and hard to diagnose error. The probably worst case for a build tools like Mill is that we produce and publish incorrect artifacts which goes unnoticed. (E.g. if a stale value for the out path is used, some task might collect the wrong files.)

Instead, we should either use methods (which results in more boilerplate) or non-static fields.

Impact

I choose the same name OutFiles for the inner singleton accessor, so that all callsite look identical, except the different import. The import changes from mill.constants.OutFiles to mill.constants.OutFiles.OutFiles.

To preserve binary compatibility, these changes were made:

  • Added a new (inner) class OutFiles1 to hold the non-static final fields
  • Deprecate the static final fields
  • Forward all deprected fields to their new definitions

…ttings

To preserve binary compatibility, these changes were made:
* Added a new (inner) class `OutFiles1` to hold the non-static final fields
* Deprecate the static final fields
* Forward all deprected fields to their new definitions
@lefou lefou changed the title Use a static singleton instance instead of static field for shared settings OutFiles: use static singleton instance instead of static fields Nov 28, 2025
@lefou lefou changed the title OutFiles: use static singleton instance instead of static fields OutFiles: use singleton instance instead of static fields Nov 28, 2025
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.

1 participant