Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SpEL method invocation with varargs on proxy [SPR-16122] #20670

Closed
spring-projects-issues opened this issue Oct 26, 2017 · 1 comment
Closed
Assignees
Labels
in: core Issues in core modules (aop, beans, core, context, expression) status: backported An issue that has been backported to maintenance branches type: bug A general bug
Milestone

Comments

@spring-projects-issues
Copy link
Collaborator

spring-projects-issues commented Oct 26, 2017

Gary Russell opened SPR-16122 and commented

SpEL method invocation on a proxy does not work with varargs.

Consider the following:

@SpringBootApplication
public class So46953884Application extends GlobalAuthenticationConfigurerAdapter {

	public static void main(String[] args) {
		SpringApplication.run(So46953884Application.class, args);
	}

	@Value("#{foo.foo('a', 'b')}")
	private String fooValue;

//	@Value("#{fooProxy.foo('c', 'd')}")
	private String fooProxyValue;

	@Autowired
	private Foo foo;

	@Autowired
	private Foo fooProxy;

	@Bean
	public ApplicationRunner runner() {
		return args -> {
			System.out.println(fooValue);
			System.out.println(foo.getClass());
			System.out.println(fooProxyValue);
			System.out.println(fooProxy.getClass());
		};
	}

	@Bean
	public Foo foo() {
		return new FooImpl();
	}

	@Bean
	public Foo fooProxy() {
		return new FooImpl();
	}

	@Bean
	public static BeanPostProcessor bpp() {
		return new BeanPostProcessor() {

			@Override
			public Object postProcessBeforeInitialization(Object bean, String name) throws BeansException {
				if (name.equals("fooProxy")) {
					ProxyFactoryBean pfb = new ProxyFactoryBean();
					pfb.setTarget(bean);
					return pfb.getObject();
				}
				return bean;
			}

			@Override
			public Object postProcessAfterInitialization(Object bean, String name) throws BeansException {
				return bean;
			}
		};
	}

	public interface Foo {

		String foo(String... strings);

	}

	public static class FooImpl implements Foo {

		@Override
		public String foo(String... strings) {
			return "filled: " + Arrays.toString(strings);
		}

	}

}

As written, this emits

filled: [a, b]
class com.example.two.So46953884Application$FooImpl
null
class com.sun.proxy.$Proxy36

Uncommenting the second @Value results in...

EL1004E: Method call: Method foo(java.lang.String,java.lang.String) cannot be found on com.sun.proxy.$Proxy36 type

Affects: 4.3.12

Reference URL: https://stackoverflow.com/questions/46953884

Issue Links:

Referenced from: commits 419b444, 9cc3349

Backported to: 4.3.13

@spring-projects-issues
Copy link
Collaborator Author

Juergen Hoeller commented

It turns out that the proxy-declared methods in a JDK proxy (independent from Spring AOP) do not expose vararg declarations. As a consequence, SpEL's ReflectiveMethodExecutor explicitly looks at the interface-declared variants of those methods in case of a proxy now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in: core Issues in core modules (aop, beans, core, context, expression) status: backported An issue that has been backported to maintenance branches type: bug A general bug
Projects
None yet
Development

No branches or pull requests

2 participants