Skip to content
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

8307512: Provide more information in message of NoSuchFieldException thrown by Class #14624

Closed
wants to merge 1 commit into from

Conversation

quadhier
Copy link
Contributor

@quadhier quadhier commented Jun 23, 2023

Similar to #11745 , this patch adds more information for NoSuchFieldException thrown by getField() or getDeclaredField() of java.lang.Class. The error message changes like the example below:

  1. For getField()

Before this change:

Exception in thread "main" java.lang.NoSuchFieldException: i
…

After this change:

Exception in thread "main" java.lang.NoSuchFieldException: Class 'Test' does not have member field 'i'
…
  1. For getDeclaredField()

Before this change:

Exception in thread "main" java.lang.NoSuchFieldException: i
…

After this change:

Exception in thread "main" java.lang.NoSuchFieldException: Class 'Test' does not have declared field 'i'
…

Tests tier1-3 has passed for release build on Linux x86-64. (With one failure not related to this.)


Progress

  • Change must be properly reviewed (1 review required, with at least 1 Reviewer)
  • Change must not contain extraneous whitespace
  • Commit message must refer to an issue

Issue

  • JDK-8307512: Provide more information in message of NoSuchFieldException thrown by Class (Enhancement - P4)

Reviewing

Using git

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

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

Using Skara CLI tools

Checkout this PR locally:
$ git pr checkout 14624

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

Using diff file

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

Webrev

Link to Webrev Comment

Sorry, something went wrong.

@bridgekeeper
Copy link

bridgekeeper bot commented Jun 23, 2023

👋 Welcome back dqu! 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 openjdk bot added the rfr Pull request is ready for review label Jun 23, 2023
@openjdk
Copy link

openjdk bot commented Jun 23, 2023

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

  • core-libs

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 core-libs core-libs-dev@openjdk.org label Jun 23, 2023
@mlbridge
Copy link

mlbridge bot commented Jun 23, 2023

Webrevs

@liach
Copy link
Member

liach commented Jun 23, 2023

I think a message like 'Class.field' is better, more consistent with methodToString's behavior.

@quadhier
Copy link
Contributor Author

quadhier commented Jun 23, 2023

I think a message like 'Class.field' is better, more consistent with methodToString's behavior.

Hi, @liach, thanks for your suggestions, this Class.field format is indeed more succinct. But I'm following this format (NoSuchFieldError thrown in linkResolver.cpp).

// check if field exists; i.e., if a klass containing the field def has been selected
if (sel_klass == nullptr) {
ResourceMark rm(THREAD);
stringStream ss;
ss.print("Class %s does not have member field '", resolved_klass->external_name());
sig->print_as_field_external_type(&ss);
ss.print(" %s'", field->as_C_string());
THROW_MSG(vmSymbols::java_lang_NoSuchFieldError(), ss.as_string());
}

Anyway, the point here is that the name of the class should be added to the message. So maybe both are acceptable. Let's wait for some others' opinions :D

@liach
Copy link
Member

liach commented Jun 23, 2023

IMO #11745 is a bit too verbose, compared to the code that prints the absent method in NoSuchMethodError:

if (resolved_method.is_null()) {
// no method found
ResourceMark rm(THREAD);
stringStream ss;
ss.print("'");
Method::print_external_name(&ss, resolved_klass, link_info.name(), link_info.signature());
ss.print("'");
THROW_MSG_NULL(vmSymbols::java_lang_NoSuchMethodError(), ss.as_string());
}

Printing the descriptor directly suffices. Field descriptors are described by JVMS 4.3.2.

@quadhier quadhier closed this Jul 14, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
core-libs core-libs-dev@openjdk.org rfr Pull request is ready for review
Development

Successfully merging this pull request may close these issues.

None yet

2 participants