Skip to content

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

@spring-projects-issues

Description

@spring-projects-issues

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

Metadata

Metadata

Assignees

Labels

in: coreIssues in core modules (aop, beans, core, context, expression)status: backportedAn issue that has been backported to maintenance branchestype: bugA general bug

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions