pull/14801/head
Phillip Webb 6 years ago
parent bd482d7063
commit a085541d26

@ -149,6 +149,40 @@ final class BeanTypeRegistry implements SmartInitializingSingleton {
this.beanDefinitions.clear(); this.beanDefinitions.clear();
} }
private RootBeanDefinition getBeanDefinition(String name) {
try {
return (RootBeanDefinition) this.beanFactory.getMergedBeanDefinition(name);
}
catch (BeanDefinitionStoreException ex) {
logIgnoredError("unresolvable metadata in bean definition", name, ex);
return null;
}
}
private void logIgnoredError(String message, String name, Exception ex) {
if (BeanTypeRegistry.logger.isDebugEnabled()) {
BeanTypeRegistry.logger.debug("Ignoring " + message + " '" + name + "'", ex);
}
}
private boolean requiresEagerInit(String factoryBeanName) {
return (factoryBeanName != null && this.beanFactory.isFactoryBean(factoryBeanName)
&& !this.beanFactory.containsSingleton(factoryBeanName));
}
private void updateTypesIfNecessary() {
Iterator<String> names = this.beanFactory.getBeanNamesIterator();
while (names.hasNext()) {
String name = names.next();
if (!this.beanTypes.containsKey(name)) {
addBeanType(name);
}
else {
updateBeanType(name);
}
}
}
private void addBeanType(String name) { private void addBeanType(String name) {
if (this.beanFactory.containsSingleton(name)) { if (this.beanFactory.containsSingleton(name)) {
this.beanTypes.put(name, this.beanFactory.getType(name)); this.beanTypes.put(name, this.beanFactory.getType(name));
@ -165,13 +199,17 @@ final class BeanTypeRegistry implements SmartInitializingSingleton {
} }
} }
private RootBeanDefinition getBeanDefinition(String name) { private void updateBeanType(String name) {
try { if (this.beanFactory.isAlias(name) || this.beanFactory.containsSingleton(name)) {
return (RootBeanDefinition) this.beanFactory.getMergedBeanDefinition(name); return;
} }
catch (BeanDefinitionStoreException ex) { RootBeanDefinition beanDefinition = getBeanDefinition(name);
logIgnoredError("unresolvable metadata in bean definition", name, ex); if (beanDefinition == null) {
return null; return;
}
RootBeanDefinition previous = this.beanDefinitions.put(name, beanDefinition);
if (previous != null && !beanDefinition.equals(previous)) {
addBeanTypeForNonAliasDefinition(name, beanDefinition);
} }
} }
@ -200,41 +238,6 @@ final class BeanTypeRegistry implements SmartInitializingSingleton {
} }
} }
private void logIgnoredError(String message, String name, Exception ex) {
if (BeanTypeRegistry.logger.isDebugEnabled()) {
BeanTypeRegistry.logger.debug("Ignoring " + message + " '" + name + "'", ex);
}
}
private boolean requiresEagerInit(String factoryBeanName) {
return (factoryBeanName != null && this.beanFactory.isFactoryBean(factoryBeanName)
&& !this.beanFactory.containsSingleton(factoryBeanName));
}
private void updateTypesIfNecessary() {
Iterator<String> names = this.beanFactory.getBeanNamesIterator();
while (names.hasNext()) {
String name = names.next();
if (!this.beanTypes.containsKey(name)) {
addBeanType(name);
}
else {
if (!this.beanFactory.isAlias(name)
&& !this.beanFactory.containsSingleton(name)) {
RootBeanDefinition beanDefinition = getBeanDefinition(name);
if (beanDefinition != null) {
RootBeanDefinition existingDefinition = this.beanDefinitions
.put(name, beanDefinition);
if (existingDefinition != null
&& !beanDefinition.equals(existingDefinition)) {
addBeanTypeForNonAliasDefinition(name, beanDefinition);
}
}
}
}
}
}
/** /**
* Attempt to guess the type that a {@link FactoryBean} will return based on the * Attempt to guess the type that a {@link FactoryBean} will return based on the
* generics in its method signature. * generics in its method signature.

@ -347,7 +347,6 @@ public class ConditionalOnBeanTests {
public static class ConsumingConfiguration { public static class ConsumingConfiguration {
ConsumingConfiguration(String testBean) { ConsumingConfiguration(String testBean) {
} }
} }

@ -214,8 +214,8 @@ public class RestartClassLoaderTests {
} }
private <T> List<T> toList(Enumeration<T> enumeration) { private <T> List<T> toList(Enumeration<T> enumeration) {
return ((enumeration != null) ? Collections.list(enumeration) return (enumeration != null) ? Collections.list(enumeration)
: Collections.<T>emptyList()); : Collections.<T>emptyList();
} }
} }

@ -30,19 +30,16 @@ import java.util.zip.InflaterInputStream;
*/ */
class ZipInflaterInputStream extends InflaterInputStream { class ZipInflaterInputStream extends InflaterInputStream {
private final Inflater inflater; private int available;
private boolean extraBytesWritten; private boolean extraBytesWritten;
private int available;
ZipInflaterInputStream(InputStream inputStream, int size) { ZipInflaterInputStream(InputStream inputStream, int size) {
this(inputStream, new Inflater(true), size); this(inputStream, new Inflater(true), size);
} }
private ZipInflaterInputStream(InputStream inputStream, Inflater inflater, int size) { private ZipInflaterInputStream(InputStream inputStream, Inflater inflater, int size) {
super(inputStream, inflater, getInflaterBufferSize(size)); super(inputStream, new Inflater(true), getInflaterBufferSize(size));
this.inflater = inflater;
this.available = size; this.available = size;
} }
@ -66,7 +63,7 @@ class ZipInflaterInputStream extends InflaterInputStream {
@Override @Override
public void close() throws IOException { public void close() throws IOException {
super.close(); super.close();
this.inflater.end(); this.inf.end();
} }
@Override @Override

@ -450,8 +450,8 @@ public class UndertowEmbeddedServletContainerFactory
private AccessLogHandler createAccessLogHandler(HttpHandler handler, private AccessLogHandler createAccessLogHandler(HttpHandler handler,
AccessLogReceiver accessLogReceiver) { AccessLogReceiver accessLogReceiver) {
createAccessLogDirectoryIfNecessary(); createAccessLogDirectoryIfNecessary();
String formatString = ((this.accessLogPattern != null) ? this.accessLogPattern String formatString = (this.accessLogPattern != null) ? this.accessLogPattern
: "common"); : "common";
return new AccessLogHandler(handler, accessLogReceiver, formatString, return new AccessLogHandler(handler, accessLogReceiver, formatString,
Undertow.class.getClassLoader()); Undertow.class.getClassLoader());
} }

@ -48,24 +48,8 @@ class NoSuchMethodFailureAnalyzer extends AbstractFailureAnalyzer<NoSuchMethodEr
if (actual == null) { if (actual == null) {
return null; return null;
} }
StringWriter description = new StringWriter(); String description = getDescription(cause, className, candidates, actual);
PrintWriter writer = new PrintWriter(description); return new FailureAnalysis(description,
writer.print("An attempt was made to call the method ");
writer.print(cause.getMessage());
writer.print(" but it does not exist. Its class, ");
writer.print(className);
writer.println(", is available from the following locations:");
writer.println();
for (URL candidate : candidates) {
writer.print(" ");
writer.println(candidate);
}
writer.println();
writer.println("It was loaded from the following location:");
writer.println();
writer.print(" ");
writer.println(actual);
return new FailureAnalysis(description.toString(),
"Correct the classpath of your application so that it contains a single," "Correct the classpath of your application so that it contains a single,"
+ " compatible version of " + className, + " compatible version of " + className,
cause); cause);
@ -105,4 +89,26 @@ class NoSuchMethodFailureAnalyzer extends AbstractFailureAnalyzer<NoSuchMethodEr
} }
} }
private String getDescription(NoSuchMethodError cause, String className,
List<URL> candidates, URL actual) {
StringWriter description = new StringWriter();
PrintWriter writer = new PrintWriter(description);
writer.print("An attempt was made to call the method ");
writer.print(cause.getMessage());
writer.print(" but it does not exist. Its class, ");
writer.print(className);
writer.println(", is available from the following locations:");
writer.println();
for (URL candidate : candidates) {
writer.print(" ");
writer.println(candidate);
}
writer.println();
writer.println("It was loaded from the following location:");
writer.println();
writer.print(" ");
writer.println(actual);
return description.toString();
}
} }

