RFR: 8298065: Provide more information in message of NoSuchFieldError [v4]

Ioi Lam iklam at openjdk.org
Thu Dec 22 23:25:49 UTC 2022


On Thu, 22 Dec 2022 19:35:22 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-4 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)`
>> 
>> The added test considers different types of fields like primitives, arrays, and references.
>
> Matias Saavedra Silva has updated the pull request incrementally with one additional commit since the last revision:
> 
>   Improved style and cleanup

src/hotspot/share/runtime/signature.cpp line 455:

> 453:       strncat(buf, "[]", strlen(buf));
> 454:       buf[strlen(buf)] = '\0';
> 455:     }

Java array dimensions can be up to 255, so the `buf` is not long enough.

Anyway, I think we already have code that can translate a signature like `[I` to the source code form of `int []`. Try this:


super class Foofoo
	version 63:0
{
  public static Method main:"([Ljava/lang/String;)V"
	stack 30 locals 3
  {
                iconst_0;
                iconst_0;
                aconst_null;
		invokestatic	Method "xxx":"(II[I)V";
		return;
  }
} 

$ java -cp . Foofoo
Exception in thread "main" java.lang.NoSuchMethodError: 'void Foofoo.xxx(int, int, int[])'
	at Foofoo.main(Foofoo.jasm)


Writing such conversion is very difficult. You should try to use the existing code (refactoring it as necessary).

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

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


More information about the hotspot-runtime-dev mailing list