Skip to content

Fix incremental detection of empty sources, 4.x - #1076

Merged
desruisseaux merged 2 commits into
apache:masterfrom
wilx:issue-1000-empty-source-4.x
Jul 20, 2026
Merged

desruisseaux merged 2 commits into
apache:masterfrom
wilx:issue-1000-empty-source-4.x

Conversation

@wilx

@wilx wilx commented Jul 12, 2026

Copy link
Copy Markdown
Contributor

Class-based incremental compilation assumes every Java source produces an inferred output file. A zero-byte compilation unit produces no class file, so it was detected as modified on every invocation.

This change records whether a source is empty using the file attributes already collected during source scanning. A modified zero-byte source is treated as ignorable only when its inferred output does not exist. If an output does exist, the source remains stale so truncating an existing source is still detected as a change.

A regression test compiles an empty source twice with class-based incremental detection and verifies that the second invocation reports all classes as up to date.

Fixes #1000.

Following this checklist to help us incorporate your
contribution quickly and easily:

  • Your pull request should address just one issue, without pulling in other changes.
  • Write a pull request description that is detailed enough to understand what the pull request does, how, and why.
  • Each commit in the pull request should have a meaningful subject line and body.
    Note that commits might be squashed by a maintainer on merge.
  • Write unit tests that match behavioral changes, where the tests fail if the changes to the runtime are not applied.
    This may not always be possible but is a best-practice.
  • Run mvn verify to make sure basic checks pass.
    A more thorough check will be performed on your pull request automatically.
  • You have run the integration tests successfully (mvn -Prun-its verify).

If your pull request is about ~20 lines of code you don't need to sign an
Individual Contributor License Agreement if you are unsure
please ask on the developers list.

To make clear that you license your contribution under
the Apache License Version 2.0, January 2004
you have to acknowledge this by using the following check-box.

Zero-byte Java sources do not produce class files, so class-based incremental detection treated them as modified on every invocation. Record source emptiness and ignore an empty source when its inferred output does not exist.

Add a regression test that compiles an empty source twice and verifies that the second invocation is up to date.

Fixes apache#1000.
@wilx wilx changed the title Fix incremental detection of empty sources Fix incremental detection of empty sources, 4.x Jul 12, 2026
@wampiedriessen

Copy link
Copy Markdown

For this PullRequest, please also consider the case where a Java source file consists of only comments.
Making it effectively empty as well

@wilx

wilx commented Jul 20, 2026

Copy link
Copy Markdown
Contributor Author

This would require parsing the Java file. There are parsers that can be used, I think. However, it seems like overkill for already marginal situation.

@desruisseaux
desruisseaux merged commit 19bd927 into apache:master Jul 20, 2026
20 checks passed
@github-actions

Copy link
Copy Markdown

@desruisseaux Please assign appropriate label to PR according to the type of change.

@github-actions github-actions Bot added this to the 4.0.0-beta-5 milestone Jul 20, 2026
@desruisseaux desruisseaux added the enhancement New feature or request label Jul 20, 2026
@desruisseaux

Copy link
Copy Markdown
Contributor

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Empty Java source files are always detected as changed by compiler:compile, which triggers full recompilation of all dependent modules.

3 participants