@ -195,7 +195,6 @@ public abstract class SpringBootServletInitializer implements WebApplicationInit
((ConfigurableWebEnvironment) environment) ((ConfigurableWebEnvironment) environment)
.initPropertySources(this.servletContext, null); .initPropertySources(this.servletContext, null);
} }
} }
@Override @Override

@ -383,14 +383,14 @@ public class JettyEmbeddedServletContainerFactoryTests
contexts.iterator().next().addEventListener(new ServletContextListener() { contexts.iterator().next().addEventListener(new ServletContextListener() {
@Override @Override
public void contextInitialized(ServletContextEvent sce) { public void contextInitialized(ServletContextEvent event) {
throw new RuntimeException(); throw new RuntimeException();
} }
@Override @Override
public void contextDestroyed(ServletContextEvent sce) { public void contextDestroyed(ServletContextEvent event) {
} }
}); });
} }

@ -30,7 +30,9 @@ import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.Mockito.mock; import static org.mockito.Mockito.mock;
/** /**
* @author awilkinson * Tests for {@link NoSuchMethodFailureAnalyzer}.
*
* @author Andy Wilkinson
*/ */
@RunWith(ModifiedClassPathRunner.class) @RunWith(ModifiedClassPathRunner.class)
@ClassPathOverrides("javax.servlet:servlet-api:2.5") @ClassPathOverrides("javax.servlet:servlet-api:2.5")

Loading…
Cancel
Save