GroovyBeanDefinitionReader consistently throws BeanDefinitionParsingException for invalid files of any name
Issue: SPR-12435
This commit is contained in:
parent
4bd75e4146
commit
b4167be52d
|
|
@ -53,6 +53,7 @@ import org.springframework.beans.factory.xml.XmlReaderContext;
|
|||
import org.springframework.core.io.DescriptiveResource;
|
||||
import org.springframework.core.io.Resource;
|
||||
import org.springframework.core.io.support.EncodedResource;
|
||||
import org.springframework.util.ObjectUtils;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
/**
|
||||
|
|
@ -239,7 +240,7 @@ public class GroovyBeanDefinitionReader extends AbstractBeanDefinitionReader imp
|
|||
int countBefore = getRegistry().getBeanDefinitionCount();
|
||||
try {
|
||||
GroovyShell shell = new GroovyShell(getResourceLoader().getClassLoader(), binding);
|
||||
shell.evaluate(encodedResource.getReader(), encodedResource.getResource().getFilename());
|
||||
shell.evaluate(encodedResource.getReader(), "beans");
|
||||
}
|
||||
catch (Throwable ex) {
|
||||
throw new BeanDefinitionParsingException(new Problem("Error evaluating Groovy script: " + ex.getMessage(),
|
||||
|
|
@ -282,10 +283,9 @@ public class GroovyBeanDefinitionReader extends AbstractBeanDefinitionReader imp
|
|||
try {
|
||||
Closure callable = null;
|
||||
Collection constructorArgs = null;
|
||||
if (args != null && args.length > 0) {
|
||||
if (!ObjectUtils.isEmpty(args)) {
|
||||
int index = args.length;
|
||||
Object lastArg = args[index-1];
|
||||
|
||||
if (lastArg instanceof Closure) {
|
||||
callable = (Closure) lastArg;
|
||||
index--;
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2002-2013 the original author or authors.
|
||||
* Copyright 2002-2014 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.
|
||||
|
|
@ -16,16 +16,20 @@
|
|||
|
||||
package org.springframework.context.groovy;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
import org.junit.Test;
|
||||
|
||||
import org.springframework.beans.factory.parsing.BeanDefinitionParsingException;
|
||||
import org.springframework.context.support.GenericGroovyApplicationContext;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
/**
|
||||
* @author Jeff Brown
|
||||
* @author Juergen Hoeller
|
||||
*/
|
||||
public class GroovyApplicationContextTests extends TestCase {
|
||||
public class GroovyApplicationContextTests {
|
||||
|
||||
@Test
|
||||
public void testLoadingConfigFile() {
|
||||
GenericGroovyApplicationContext ctx = new GenericGroovyApplicationContext(
|
||||
"org/springframework/context/groovy/applicationContext.groovy");
|
||||
|
|
@ -35,6 +39,7 @@ public class GroovyApplicationContextTests extends TestCase {
|
|||
assertEquals("Grails", framework);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testLoadingMultipleConfigFiles() {
|
||||
GenericGroovyApplicationContext ctx = new GenericGroovyApplicationContext(
|
||||
"org/springframework/context/groovy/applicationContext2.groovy",
|
||||
|
|
@ -49,6 +54,7 @@ public class GroovyApplicationContextTests extends TestCase {
|
|||
assertEquals("SpringSource", company);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testLoadingMultipleConfigFilesWithRelativeClass() {
|
||||
GenericGroovyApplicationContext ctx = new GenericGroovyApplicationContext();
|
||||
ctx.load(GroovyApplicationContextTests.class, "applicationContext2.groovy", "applicationContext.groovy");
|
||||
|
|
@ -63,4 +69,14 @@ public class GroovyApplicationContextTests extends TestCase {
|
|||
assertEquals("SpringSource", company);
|
||||
}
|
||||
|
||||
@Test(expected = BeanDefinitionParsingException.class)
|
||||
public void testConfigFileParsingError() {
|
||||
new GenericGroovyApplicationContext("org/springframework/context/groovy/applicationContext-error.groovy");
|
||||
}
|
||||
|
||||
@Test(expected = BeanDefinitionParsingException.class)
|
||||
public void testConfigFileParsingErrorWhenNamedBeans() {
|
||||
new GenericGroovyApplicationContext("org/springframework/context/groovy/beans.groovy");
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,6 @@
|
|||
package org.springframework.context.groovy
|
||||
|
||||
beans = {
|
||||
framework String, 'Grails'
|
||||
foo String, 'hello'
|
||||
}
|
||||
|
|
@ -0,0 +1,6 @@
|
|||
package org.springframework.context.groovy
|
||||
|
||||
beans = {
|
||||
framework String, 'Grails'
|
||||
foo String, 'hello'
|
||||
}
|
||||
Loading…
Reference in New Issue