RFR: 8338675: javac shouldn't silently change .jar files on the classpath
David Beaumont
duke at openjdk.org
Fri Feb 21 10:24:57 UTC 2025
On Fri, 21 Feb 2025 10:07:45 GMT, David Beaumont <duke at openjdk.org> wrote:
>> test/langtools/tools/javac/T8338675/NoOverwriteJarClassFilesByDefault.java line 100:
>>
>>> 98: // The class file generated he is in the lib/ directory, which we delete
>>> 99: // after making the JAR (just to be sure).
>>> 100: new JavacTask(tb).files(LIB_SOURCE_NAME).run();
>>
>> I tend to use `.writeAll()` after `.run()`, so that if there's any output, it is written out. (Admittedly, the run method could be changed to do that automatically, but I don't think it does currently.)
>>
>> Also, nit: might be nicer to format this using a "builder" style:
>>
>> new JavacTask(tb)
>> .file(LIB_SOURCE_NAME)
>> .run()
>> .writeAll();
>>
>>
>> Also note there's `ToolBox.findJavaFiles`, which finds Java sources in the given directories. No that useful here, but might be useful in some cases.
>
> IntelliJ formatting did this. If there was a recommended IJ formatter setup that would would "just work (tm)" I'd love to know about it.
>
> I didn't know about the `writeAll()` thing, and several tests I looked at don't do this (and appear to work reliably) so I think it always writes things out. I will double check for my own edification.
Ahh I see, `writeAll()` is for stream output, not file writing. It's flushed for cases where compilation doesn't proceed as expected, but not "normally". So adding it here only affects the currency of stream output while the test is running.
-------------
PR Review Comment: https://git.openjdk.org/jdk/pull/23699#discussion_r1965235482
More information about the compiler-dev
mailing list