RFR: 8298065: Provide more information in message of NoSuchFieldError

David Holmes dholmes at openjdk.org
Wed Dec 21 08:33:51 UTC 2022


On Tue, 20 Dec 2022 22:55:59 GMT, Matias Saavedra Silva <matsaave at openjdk.org> wrote:

> A java.lang.NoSuchFieldError is typically thrown when you remove a field but do not recompile the client code that calls the field. However, the message does not indicate in which class the field was not found. 
> 
> Additionally, java.lang.NoSuchFieldError is thrown if the field is still present but the types are incompatible. For example, if a field is first defined as int, and later changed to long without recompiling the client. The error text has been expanded to include the class name and field type. Verified with tier 1 tests.
> 
> Old output:
> `Exception in thread "main" java.lang.NoSuchFieldError: x
>         at NoSuchFieldMain.main(NoSuchFieldMain.java:3)`
> Example output:
> `Exception in thread "main" java.lang.NoSuchFieldError: Class Other does not have field 'int x'
>         at NoSuchFieldMain.main(NoSuchFieldMain.java:3)`

Unclear on the way Object types are reported but the general idea is fine.

A few comments/suggestions around the test.

I would also search for any tests that catch `NoSuchFieldError` in case they look for specific messages (e.g. in reflection tests).

Thanks.

src/hotspot/share/interpreter/linkResolver.cpp line 977:

> 975:     THROW_MSG(vmSymbols::java_lang_NoSuchFieldError(),
> 976:         err_msg("No resolved class, field '%s %s'",
> 977:                 type2name(Signature::basic_type(sig->char_at(0))),

Isn't this going to report "object" for all non-primitive types?

test/hotspot/jtreg/runtime/linkResolver/FieldName.java line 24:

> 22:  */
> 23: 
> 24: /*  Let jtreg compile this one with NoSuchFieldTest.java */

Suggestion:

/* Base definition for compilation by javac. */

test/hotspot/jtreg/runtime/linkResolver/FieldName.java line 38:

> 36: public class FieldName {
> 37: }
> 38: */

These comments belong in the respective jasm files

test/hotspot/jtreg/runtime/linkResolver/FieldName1.jasm line 1:

> 1: 

Missing copyright and licence header

test/hotspot/jtreg/runtime/linkResolver/FieldName2.jasm line 1:

> 1: 

Missing copyright and licence header

-------------

Changes requested by dholmes (Reviewer).

PR: https://git.openjdk.org/jdk/pull/11745


More information about the hotspot-runtime-dev mailing list