Skip to content

AnnotationsPropertySource can throw a NPE when javax meta-annotations are present #15175

Closed
@yanavasileva

Description

@yanavasileva

Hello,

We are trying to adopt Spring Boot 2.1 (currently we are on 2.0.2) but we face issues.
Here is an example:

@RunWith(SpringRunner.class)
@SpringBootTest(classes = { TestApplication.class }, webEnvironment = WebEnvironment.NONE)
@Transactional
public class SampleIT {

  @Autowired
  private TestEntityRepository testEntityRepository;

  @Autowired
  private TransactionalTestService transactionalTestService;

  ...
}

Here is the stacktrace:

java.lang.NullPointerException: null
        at org.springframework.boot.test.autoconfigure.properties.AnnotationsPropertySource.collectProperties(AnnotationsPropertySource.java:73)
        at org.springframework.boot.test.autoconfigure.properties.AnnotationsPropertySource.collectProperties(AnnotationsPropertySource.java:79)
        at org.springframework.boot.test.autoconfigure.properties.AnnotationsPropertySource.getProperties(AnnotationsPropertySource.java:64)
        at org.springframework.boot.test.autoconfigure.properties.AnnotationsPropertySource.<init>(AnnotationsPropertySource.java:59)
        at org.springframework.boot.test.autoconfigure.properties.AnnotationsPropertySource.<init>(AnnotationsPropertySource.java:54)
        at org.springframework.boot.test.autoconfigure.properties.PropertyMappingContextCustomizerFactory.createContextCustomizer(PropertyMappingContextCustomizerFactory.java:37)
        at org.springframework.test.context.support.AbstractTestContextBootstrapper.getContextCustomizers(AbstractTestContextBootstrapper.java:404)
        at org.springframework.test.context.support.AbstractTestContextBootstrapper.buildMergedContextConfiguration(AbstractTestContextBootstrapper.java:376)
        at org.springframework.test.context.support.AbstractTestContextBootstrapper.buildDefaultMergedContextConfiguration(AbstractTestContextBootstrapper.java:312)
        at org.springframework.test.context.support.AbstractTestContextBootstrapper.buildMergedContextConfiguration(AbstractTestContextBootstrapper.java:265)
        at org.springframework.test.context.support.AbstractTestContextBootstrapper.buildTestContext(AbstractTestContextBootstrapper.java:108)
        at org.springframework.boot.test.context.SpringBootTestContextBootstrapper.buildTestContext(SpringBootTestContextBootstrapper.java:99)
        at org.springframework.test.context.TestContextManager.<init>(TestContextManager.java:139)
        at org.springframework.test.context.TestContextManager.<init>(TestContextManager.java:124)
        at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.createTestContextManager(SpringJUnit4ClassRunner.java:151)
        at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.<init>(SpringJUnit4ClassRunner.java:142)
        at org.springframework.test.context.junit4.SpringRunner.<init>(SpringRunner.java:49)
        at sun.reflect.GeneratedConstructorAccessor56.newInstance(Unknown Source)
        at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
        at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
        at org.junit.internal.builders.AnnotatedBuilder.buildRunner(AnnotatedBuilder.java:104)
        at org.junit.internal.builders.AnnotatedBuilder.runnerForClass(AnnotatedBuilder.java:86)
        at org.junit.runners.model.RunnerBuilder.safeRunnerForClass(RunnerBuilder.java:59)
        at org.junit.internal.builders.AllDefaultPossibilitiesBuilder.runnerForClass(AllDefaultPossibilitiesBuilder.java:26)
        at org.junit.runners.model.RunnerBuilder.safeRunnerForClass(RunnerBuilder.java:59)
        at org.junit.internal.requests.ClassRequest.getRunner(ClassRequest.java:33)
        at org.apache.maven.surefire.junit4.JUnit4Provider.execute(JUnit4Provider.java:283)
        at org.apache.maven.surefire.junit4.JUnit4Provider.executeWithRerun(JUnit4Provider.java:173)
        at org.apache.maven.surefire.junit4.JUnit4Provider.executeTestSet(JUnit4Provider.java:153)
        at org.apache.maven.surefire.junit4.JUnit4Provider.invoke(JUnit4Provider.java:128)
        at org.apache.maven.surefire.booter.ForkedBooter.invokeProviderInSameClassLoader(ForkedBooter.java:203)
        at org.apache.maven.surefire.booter.ForkedBooter.runSuitesInProcess(ForkedBooter.java:155)
        at org.apache.maven.surefire.booter.ForkedBooter.main(ForkedBooter.java:103)

The problem occurs during because mergedAnnotations return [null] for the Transactional annotation.
Have you seen similar problem before? Do you need more input?

Best regards,
Yana

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions