mtedone / podam

PODAM - POjo DAta Mocker
https://mtedone.github.io/podam
MIT License
323 stars 750 forks source link

When reaching maxDepth, null value is placed in collection #269

Closed shollander closed 5 years ago

shollander commented 5 years ago

If maxDepth is set to avoid too many levels of recursion, and the recursive object is located within a collection; then although maxDepth does prevent recursion beyond the specified depth, it will fill the collection with null values. For example, given this object structure:

public class MyObject {
    private String name;
    private List<MyObject> children;
}

When maxDepth is reached, myObject.children will be equal to [null, null, null, null, null]. I don't think this is the usual expected behavior. Normally, null should not be placed in a collection. I would expect it to just not set any value for the children field at all, leaving it to the class initialization default.

daivanov commented 5 years ago

Hi,

What is value of depth you are using?

Normally, null should not be placed in a collection.

Depth limitation feature has nothing to do with type of the objects. It just counts number of occurrences in the production loop and cuts instantiation, when limit has been reached. In case it will be taking into account type of objects on the tree it will make it hard to predict how it works.

Thanks, Daniil

shollander commented 5 years ago

The value of depth that I am using is 2.

daivanov commented 5 years ago

Yes, with depth 2 Podam will produce MyObject (depth 1) -> List -> MyObject (depth 2) -> List -> null (depth 3)

daivanov commented 5 years ago

I feel this is not a proper solution, as third party libraries not implementing Collection, List or Map interfaces will be handled differently. Also not much can be done for arrays. Probably, a better solution is to allow to customize object population.

daivanov commented 5 years ago

Podam 7.2.2 has been released