I have encountered a very strange issue and I'm not sure what to make of it.
It seems that: if AOP is enabled, Spring Data Rest is enabled, and a bean is marked @Lazy, then the constants in TypeInformation return null instead of thier expected values. I was able to narrow this down to a minimal example project.
That example project encompasses pretty much everything I know about this problem in the most minimal form I could find; but I'm more than happy to answer any questions if I can.
Comment From: wilkinsona
Thanks for the report.
I've managed to reduce things down quite a bit more and can reproduce the failure with the following:
package com.example.lazyproxyissue;
import static org.assertj.core.api.Assertions.assertThat;
import org.junit.jupiter.api.Test;
import org.springframework.data.util.ClassTypeInformation;
import org.springframework.data.util.TypeInformation;
public class SimplifiedTests {
@Test
void typeInformationMapIsNotNull() {
Object whatever = ClassTypeInformation.MAP;
assertThat(TypeInformation.MAP).isNotNull();
}
}
The test fails as TypeInformation.MAP is null. The test passes when Object whatever = ClassTypeInformation.MAP; is commented out. I think this is a bug in Spring Data Commons. As far as I can tell, to work as intended certain classes and interfaces have to be initialized in a particular order. If that order isn't used, constants on TypeInformation become null.
Please open a Spring Data Commons issue so that the Spring Data team can investigate.