Skip to content

Commit 092b3d4

Browse files
committed
Warning instead of error for non-present type filter class
Issue: SPR-16356 (cherry picked from commit 4adc820)
1 parent bf4cada commit 092b3d4

File tree

3 files changed

+35
-35
lines changed

3 files changed

+35
-35
lines changed

spring-beans/src/test/java/org/springframework/beans/factory/parsing/CustomProblemReporterTests.java

+4-5
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2013 the original author or authors.
2+
* Copyright 2002-2018 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.
@@ -35,7 +35,7 @@
3535
* @author Chris Beams
3636
* @since 2.0
3737
*/
38-
public final class CustomProblemReporterTests {
38+
public class CustomProblemReporterTests {
3939

4040
private static final Resource CONTEXT = qualifiedResource(CustomProblemReporterTests.class, "context.xml");
4141

@@ -66,10 +66,9 @@ public void testErrorsAreCollated() {
6666

6767
private static class CollatingProblemReporter implements ProblemReporter {
6868

69-
private List<Problem> errors = new ArrayList<Problem>();
70-
71-
private List<Problem> warnings = new ArrayList<Problem>();
69+
private final List<Problem> errors = new ArrayList<>();
7270

71+
private final List<Problem> warnings = new ArrayList<>();
7372

7473
@Override
7574
public void fatal(Problem problem) {

spring-context/src/main/java/org/springframework/context/annotation/ComponentScanBeanDefinitionParser.java

+29-28
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2016 the original author or authors.
2+
* Copyright 2002-2018 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.
@@ -25,7 +25,6 @@
2525
import org.w3c.dom.NodeList;
2626

2727
import org.springframework.beans.BeanUtils;
28-
import org.springframework.beans.FatalBeanException;
2928
import org.springframework.beans.factory.config.BeanDefinition;
3029
import org.springframework.beans.factory.config.BeanDefinitionHolder;
3130
import org.springframework.beans.factory.parsing.BeanComponentDefinition;
@@ -40,6 +39,7 @@
4039
import org.springframework.core.type.filter.AssignableTypeFilter;
4140
import org.springframework.core.type.filter.RegexPatternTypeFilter;
4241
import org.springframework.core.type.filter.TypeFilter;
42+
import org.springframework.util.ClassUtils;
4343
import org.springframework.util.StringUtils;
4444

4545
/**
@@ -212,6 +212,10 @@ else if (EXCLUDE_FILTER_ELEMENT.equals(localName)) {
212212
scanner.addExcludeFilter(typeFilter);
213213
}
214214
}
215+
catch (ClassNotFoundException ex) {
216+
parserContext.getReaderContext().warning(
217+
"Ignoring non-present type filter class: " + ex, parserContext.extractSource(element));
218+
}
215219
catch (Exception ex) {
216220
parserContext.getReaderContext().error(
217221
ex.getMessage(), parserContext.extractSource(element), ex.getCause());
@@ -221,37 +225,34 @@ else if (EXCLUDE_FILTER_ELEMENT.equals(localName)) {
221225
}
222226

223227
@SuppressWarnings("unchecked")
224-
protected TypeFilter createTypeFilter(Element element, ClassLoader classLoader, ParserContext parserContext) {
228+
protected TypeFilter createTypeFilter(Element element, ClassLoader classLoader,
229+
ParserContext parserContext) throws ClassNotFoundException {
230+
225231
String filterType = element.getAttribute(FILTER_TYPE_ATTRIBUTE);
226232
String expression = element.getAttribute(FILTER_EXPRESSION_ATTRIBUTE);
227233
expression = parserContext.getReaderContext().getEnvironment().resolvePlaceholders(expression);
228-
try {
229-
if ("annotation".equals(filterType)) {
230-
return new AnnotationTypeFilter((Class<Annotation>) classLoader.loadClass(expression));
231-
}
232-
else if ("assignable".equals(filterType)) {
233-
return new AssignableTypeFilter(classLoader.loadClass(expression));
234-
}
235-
else if ("aspectj".equals(filterType)) {
236-
return new AspectJTypeFilter(expression, classLoader);
237-
}
238-
else if ("regex".equals(filterType)) {
239-
return new RegexPatternTypeFilter(Pattern.compile(expression));
240-
}
241-
else if ("custom".equals(filterType)) {
242-
Class<?> filterClass = classLoader.loadClass(expression);
243-
if (!TypeFilter.class.isAssignableFrom(filterClass)) {
244-
throw new IllegalArgumentException(
245-
"Class is not assignable to [" + TypeFilter.class.getName() + "]: " + expression);
246-
}
247-
return (TypeFilter) BeanUtils.instantiateClass(filterClass);
248-
}
249-
else {
250-
throw new IllegalArgumentException("Unsupported filter type: " + filterType);
234+
if ("annotation".equals(filterType)) {
235+
return new AnnotationTypeFilter((Class<Annotation>) ClassUtils.forName(expression, classLoader));
236+
}
237+
else if ("assignable".equals(filterType)) {
238+
return new AssignableTypeFilter(ClassUtils.forName(expression, classLoader));
239+
}
240+
else if ("aspectj".equals(filterType)) {
241+
return new AspectJTypeFilter(expression, classLoader);
242+
}
243+
else if ("regex".equals(filterType)) {
244+
return new RegexPatternTypeFilter(Pattern.compile(expression));
245+
}
246+
else if ("custom".equals(filterType)) {
247+
Class<?> filterClass = ClassUtils.forName(expression, classLoader);
248+
if (!TypeFilter.class.isAssignableFrom(filterClass)) {
249+
throw new IllegalArgumentException(
250+
"Class is not assignable to [" + TypeFilter.class.getName() + "]: " + expression);
251251
}
252+
return (TypeFilter) BeanUtils.instantiateClass(filterClass);
252253
}
253-
catch (ClassNotFoundException ex) {
254-
throw new FatalBeanException("Type filter class not found: " + expression, ex);
254+
else {
255+
throw new IllegalArgumentException("Unsupported filter type: " + filterType);
255256
}
256257
}
257258

spring-jms/src/main/java/org/springframework/jms/config/JmsListenerContainerParser.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2014 the original author or authors.
2+
* Copyright 2002-2018 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.
@@ -150,7 +150,7 @@ protected MutablePropertyValues parseSpecificContainerProperties(Element contain
150150
if (!("auto".equals(cache) || "consumer".equals(cache))) {
151151
parserContext.getReaderContext().warning(
152152
"'cache' attribute not actively supported for listener container of type \"simple\". " +
153-
"Effective runtime behavior will be equivalent to \"consumer\" / \"auto\".", containerEle);
153+
"Effective runtime behavior will be equivalent to \"consumer\" / \"auto\".", containerEle);
154154
}
155155
}
156156
else {

0 commit comments

Comments
 (0)