Skip to content

Ensure indexer gracefully handle missing meta annotations #22385

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions spring-context-indexer/spring-context-indexer.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}
Original file line number Diff line number Diff line change
@@ -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.
Expand All @@ -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;
Expand Down Expand Up @@ -110,7 +111,12 @@ public List<Element> getDirectInterfaces(Element element) {
}

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();
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import javax.persistence.Embeddable;
import javax.persistence.Entity;
import javax.persistence.MappedSuperclass;
import javax.transaction.Transactional;

import org.junit.Before;
import org.junit.Rule;
Expand All @@ -44,6 +45,7 @@
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;
Expand All @@ -67,6 +69,7 @@
* Tests for {@link CandidateComponentsIndexer}.
*
* @author Stephane Nicoll
* @author Vedran Pavic
*/
public class CandidateComponentsIndexerTests {

Expand Down Expand Up @@ -142,6 +145,11 @@ public void cdiNamed() {
testSingleComponent(SampleNamed.class, Named.class);
}

@Test
public void cdiTransactional() {
testSingleComponent(SampleTransactional.class, Transactional.class);
}

@Test
public void persistenceEntity() {
testSingleComponent(SampleEntity.class, Entity.class);
Expand Down
Original file line number Diff line number Diff line change
@@ -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 {
}