Skip to content

Commit 4adc820

Browse files
committed
Warning instead of error for non-present type filter class
Issue: SPR-16356
1 parent 0d151b0 commit 4adc820

File tree

3 files changed

+32
-35
lines changed

3 files changed

+32
-35
lines changed

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

Lines changed: 3 additions & 4 deletions
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.
@@ -66,10 +66,9 @@ public void testErrorsAreCollated() {
6666

6767
private static class CollatingProblemReporter implements ProblemReporter {
6868

69-
private List<Problem> errors = new ArrayList<>();
70-
71-
private List<Problem> warnings = new ArrayList<>();
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

Lines changed: 27 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2017 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;
@@ -216,6 +215,10 @@ else if (EXCLUDE_FILTER_ELEMENT.equals(localName)) {
216215
scanner.addExcludeFilter(typeFilter);
217216
}
218217
}
218+
catch (ClassNotFoundException ex) {
219+
parserContext.getReaderContext().warning(
220+
"Ignoring non-present type filter class: " + ex, parserContext.extractSource(element));
221+
}
219222
catch (Exception ex) {
220223
parserContext.getReaderContext().error(
221224
ex.getMessage(), parserContext.extractSource(element), ex.getCause());
@@ -225,39 +228,34 @@ else if (EXCLUDE_FILTER_ELEMENT.equals(localName)) {
225228
}
226229

227230
@SuppressWarnings("unchecked")
228-
protected TypeFilter createTypeFilter(
229-
Element element, @Nullable ClassLoader classLoader, ParserContext parserContext) {
231+
protected TypeFilter createTypeFilter(Element element, @Nullable ClassLoader classLoader,
232+
ParserContext parserContext) throws ClassNotFoundException {
230233

231234
String filterType = element.getAttribute(FILTER_TYPE_ATTRIBUTE);
232235
String expression = element.getAttribute(FILTER_EXPRESSION_ATTRIBUTE);
233236
expression = parserContext.getReaderContext().getEnvironment().resolvePlaceholders(expression);
234-
try {
235-
if ("annotation".equals(filterType)) {
236-
return new AnnotationTypeFilter((Class<Annotation>) ClassUtils.forName(expression, classLoader));
237-
}
238-
else if ("assignable".equals(filterType)) {
239-
return new AssignableTypeFilter(ClassUtils.forName(expression, classLoader));
240-
}
241-
else if ("aspectj".equals(filterType)) {
242-
return new AspectJTypeFilter(expression, classLoader);
243-
}
244-
else if ("regex".equals(filterType)) {
245-
return new RegexPatternTypeFilter(Pattern.compile(expression));
246-
}
247-
else if ("custom".equals(filterType)) {
248-
Class<?> filterClass = ClassUtils.forName(expression, classLoader);
249-
if (!TypeFilter.class.isAssignableFrom(filterClass)) {
250-
throw new IllegalArgumentException(
251-
"Class is not assignable to [" + TypeFilter.class.getName() + "]: " + expression);
252-
}
253-
return (TypeFilter) BeanUtils.instantiateClass(filterClass);
254-
}
255-
else {
256-
throw new IllegalArgumentException("Unsupported filter type: " + filterType);
237+
if ("annotation".equals(filterType)) {
238+
return new AnnotationTypeFilter((Class<Annotation>) ClassUtils.forName(expression, classLoader));
239+
}
240+
else if ("assignable".equals(filterType)) {
241+
return new AssignableTypeFilter(ClassUtils.forName(expression, classLoader));
242+
}
243+
else if ("aspectj".equals(filterType)) {
244+
return new AspectJTypeFilter(expression, classLoader);
245+
}
246+
else if ("regex".equals(filterType)) {
247+
return new RegexPatternTypeFilter(Pattern.compile(expression));
248+
}
249+
else if ("custom".equals(filterType)) {
250+
Class<?> filterClass = ClassUtils.forName(expression, classLoader);
251+
if (!TypeFilter.class.isAssignableFrom(filterClass)) {
252+
throw new IllegalArgumentException(
253+
"Class is not assignable to [" + TypeFilter.class.getName() + "]: " + expression);
257254
}
255+
return (TypeFilter) BeanUtils.instantiateClass(filterClass);
258256
}
259-
catch (ClassNotFoundException ex) {
260-
throw new FatalBeanException("Type filter class not found: " + expression, ex);
257+
else {
258+
throw new IllegalArgumentException("Unsupported filter type: " + filterType);
261259
}
262260
}
263261

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

Lines changed: 2 additions & 2 deletions
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)