Skip to content

[WIP] Include existing output directories on the compiler classpath - #1127

Open
goutamadwant wants to merge 2 commits into
apache:masterfrom
goutamadwant:wip-1036-output-classpath
Open

goutamadwant wants to merge 2 commits into
apache:masterfrom
goutamadwant:wip-1036-output-classpath

Conversation

@goutamadwant

Copy link
Copy Markdown

Related to #1036.

Draft for design review. A known correctness regression blocks merging this change.

The current compiler plugin omits the output directory from the classpath during full compilation. This prevents Java sources from resolving classes written earlier by Kotlin, in both main and test compilation.

This draft adds the output directory to the nonmodular classpath and covers main/test compilation with embedded and forked javac. The four native regressions fail on unchanged production code, and the reporter's mixed Kotlin/Java project passes with the initial implementation.

Broader validation exposed stale Java bytecode reuse: after removing a source or a secondary class declaration, a full rebuild can incorrectly succeed by resolving the old class file from the output directory. The existing source-to-output cache cannot identify every javac-produced class. Reliable output ownership and cleanup are needed before enabling this behavior generally.

The annotation-processor fixture also needed to disable processing while compiling its own provider, whose service descriptor is copied before its class exists. This is restricted to the provider module; the consuming module still exercises annotation processing. Compiler 3.15 reproduces the same provider self-discovery failure.

Validation evidence:

  • Initial clean verify passed 20 tests on Java 17 and Java 21.
  • The reporter project passed normal and forked clean builds, with four tests each.
  • The initial full integration run reported 79 passed, two failed, and two skipped. The processor fixture was subsequently corrected, but the stale-class regression remains and no passing final full integration run is claimed.
  • A separate reproduction confirms incorrect success after removing a package-private class declaration from a source file that remains present.

Proposed next step: agree on compiler-output ownership tracking, including partial/full builds, failed compilations, cache migration, multiple executions and multi-release outputs, while preserving classes generated by earlier compilers.

Expose earlier compiler output during main and test compilation and add mixed-language and forked regression coverage. Related to apache#1036.

This is an incomplete comparison for review. Broader validation demonstrates stale Java bytecode can satisfy references after sources or declarations are removed. Output ownership and cleanup must be addressed before this change can be merged. The full integration suite is not passing.
if (location.isPresent()) { // Cannot use `Optional.ifPresent(…)` because of checked IOException.
var value = location.get();
if (value == StandardLocation.CLASS_PATH) {
if (isPartialBuild && !hasModuleDeclaration) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think that you should delete this block, unless you find it to be wrong. In my understanding, the only change which is needed is the removal of the isPartialBuild flag.

if (!paths.contains(outputDirectory)) {
paths.add(outputDirectory);
}
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do not add this block if the suggestion to not remove the block below is applied.

Signed-off-by: goutamadwant <workwithgoutam@gmail.com>
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.

2 participants