javac --module option and stale classes
Christian Stein
sormuras at gmail.com
Wed Jul 29 12:49:14 UTC 2020
Hi,
when using the --module option of javac, the Java source files
of a module are automatically added to the list of to be compiled
files, checking timestamps. This works as expected as long as
existing source files are changed and/or new source files are
added.
If a Java source file is deleted from a module its associated
class files are left in place (within the -d destination directory).
This leads to unexpected and wrong results in downstream
tool calls - for example, a JAR file with stale/orphaned classes
as described by [0].
The straightforward "solution" is to delete the -D directory
prior to every call of javac --module ... which leads to a
"rebuild" of all modules and effectively by-passes the gains
provided by the timestamp check.
This "solution" can be fine-tuned in some ways via
remembering checksums and other external measures.
I wonder whether the logic at [1] is a) the sole place that
controls this feature and b) whether it can be enhanced
to also prune stale classes from previous javac runs.
Cheers,
Christian
[0] https://github.com/sormuras/bach/issues/158
[1]
https://github.com/openjdk/jdk/blob/76baa501faa11c934f7ee8e463e13d098ef90518/src/jdk.compiler/share/classes/com/sun/tools/javac/main/Arguments.java#L426-L435
More information about the jigsaw-dev
mailing list