Ensure indexer gracefully handle missing meta annotations

See gh-22385
master
Vedran Pavic 6 years ago committed by Stephane Nicoll
parent 566cc87748
commit 87e5f0db01
  1. 1
      spring-context-indexer/spring-context-indexer.gradle
  2. 10
      spring-context-indexer/src/main/java/org/springframework/context/index/processor/TypeHelper.java
  3. 8
      spring-context-indexer/src/test/java/org/springframework/context/index/processor/CandidateComponentsIndexerTests.java
  4. 28
      spring-context-indexer/src/test/java/org/springframework/context/index/sample/cdi/SampleTransactional.java

@ -4,5 +4,6 @@ dependencies {
testCompile(project(":spring-context"))
testCompile("javax.inject:javax.inject:1")
testCompile("javax.annotation:javax.annotation-api:1.3.2")
testCompile("javax.transaction:javax.transaction-api:1.3")
testCompile("org.eclipse.persistence:javax.persistence:2.2.0")
}

@ -1,5 +1,5 @@
/*
* Copyright 2002-2018 the original author or authors.
* Copyright 2002-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -17,6 +17,7 @@
package org.springframework.context.index.processor;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import javax.annotation.processing.ProcessingEnvironment;
import javax.lang.model.element.AnnotationMirror;
@ -110,7 +111,12 @@ class TypeHelper {
}
public List<? extends AnnotationMirror> getAllAnnotationMirrors(Element e) {
return this.env.getElementUtils().getAllAnnotationMirrors(e);
try {
return this.env.getElementUtils().getAllAnnotationMirrors(e);
}
catch (Throwable ex) {
return Collections.emptyList();
}
}
}

@ -25,6 +25,7 @@ import javax.persistence.Converter;
import javax.persistence.Embeddable;
import javax.persistence.Entity;
import javax.persistence.MappedSuperclass;
import javax.transaction.Transactional;
import org.junit.Before;
import org.junit.Rule;
@ -44,6 +45,7 @@ import org.springframework.context.index.sample.SampleRepository;
import org.springframework.context.index.sample.SampleService;
import org.springframework.context.index.sample.cdi.SampleManagedBean;
import org.springframework.context.index.sample.cdi.SampleNamed;
import org.springframework.context.index.sample.cdi.SampleTransactional;
import org.springframework.context.index.sample.jpa.SampleConverter;
import org.springframework.context.index.sample.jpa.SampleEmbeddable;
import org.springframework.context.index.sample.SampleEmbedded;
@ -67,6 +69,7 @@ import static org.springframework.context.index.processor.Metadata.*;
* Tests for {@link CandidateComponentsIndexer}.
*
* @author Stephane Nicoll
* @author Vedran Pavic
*/
public class CandidateComponentsIndexerTests {
@ -142,6 +145,11 @@ public class CandidateComponentsIndexerTests {
testSingleComponent(SampleNamed.class, Named.class);
}
@Test
public void cdiTransactional() {
testSingleComponent(SampleTransactional.class, Transactional.class);
}
@Test
public void persistenceEntity() {
testSingleComponent(SampleEntity.class, Entity.class);

@ -0,0 +1,28 @@
/*
* Copyright 2002-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.context.index.sample.cdi;
import javax.transaction.Transactional;
/**
* Test candidate for {@link Transactional}.
*
* @author Vedran Pavic
*/
@Transactional
public class SampleTransactional {
}
Loading…
Cancel
Save