One more case of false-positive cycles detection [DATAMONGO-1652] #2558
Labels
in: mapping
Mapping and conversion infrastructure
status: duplicate
A duplicate of another issue
type: bug
A general bug
Sergey Bykov opened DATAMONGO-1652 and commented
The cycles detector gives false warnings under some conditions. The issue occurs when there are multiple similar 'branches' in the tree of the included objects.
Example reproducing the issue
Full working example can be seen here: https://github.com/centibit/spring-data-mongodb-false-positive-cycle-detection
Main entity A includes two value objects B and C:
Class B is not highly interesting, the only note is it must include some fields not of simple types, for example D (the contents of D doesn’t matter):
Class C also includes B (it is crucial that B is included both in A and C):
When the application with such a class structure boots, it gives a false warning:
org.springframework.data.mongodb.core.index.MongoPersistentEntityIndexResolver$CyclicPropertyReferenceException: Found cycle for field 'd' in type 'B' for path 'b'
which was probably intended to fix such cases but still fails under some rare conditions.Source of the problem
When MongoPersistentEntityIndexResolver searches for the cycles, it records the possible inclusion paths as a set of the strings, and then tries to match the current stringified path with the previously found paths. In this example ".b" is found to be a substring of "c.b", so it gives a false positive warning.
Note that C must include some non-simple fields (class D in the example), otherwise it would be outfiltered by the conditional logic in
org.springframework.data.mapping.model.AbstractPersistentProperty.getTypeInformationIfEntityCandidate
.Quick workaround
Simply swap the lines
public B b;
andpublic C c;
in the definition of the class A. In this case, traverse order changes, and the cycle detector will try to check whether "c.b" is a substring of ".b", which is not, and no warning will be issued :)Affects: 1.10.1 (Ingalls SR1)
Reference URL: https://github.com/centibit/spring-data-mongodb-false-positive-cycle-detection
Issue Links:
("is duplicated by")
The text was updated successfully, but these errors were encountered: