Skip to content

Commit d611486

Browse files
committed
HandlerMappingIntrospector.getHandlerMappings() never returns null
1 parent 2e0a284 commit d611486

File tree

1 file changed

+42
-41
lines changed

1 file changed

+42
-41
lines changed

spring-webmvc/src/main/java/org/springframework/web/servlet/handler/HandlerMappingIntrospector.java

Lines changed: 42 additions & 41 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-2017 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.
@@ -90,7 +90,7 @@ public HandlerMappingIntrospector(ApplicationContext context) {
9090
* Return the configured HandlerMapping's.
9191
*/
9292
public List<HandlerMapping> getHandlerMappings() {
93-
return this.handlerMappings;
93+
return (this.handlerMappings != null ? this.handlerMappings : Collections.emptyList());
9494
}
9595

9696

@@ -107,44 +107,6 @@ public void afterPropertiesSet() {
107107
}
108108
}
109109

110-
private static List<HandlerMapping> initHandlerMappings(ApplicationContext applicationContext) {
111-
Map<String, HandlerMapping> beans = BeanFactoryUtils.beansOfTypeIncludingAncestors(
112-
applicationContext, HandlerMapping.class, true, false);
113-
if (!beans.isEmpty()) {
114-
List<HandlerMapping> mappings = new ArrayList<>(beans.values());
115-
AnnotationAwareOrderComparator.sort(mappings);
116-
return Collections.unmodifiableList(mappings);
117-
}
118-
return Collections.unmodifiableList(initFallback(applicationContext));
119-
}
120-
121-
private static List<HandlerMapping> initFallback(ApplicationContext applicationContext) {
122-
Properties props;
123-
String path = "DispatcherServlet.properties";
124-
try {
125-
Resource resource = new ClassPathResource(path, DispatcherServlet.class);
126-
props = PropertiesLoaderUtils.loadProperties(resource);
127-
}
128-
catch (IOException ex) {
129-
throw new IllegalStateException("Could not load '" + path + "': " + ex.getMessage());
130-
}
131-
132-
String value = props.getProperty(HandlerMapping.class.getName());
133-
String[] names = StringUtils.commaDelimitedListToStringArray(value);
134-
List<HandlerMapping> result = new ArrayList<>(names.length);
135-
for (String name : names) {
136-
try {
137-
Class<?> clazz = ClassUtils.forName(name, DispatcherServlet.class.getClassLoader());
138-
Object mapping = applicationContext.getAutowireCapableBeanFactory().createBean(clazz);
139-
result.add((HandlerMapping) mapping);
140-
}
141-
catch (ClassNotFoundException ex) {
142-
throw new IllegalStateException("Could not find default HandlerMapping [" + name + "]");
143-
}
144-
}
145-
return result;
146-
}
147-
148110

149111
/**
150112
* Find the {@link HandlerMapping} that would handle the given request and
@@ -204,6 +166,45 @@ public CorsConfiguration getCorsConfiguration(HttpServletRequest request) {
204166
}
205167

206168

169+
private static List<HandlerMapping> initHandlerMappings(ApplicationContext applicationContext) {
170+
Map<String, HandlerMapping> beans = BeanFactoryUtils.beansOfTypeIncludingAncestors(
171+
applicationContext, HandlerMapping.class, true, false);
172+
if (!beans.isEmpty()) {
173+
List<HandlerMapping> mappings = new ArrayList<>(beans.values());
174+
AnnotationAwareOrderComparator.sort(mappings);
175+
return Collections.unmodifiableList(mappings);
176+
}
177+
return Collections.unmodifiableList(initFallback(applicationContext));
178+
}
179+
180+
private static List<HandlerMapping> initFallback(ApplicationContext applicationContext) {
181+
Properties props;
182+
String path = "DispatcherServlet.properties";
183+
try {
184+
Resource resource = new ClassPathResource(path, DispatcherServlet.class);
185+
props = PropertiesLoaderUtils.loadProperties(resource);
186+
}
187+
catch (IOException ex) {
188+
throw new IllegalStateException("Could not load '" + path + "': " + ex.getMessage());
189+
}
190+
191+
String value = props.getProperty(HandlerMapping.class.getName());
192+
String[] names = StringUtils.commaDelimitedListToStringArray(value);
193+
List<HandlerMapping> result = new ArrayList<>(names.length);
194+
for (String name : names) {
195+
try {
196+
Class<?> clazz = ClassUtils.forName(name, DispatcherServlet.class.getClassLoader());
197+
Object mapping = applicationContext.getAutowireCapableBeanFactory().createBean(clazz);
198+
result.add((HandlerMapping) mapping);
199+
}
200+
catch (ClassNotFoundException ex) {
201+
throw new IllegalStateException("Could not find default HandlerMapping [" + name + "]");
202+
}
203+
}
204+
return result;
205+
}
206+
207+
207208
/**
208209
* Request wrapper that ignores request attribute changes.
209210
*/
@@ -215,7 +216,7 @@ public RequestAttributeChangeIgnoringWrapper(HttpServletRequest request) {
215216

216217
@Override
217218
public void setAttribute(String name, Object value) {
218-
// Ignore attribute change
219+
// Ignore attribute change...
219220
}
220221
}
221222

0 commit comments

Comments
 (0)