-
Notifications
You must be signed in to change notification settings - Fork 6.2k
8338675: javac shouldn't silently change .jar files on the classpath #23699
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
|
👋 Welcome back david-beaumont! A progress list of the required criteria for merging this PR into |
|
@david-beaumont This change now passes all automated pre-integration checks. ℹ️ This project also has non-automated pre-integration requirements. Please see the file CONTRIBUTING.md for details. After integration, the commit message for the final commit will be: You can use pull request commands such as /summary, /contributor and /issue to adjust it as needed. At the time when this comment was updated there had been 673 new commits pushed to the
As there are no conflicts, your changes will automatically be rebased on top of these commits when integrating. If you prefer to avoid this automatic rebasing, please check the documentation for the /integrate command for further details. As you do not have Committer status in this project an existing Committer must agree to sponsor your change. Possible candidates are the reviewers of this PR (@lahodaj) but any other Committer may sponsor as well. ➡️ To flag this PR as ready for integration with the above commit message, type |
|
@david-beaumont The following label will be automatically applied to this pull request:
When this pull request is ready to be reviewed, an "RFR" email will be sent to the corresponding mailing list. If you would like to change these labels, use the /label pull request command. |
Webrevs
|
|
/csr needed |
|
@jddarcy has indicated that a compatibility and specification (CSR) request is needed for this pull request. @david-beaumont please create a CSR request for issue JDK-8338675 with the correct fix version. This pull request cannot be integrated until the CSR request is approved. |
lahodaj
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The fix as such seems reasonable to me. The test is good, but I added some comments for possible improvements for the test.
test/langtools/tools/javac/T8338675/NoOverwriteJarClassFilesByDefault.java
Outdated
Show resolved
Hide resolved
test/langtools/tools/javac/T8338675/NoOverwriteJarClassFilesByDefault.java
Outdated
Show resolved
Hide resolved
test/langtools/tools/javac/T8338675/NoOverwriteJarClassFilesByDefault.java
Outdated
Show resolved
Hide resolved
| public static void main(String[] args) throws IOException { | ||
| ToolBox tb = new ToolBox(); | ||
| tb.createDirectories("lib"); | ||
| tb.writeFile(LIB_SOURCE_NAME, OLD_LIB_SOURCE); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Using Paths based on relative paths is not wrong, I think, but I think I would suggest to create same Path base = Paths.get("<testcasename>");, and in the rest of the test use Path derived from the base path. So that it is easier to e.g. change the location of the working directory.
Also note ToolBox has writeJavaFile, which infers the relative path automatically in almost all cases (not so useful in this case, of course, as this test needs to know the real path anyway).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was under the impression that JTreg already moves into a test-specific scratch directory which is guaranteed empty at test start, so it's fine to write test files from the "current" directory.
Since I'm still learning best-practice around this, if you have docs or other links giving best practice for test file naming, I'd be very grateful.
test/langtools/tools/javac/T8338675/NoOverwriteJarClassFilesByDefault.java
Outdated
Show resolved
Hide resolved
test/langtools/tools/javac/T8338675/NoOverwriteJarClassFilesByDefault.java
Outdated
Show resolved
Hide resolved
test/langtools/tools/javac/T8338675/NoOverwriteJarClassFilesByDefault.java
Outdated
Show resolved
Hide resolved
|
@lahodaj Is there anything else you think needs to be done for this PR? I think the CSR will be finalized very soon. |
|
I think it would be useful to have an answer to this CSR question: I suspect best would be to have some tests for the Filer methods. Please note you'll have to mark the CSR Finalized before it is considered again. Thanks! |
| if (sibling != null && sibling instanceof PathFileObject pathFileObject) { | ||
| // Use the sibling to determine the output location where possible, unless | ||
| // it is in a JAR/ZIP file (we don't attempt to write class files back into | ||
| // archives). See JDK-8338675. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Per usual JDK coding conventions, we don't put bug numbers into source code.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wasn't aware of this. Thanks.
| } | ||
|
|
||
| @SupportedAnnotationTypes("*") | ||
| static class TestAnnotationProcessor extends AbstractProcessor { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please see the test library file
langtools/toosl/javac/lib/JavacTestingAbstractProcessor.java
and consider extending that class instead.
lahodaj
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks reasonable to me.
| * written back into the JAR in which its source was found, possibly overwriting | ||
| * an existing class file entry. This would be very problematic. | ||
| * <p> | ||
| * This test ensures javac will not modify JAR files on the classpath, even if |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does something reasonable happen if the soucepath and classpath are both set to the same jar file?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Behaviour is same for either/both. Jar file is never modified, sources appear in the working directory.
| * | ||
| * <h2>Important</h2> | ||
| * | ||
| * This test creates files from Java compilation and annotation processing, and |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I suppose some of the desired effect could be achieved using jtreg directives instead, but this approach seems fine too.
lahodaj
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The new tests seems reasonable to me.
|
/integrate |
|
@david-beaumont |
|
/sponsor |
|
Going to push as commit bd74922.
Your commit was automatically rebased without conflicts. |
|
@lahodaj @david-beaumont Pushed as commit bd74922. 💡 You may see a message that your pull request was closed with unmerged commits. This can be safely ignored. |
Modifying
JavacFileManagerto skip creating sibling output class files for source files found in JARs.This should match older (JDK 8) behavior whereby the JAR was not writable, and results in any newly generated class files being written to the current working directory (the output of class files into current directory isn't good, but it should match the old behavior).
Progress
Warning
8338675: javac shouldn't silently change .jar files on the classpathIssues
Reviewers
Reviewing
Using
gitCheckout this PR locally:
$ git fetch https://git.openjdk.org/jdk.git pull/23699/head:pull/23699$ git checkout pull/23699Update a local copy of the PR:
$ git checkout pull/23699$ git pull https://git.openjdk.org/jdk.git pull/23699/headUsing Skara CLI tools
Checkout this PR locally:
$ git pr checkout 23699View PR using the GUI difftool:
$ git pr show -t 23699Using diff file
Download this PR as a diff file:
https://git.openjdk.org/jdk/pull/23699.diff
Using Webrev
Link to Webrev Comment