Skip to content

Commit 87e5f0d

Browse files
vpavicsnicoll
authored andcommitted
Ensure indexer gracefully handle missing meta annotations
See gh-22385
1 parent 566cc87 commit 87e5f0d

File tree

4 files changed

+45
-2
lines changed

4 files changed

+45
-2
lines changed

spring-context-indexer/spring-context-indexer.gradle

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,6 @@ dependencies {
44
testCompile(project(":spring-context"))
55
testCompile("javax.inject:javax.inject:1")
66
testCompile("javax.annotation:javax.annotation-api:1.3.2")
7+
testCompile("javax.transaction:javax.transaction-api:1.3")
78
testCompile("org.eclipse.persistence:javax.persistence:2.2.0")
89
}

spring-context-indexer/src/main/java/org/springframework/context/index/processor/TypeHelper.java

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2018 the original author or authors.
2+
* Copyright 2002-2019 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -17,6 +17,7 @@
1717
package org.springframework.context.index.processor;
1818

1919
import java.util.ArrayList;
20+
import java.util.Collections;
2021
import java.util.List;
2122
import javax.annotation.processing.ProcessingEnvironment;
2223
import javax.lang.model.element.AnnotationMirror;
@@ -110,7 +111,12 @@ public List<Element> getDirectInterfaces(Element element) {
110111
}
111112

112113
public List<? extends AnnotationMirror> getAllAnnotationMirrors(Element e) {
113-
return this.env.getElementUtils().getAllAnnotationMirrors(e);
114+
try {
115+
return this.env.getElementUtils().getAllAnnotationMirrors(e);
116+
}
117+
catch (Throwable ex) {
118+
return Collections.emptyList();
119+
}
114120
}
115121

116122
}

spring-context-indexer/src/test/java/org/springframework/context/index/processor/CandidateComponentsIndexerTests.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
import javax.persistence.Embeddable;
2626
import javax.persistence.Entity;
2727
import javax.persistence.MappedSuperclass;
28+
import javax.transaction.Transactional;
2829

2930
import org.junit.Before;
3031
import org.junit.Rule;
@@ -44,6 +45,7 @@
4445
import org.springframework.context.index.sample.SampleService;
4546
import org.springframework.context.index.sample.cdi.SampleManagedBean;
4647
import org.springframework.context.index.sample.cdi.SampleNamed;
48+
import org.springframework.context.index.sample.cdi.SampleTransactional;
4749
import org.springframework.context.index.sample.jpa.SampleConverter;
4850
import org.springframework.context.index.sample.jpa.SampleEmbeddable;
4951
import org.springframework.context.index.sample.SampleEmbedded;
@@ -67,6 +69,7 @@
6769
* Tests for {@link CandidateComponentsIndexer}.
6870
*
6971
* @author Stephane Nicoll
72+
* @author Vedran Pavic
7073
*/
7174
public class CandidateComponentsIndexerTests {
7275

@@ -142,6 +145,11 @@ public void cdiNamed() {
142145
testSingleComponent(SampleNamed.class, Named.class);
143146
}
144147

148+
@Test
149+
public void cdiTransactional() {
150+
testSingleComponent(SampleTransactional.class, Transactional.class);
151+
}
152+
145153
@Test
146154
public void persistenceEntity() {
147155
testSingleComponent(SampleEntity.class, Entity.class);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
/*
2+
* Copyright 2002-2019 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package org.springframework.context.index.sample.cdi;
18+
19+
import javax.transaction.Transactional;
20+
21+
/**
22+
* Test candidate for {@link Transactional}.
23+
*
24+
* @author Vedran Pavic
25+
*/
26+
@Transactional
27+
public class SampleTransactional {
28+
}

0 commit comments

Comments
 (0)