Skip to content

Commit

Permalink
Stop referring to optional classes in BeanDefinitionLoader’s signature
Browse files Browse the repository at this point in the history
Previously, BeanDefinitionLoader declared a field of type
GroovyBeanDefinitionReader which is a GroovyObject subclass. This is
problematic as BeanDefinitionLoader is always loaded but Groovy is an
optional dependency. Even on a JVM where class verification is performed
lazily, this can still cause problems if something reflectively tries
to access the class’s declared fields. On a JVM where classes are
verified at load time, it would be impossible to start a Spring Boot
application without having Groovy on the classpath.

This commit changes the field to be a BeanDefinitionReader, removing
the indirect reference to GroovyObject form BeanDefinitionLoader’s
signature. The reader is downcast to a GroovyBeanDefinitionReader in the
body of a method body that will only be invoked when Groovy is on the
classpath.

Closes spring-projectsgh-5040
  • Loading branch information
wilkinsona committed Feb 4, 2016
1 parent 43a5b77 commit c0a2c88
Showing 1 changed file with 4 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2012-2015 the original author or authors.
* Copyright 2012-2016 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 @@ -25,6 +25,7 @@
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.BeanDefinitionStoreException;
import org.springframework.beans.factory.groovy.GroovyBeanDefinitionReader;
import org.springframework.beans.factory.support.BeanDefinitionReader;
import org.springframework.beans.factory.support.BeanDefinitionRegistry;
import org.springframework.beans.factory.support.BeanNameGenerator;
import org.springframework.beans.factory.xml.XmlBeanDefinitionReader;
Expand Down Expand Up @@ -60,7 +61,7 @@ class BeanDefinitionLoader {

private final XmlBeanDefinitionReader xmlReader;

private GroovyBeanDefinitionReader groovyReader;
private BeanDefinitionReader groovyReader;

private final ClassPathBeanDefinitionScanner scanner;

Expand Down Expand Up @@ -162,7 +163,7 @@ private int load(Class<?> source) {

private int load(GroovyBeanDefinitionSource source) {
int before = this.xmlReader.getRegistry().getBeanDefinitionCount();
this.groovyReader.beans(source.getBeans());
((GroovyBeanDefinitionReader) this.groovyReader).beans(source.getBeans());
int after = this.xmlReader.getRegistry().getBeanDefinitionCount();
return after - before;
}
Expand Down

0 comments on commit c0a2c88

Please sign in to comment.