almondtools / testrecorder

Create Test Fixtures from Runnable Java Code
http://testrecorder.amygdalum.net/
GNU Lesser General Public License v3.0
51 stars 5 forks source link

Constructors invoking virtual methods lead to NullpointerException #13

Closed almondtools closed 8 years ago

almondtools commented 8 years ago

The problem is that the generator variable is not initialized at the beginning of the constructor. Any method relying that this variable is already set will fail, causing a NullpointerException.

First approach was to initialize the generator variable lazily. That does solve the NullpointerException problem.

But it causes a followup problem: To find the best deserialization of an object Testrecorder reflectively calls constructors. At any time a constructor is called the virtual method is called and if a snapshot is done on it, the generator will jump in, causing a really bad performance.

almondtools commented 8 years ago

One solution could be: Replace Injection of generator variable with static factory lookup.

This lookup should return a generator dummy in cases where recording is not expected.