0

I'm operating on Java bytecode and ended up with an instruction flow similar to this simplified code:

branch_1:
   new Foo
   astore 42
   goto end
branch_2:
   new Foo
   astore 42
   goto end
end:
   aload 42
   invokespecial Foo.<init>()
   

Namely, the call to new occurs in different branches and the call to the associated constructor is "factorized" in a third branch.

When running the code, Java complains on the aload 42 because it cannot tell the type of the local 42: Type top (current frame, locals[42]) is not assignable to reference type. So far my understanding is that the type of the local 42 is either "uninitialized at line X" in one code path and "uninitialized at line Y" in the other code path, thus the "top" in the error message.

Is there an instruction or another way to tell Java that the result of aload 42 is a reference to an uninitialized Foo?

Julien
  • 2,139
  • 1
  • 19
  • 32

0 Answers0