Skip to content

Conversation

@david-beaumont
Copy link
Contributor

@david-beaumont david-beaumont commented Feb 19, 2025

Modifying JavacFileManager to 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

  • Change must be properly reviewed (1 review required, with at least 1 Reviewer)
  • Change must not contain extraneous whitespace
  • Change requires CSR request JDK-8350492 to be approved
  • Commit message must refer to an issue

Warning

 ⚠️ Found leading lowercase letter in issue title for 8338675: javac shouldn't silently change .jar files on the classpath

Issues

  • JDK-8338675: javac shouldn't silently change .jar files on the classpath (Bug - P4)
  • JDK-8350492: javac shouldn't silently change .jar files on the classpath (CSR)

Reviewers

Reviewing

Using git

Checkout this PR locally:
$ git fetch https://git.openjdk.org/jdk.git pull/23699/head:pull/23699
$ git checkout pull/23699

Update a local copy of the PR:
$ git checkout pull/23699
$ git pull https://git.openjdk.org/jdk.git pull/23699/head

Using Skara CLI tools

Checkout this PR locally:
$ git pr checkout 23699

View PR using the GUI difftool:
$ git pr show -t 23699

Using diff file

Download this PR as a diff file:
https://git.openjdk.org/jdk/pull/23699.diff

Using Webrev

Link to Webrev Comment

@bridgekeeper
Copy link

bridgekeeper bot commented Feb 19, 2025

👋 Welcome back david-beaumont! A progress list of the required criteria for merging this PR into master will be added to the body of your pull request. There are additional pull request commands available for use with this pull request.

@openjdk
Copy link

openjdk bot commented Feb 19, 2025

@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:

8338675: javac shouldn't silently change .jar files on the classpath

Reviewed-by: jlahoda

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 master branch:

  • 2a31f69: 8353331: Test ForkJoinPool20Test::testFixedDelaySequence is failing
  • 1809138: 8352284: EXTRA_CFLAGS incorrectly applied to BUILD_LIBJVM src/hotspot C++ source files
  • cef5610: 8353272: One instance of STATIC_LIB_CFLAGS was missed in JDK-8345683
  • 6801eb8: 8352709: Remove bad timing annotations from WhileOpTest.java
  • 85a0baf: 8352719: Add an equals sign to the modules statement
  • f25f701: 8353226: JFR: emit old object samples must be transitive closure complete for segment
  • aff5aa7: 8350566: NMT: add size parameter to MemTracker::record_virtual_memory_tag
  • 196334f: 8352046: Test testEcoFriendly() in jdk tools launcher ExecutionEnvironment.java for AIX and Linux/musl is brittle
  • ad48846: 8350386: Test TestCodeCacheFull.java fails with option -XX:-UseCodeCacheFlushing
  • 8b4e190: 8353349: ProblemList runtime/cds/appcds/SignedJar.java
  • ... and 663 more: https://git.openjdk.org/jdk/compare/7e307916ecbf1ae9795e42e5b5a8347daad4af8c...master

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 /integrate in a new comment. (Afterwards, your sponsor types /sponsor in a new comment to perform the integration).

@openjdk
Copy link

openjdk bot commented Feb 19, 2025

@david-beaumont The following label will be automatically applied to this pull request:

  • compiler

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.

@openjdk openjdk bot added the compiler compiler-dev@openjdk.org label Feb 19, 2025
@david-beaumont david-beaumont marked this pull request as ready for review February 20, 2025 17:08
@openjdk openjdk bot added the rfr Pull request is ready for review label Feb 20, 2025
@mlbridge
Copy link

mlbridge bot commented Feb 20, 2025

@jddarcy
Copy link
Member

jddarcy commented Feb 21, 2025

/csr needed

@openjdk openjdk bot added the csr Pull request needs approved CSR before integration label Feb 21, 2025
@openjdk
Copy link

openjdk bot commented Feb 21, 2025

@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.

Copy link
Contributor

@lahodaj lahodaj left a 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.

public static void main(String[] args) throws IOException {
ToolBox tb = new ToolBox();
tb.createDirectories("lib");
tb.writeFile(LIB_SOURCE_NAME, OLD_LIB_SOURCE);
Copy link
Contributor

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).

Copy link
Contributor Author

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.

@david-beaumont
Copy link
Contributor Author

@lahodaj Is there anything else you think needs to be done for this PR? I think the CSR will be finalized very soon.

@lahodaj
Copy link
Contributor

lahodaj commented Feb 28, 2025

I think it would be useful to have an answer to this CSR question:
https://bugs.openjdk.org/browse/JDK-8350492?focusedId=14755916&page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#comment-14755916

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.
Copy link
Member

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.

Copy link
Contributor Author

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 {
Copy link
Member

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.

Copy link
Contributor

@lahodaj lahodaj left a 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.

@openjdk openjdk bot added ready Pull request is ready to be integrated and removed csr Pull request needs approved CSR before integration labels Mar 31, 2025
* 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
Copy link
Member

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?

Copy link
Contributor Author

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
Copy link
Member

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.

@openjdk openjdk bot removed the ready Pull request is ready to be integrated label Apr 1, 2025
Copy link
Contributor

@lahodaj lahodaj left a 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.

@openjdk openjdk bot added the ready Pull request is ready to be integrated label Apr 1, 2025
@david-beaumont
Copy link
Contributor Author

/integrate

@openjdk openjdk bot added the sponsor Pull request is ready to be sponsored label Apr 1, 2025
@openjdk
Copy link

openjdk bot commented Apr 1, 2025

@david-beaumont
Your change (at version 6fcea57) is now ready to be sponsored by a Committer.

@lahodaj
Copy link
Contributor

lahodaj commented Apr 3, 2025

/sponsor

@openjdk
Copy link

openjdk bot commented Apr 3, 2025

Going to push as commit bd74922.
Since your change was applied there have been 706 commits pushed to the master branch:

Your commit was automatically rebased without conflicts.

@openjdk openjdk bot added the integrated Pull request has been integrated label Apr 3, 2025
@openjdk openjdk bot closed this Apr 3, 2025
@openjdk openjdk bot removed ready Pull request is ready to be integrated rfr Pull request is ready for review sponsor Pull request is ready to be sponsored labels Apr 3, 2025
@openjdk
Copy link

openjdk bot commented Apr 3, 2025

@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.

@david-beaumont david-beaumont deleted the JDK-8338675 branch June 28, 2025 16:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

compiler compiler-dev@openjdk.org integrated Pull request has been integrated

Development

Successfully merging this pull request may close these issues.

3 participants