Explicitly constructed NPE is showing (wrong) message

Christoph Dreis christoph.dreis at freenet.de
Sat Jun 27 09:54:19 UTC 2020


I hope this is the correct mailing list.

The latest changes on JDK-8233014 to enable ShowCodeDetailsInExceptionMessages by default have uncovered a likely bug (I think).

To my understanding explicitly created NullPointerExceptions should not print any message.
With the following example:

public class Main {
	public static void main(String[] args) {
		NullPointerException ex = new NullPointerException();
		Throwable throwable = ex.fillInStackTrace();

I see the following output though:

java.lang.NullPointerException: Cannot invoke "java.lang.NullPointerException.fillInStackTrace()" (on slot 0) because "ex" is null

Which obviously is not really true.
I was debugging the thing (hence the additional "on slot 0") output, but couldn't find the error so far.

I'm suspecting the error to be somewhere around bytecodeUtils.cpp 1155:

        if (name != vmSymbols::object_initializer_name()) {
          int     type_index = cp->signature_ref_index_at(name_and_type_index);
          Symbol* signature  = cp->symbol_at(type_index);
          // The 'this' parameter was null. Return the slot of it.
          return ArgumentSizeComputer(signature).size();
        } else {

I initially hoped to find a fix for it directly, but I would probably need a bit more time for it, so I decided to report it.
Is this a bug even or am I chasing ghosts here? In case it is, I would be happy about a mentioning somewhere in an eventual commit.


More information about the hotspot-runtime-dev mailing list