|
If PersistentBag is uninitialized, calling the toString() method should not cause lazy loading of data. Reasoning:
1. toString() method, by java.lang.Object.toString() documentation, should return a string representation of the object. In this case it changes the object state or throws LazyInitializationException.
2. In eclipse, if I debug an application and show variables, then after clicking on PersistentBag it calls toString(). This causes lazy initialization, which is unexpected side effect.
3. If you are debugging NotSerializableException and add JVM parameter -Dsun.io.serialization.extendedDebugInfo=true, then you are unable to serialize PersistentBag at all, as the toString() is called on detached instance, which fails with LazyInitializationException. This renders the serialization debugging unusable.
Suggested fix: if the instance is uninitialized, toString() should not cause lazy initialization of data, and instead return message such as "uninitialized collection".
|