Unexpected Null Analysis Error in loop

Hi,

I get a Null Analysis Error in MicroEJ SDK when I write a piece of code like:

package snippet;

import ej.annotation.NonNullByDefault;

@NonNullByDefault
class A {

	A() {
	}

	void function1() {
		A a = new A();
		A temp = a;

		while (true) {
			a = temp;
			function2(a);  // <-- how 'a' can be null here ?
		}
	}

	private static void function2(A a) {

	}
}

I don’t understand how my local variable ‘a’ can be null at this point.
Do you know what happen and how can I fix that ?

Seems that Eclipse JDT is lost during the null inference of the variable ‘a’:
In this case it considers the local a as Nullable whereas is is never assigned from a Nullable value.

I just created a new issue to Eclipse using your snippet in a standard Java project: https://bugs.eclipse.org/bugs/show_bug.cgi?id=565260.

In the meantime, you just have to help the tool by declaring the local a as NonNull:

@NonNull A a = new A();