Skip to content
This repository has been archived by the owner. It is now read-only.

8206181: ExceptionInInitializerError: improve handling of exceptions in user-provided taglets #44

Closed
wants to merge 2 commits into from

Conversation

pavelrappo
Copy link
Member

@pavelrappo pavelrappo commented Dec 17, 2021

Using a custom taglet may result in exceptions, not all of which are javadoc bugs. Some of these exceptions are taglet bugs.

It was noticed that an exception in a static initializer of a custom taglet looks like a javadoc bug, which it is not. The fix was to trivially catch java.lang.ExceptionInInitializerError and translate it into an error like it is already done for some other exceptions.

While working on this fix, I noticed that there were no tests that cover various exceptions that could arise while registering a taglet:

  • ClassNotFoundException
  • NoSuchMethodException
  • InstantiationException
  • InvocationTargetException

I added a test to cover all of those as well as ExceptionInInitializerError and ClassCastException, which I proactively handled similarly to ExceptionInInitializerError.

I note that a typical taglet-registration error message is quite poor and should be improved in the future. For example, it is unclear that the method that javadoc cannot find is the nullary (i.e. parameterless or no-arg) MyTaglet constructor:

Error - Exception java.lang.NoSuchMethodException thrown while trying to register Taglet MyTaglet...

Progress

  • Change must not contain extraneous whitespace
  • Commit message must refer to an issue
  • Change must be properly reviewed

Issue

  • JDK-8206181: ExceptionInInitializerError: improve handling of exceptions in user-provided taglets

Reviewers

Reviewing

Using git

Checkout this PR locally:
$ git fetch https://git.openjdk.java.net/jdk18 pull/44/head:pull/44
$ git checkout pull/44

Update a local copy of the PR:
$ git checkout pull/44
$ git pull https://git.openjdk.java.net/jdk18 pull/44/head

Using Skara CLI tools

Checkout this PR locally:
$ git pr checkout 44

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

Using diff file

Download this PR as a diff file:
https://git.openjdk.java.net/jdk18/pull/44.diff

public class ExceptionInInitializerErrorTaglet implements Taglet {

static {
if (true) {
Copy link
Contributor

@jonathan-gibbons jonathan-gibbons Dec 17, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does the if (true) have any significance?

javac will optimize it, per JLS.

Copy link
Member Author

@pavelrappo pavelrappo Dec 17, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

$ jshell
|  Welcome to JShell -- Version 17
|  For an introduction type: /help intro

jshell> public class Whatever {
   ...> 
   ...>     static {
   ...>         throw new RuntimeException();
   ...>     }
   ...> }
   ...> 
|  Error:
|  initializer must be able to complete normally
|      static {
|      ^-------...

Copy link
Contributor

@jonathan-gibbons jonathan-gibbons left a comment

LGTM, within the spirit of the existing code.

Please file a followup bug for a more comprehensive cleanup to protect against errors in user code, like (untrusted) user-provided tablets and doclets. While this could be loosely modeled on javac ClientCodeWrapper and ClientCodeException, this time round it might be reasonable to use a Proxy-based wrapper, to catch exceptions in user-code and then throw them in a wrapped exception for better handling at a higher level. That suggests that going forward, failure to init a taglet should be a fatal error. Note: one potential complication for javadoc not found in javac is the hard tool-to-doclet abstraction barrier.

@bridgekeeper
Copy link

@bridgekeeper bridgekeeper bot commented Dec 17, 2021

👋 Welcome back prappo! 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 openjdk bot commented Dec 17, 2021

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

8206181: ExceptionInInitializerError: improve handling of exceptions in user-provided taglets

Reviewed-by: jjg

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 no new commits pushed to the master branch. If another commit should be pushed before you perform the /integrate command, your PR will be automatically rebased. If you prefer to avoid any potential automatic rebasing, please check the documentation for the /integrate command for further details.

➡️ To integrate this PR with the above commit message to the master branch, type /integrate in a new comment.

@openjdk openjdk bot added ready rfr labels Dec 17, 2021
@openjdk
Copy link

@openjdk openjdk bot commented Dec 17, 2021

@pavelrappo The following label will be automatically applied to this pull request:

  • javadoc

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 javadoc label Dec 17, 2021
@mlbridge
Copy link

@mlbridge mlbridge bot commented Dec 17, 2021

Webrevs

@pavelrappo
Copy link
Member Author

@pavelrappo pavelrappo commented Jan 11, 2022

Please file a followup bug

Done: https://bugs.openjdk.java.net/browse/JDK-8279843

@pavelrappo
Copy link
Member Author

@pavelrappo pavelrappo commented Jan 11, 2022

/integrate

@openjdk
Copy link

@openjdk openjdk bot commented Jan 11, 2022

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

  • 86d0abb: 8279695: [TESTBUG] modify compiler/loopopts/TestSkeletonPredicateNegation.java to run on C1 also
  • 6d7db4b: 8279356: Method linking fails with guarantee(mh->adapter() != NULL) failed: Adapter blob must already exist!
  • 92307e5: 8278489: Preserve result in native wrapper with +UseHeavyMonitors
  • bbc1ddb: 8278267: ARM32: several vector test failures for ASHR
  • 40df5df: 8279398: jdk/jfr/api/recording/time/TestTimeMultiple.java failed with "RuntimeException: getStopTime() > afterStop"
  • ad34f03: 8279515: C1: No inlining through invokedynamic and invokestatic call sites when resolved class is not linked
  • 928e347: 8279032: compiler/loopopts/TestSkeletonPredicateNegation.java times out with -XX:TieredStopAtLevel < 4
  • 354c904: 8273452: DocTrees.getDocCommentTree should be specified as idempotent
  • 06b4d49: 8278344: sun/security/pkcs12/KeytoolOpensslInteropTest.java test fails because of different openssl output
  • 8f969a1: 8278930: javac tries to compile a file twice via PackageElement.getEnclosedElements
  • ... and 41 more: https://git.openjdk.java.net/jdk18/compare/b46f0b0b1f2ada705f8b5aac9b7d8423699437a1...master

Your commit was automatically rebased without conflicts.

@openjdk openjdk bot added the integrated label Jan 11, 2022
@openjdk openjdk bot closed this Jan 11, 2022
@openjdk openjdk bot removed ready rfr labels Jan 11, 2022
@openjdk
Copy link

@openjdk openjdk bot commented Jan 11, 2022

@pavelrappo Pushed as commit 5aecb37.

💡 You may see a message that your pull request was closed with unmerged commits. This can be safely ignored.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
integrated javadoc
2 participants