-
Notifications
You must be signed in to change notification settings - Fork 5.7k
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
JDK-8276892: Provide a way to emulate exceptional situations in FileManager when using JavadocTester #6404
Conversation
…anager when using JavadocTester
👋 Welcome back jjg! A progress list of the required criteria for merging this PR into |
@jonathan-gibbons 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
|
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.
Initial comments below.
src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/toolkit/resources/doclets.properties
Show resolved
Hide resolved
src/jdk.javadoc/share/classes/jdk/javadoc/internal/tool/Main.java
Outdated
Show resolved
Hide resolved
src/jdk.javadoc/share/classes/jdk/javadoc/internal/tool/Main.java
Outdated
Show resolved
Hide resolved
test/langtools/jdk/javadoc/lib/javadoc/tester/JavadocTester.java
Outdated
Show resolved
Hide resolved
test/langtools/jdk/javadoc/lib/javadoc/tester/TestJavaFileManagerBuilder.java
Outdated
Show resolved
Hide resolved
Here is additional note/suggestion ... The basic API for the builder is very, well, basic, using Early drafts of the code provided overloads for the |
After having looked at this change, I think I might have fallen prey to the famous "XY problem". Instead of asking on how to emulate error conditions in a black-box fashion first, I asked to provide white-box support for those through JavadocTester. Just to make sure we're on the same page and aren't trying to solve a more complex problem than is required. Is there an easy way to make these methods throw: |
I didn't see the question this way, and I thought the JBS issue was well stated. Setting aside
I prefer not to do the first ... I prefer not to build those backdoors into the main file manager that is routinely used everywhere. So that means to do the second. Providing a new file manager to do the job means either using The one surprise/disappointment was the "sort-of technical debt" I discovered in In terms of providing a custom file manager, the question is, "which file objects" and "which methods". I went through a series of iterations before deciding on using That all being said, I accept that the API as presented at this point may seem to be a sledgehammer, and it may be convenient to provide a coat of paint. I like the general underlying architecture of the solution, but maybe we can come up with a method on the builder along the following lines:
We can bike-shed on the name, and maybe there's a 3rd argument To summarize, I don't think the change is as scary as it might appear at first, although it may be somewhat lacking in ease-of-use for common cases. While the code of the builder may seem complicated, with its use of reflection and proxies, the entire class, the file is only 240 lines, including the legal header block and documentation comments.
TL;DR: Yes. But I didn't know about the |
There is an interesting difference between trapping For |
(Sorry for the accidental closed/re-open) |
That sentence ends abruptly. |
I had meant to delete the comment, because I wasn't ready to finish it.; that must be how/why I accidentally closed the PR. For now, I have completed the sentence, but generally, you can ignore the comment. I'll follow up when I have more concrete ideas. |
I should've asked an even more general question before creating JDK-8276892: How can I trigger an error from specific operations on a FileManager and a FileObject returned from that FileManager? A simulation through a custom implementation of these types that this PR proposes would be one answer. However, such a simulation is the white-box approach, and as far as I understand, JDK contributors traditionally prefer the black-box approach. In the black-box approach, one seeks ways to emulate the environment that would yield the desired effect. For example, to trigger IOException on an attempt to delete a file, I would ensure that the path does not exist or that the JVM has insufficient file-system permissions to access that path. Here's another example. To achieve socket blocking on write, I would fill it in with as much data as possible (SO_SNDBUF) while simultaneously ensuring that no one reads from it. If you say that a black-box approach is impossible or impractical here, I'll be fine with the white-box approach along the lines of what this PR suggests. |
[...]
I don't know of a way to reliably trigger the exceptions with the current primary file manager ... i.e. Here's a different way of looking at it, as an instance of a more general problem. For the situation that motivated this issue, the desire is to test/cover the |
Overall, to better handle the ability to throw checked exceptions, the functionality of the builder is changed and now limited to providing functions that can throw user-provided exceptions, instead of fully replacing the underlying delegate method.
test/langtools/jdk/javadoc/lib/javadoc/tester/TestJavaFileManagerBuilder.java
Outdated
Show resolved
Hide resolved
test/langtools/jdk/javadoc/lib/javadoc/tester/TestJavaFileManagerBuilder.java
Outdated
Show resolved
Hide resolved
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 can work with that to test snippets; thanks. Update the copyright years before integrating.
test/langtools/jdk/javadoc/lib/javadoc/tester/TestJavaFileManagerBuilder.java
Show resolved
Hide resolved
src/jdk.javadoc/share/classes/jdk/javadoc/internal/tool/resources/javadoc.properties
Show resolved
Hide resolved
@jonathan-gibbons 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 587 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. ➡️ To integrate this PR with the above commit message to the |
fix copyright year; fix bad tag.
/integrate |
Going to push as commit d52392c.
Your commit was automatically rebased without conflicts. |
@jonathan-gibbons Pushed as commit d52392c. 💡 You may see a message that your pull request was closed with unmerged commits. This can be safely ignored. |
Please review a moderately simple addition to the
JavadocTester
world, to be able to modify the behavior of a file manager to throw exceptions as needed.The bulk of the new functionality is in a new class,
TestJavaFileManagerBuilder
, which uses the builder pattern to allow a client to configure and build a file manager that can provide file objects for which the behavior can be overridden for one or more methods. The expected use case is to throw an exception instead of calling the underlying delegate method.JavadocTester
is modified to allow a file manager to be provided when invokingjavadoc
. This requires some minor changes to the outermost javadoc tool classes,Main
andStart
. Rather than add morestatic
methods toMain
, instance methods are now provided to make it easier to configure the values that will be passed toStart
. InStart
, it was previously assumed that either the default file manager was being used or that all paths would be configured directly in the file manager. The latter part of that assumption is reduced so that path-setting options (e.g.--source-path
,--class-path
etc) can be passed to the provided file manager. (Previously, they were silently ignored.) It is an error to pass path-like options as javadoc options to a file manager that does not support them. However, since none of the changes are visible to any public API, this should not be an issue.A new test is provided, with a few simple test cases. One is for direct use of the new file manager mechanism (without using
javadoc
). The other two illustrate how the feature can be used inside aJavadocTester
call ofjavadoc
. Given that the feature is a relatively simple combination of predicates and proxies, it's not clear that we need a significant body of test cases.Progress
Issue
Reviewers
Reviewing
Using
git
Checkout this PR locally:
$ git fetch https://git.openjdk.java.net/jdk pull/6404/head:pull/6404
$ git checkout pull/6404
Update a local copy of the PR:
$ git checkout pull/6404
$ git pull https://git.openjdk.java.net/jdk pull/6404/head
Using Skara CLI tools
Checkout this PR locally:
$ git pr checkout 6404
View PR using the GUI difftool:
$ git pr show -t 6404
Using diff file
Download this PR as a diff file:
https://git.openjdk.java.net/jdk/pull/6404.diff