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

Wrong byte code for compiled SpEL when JDK proxy method invocation is used [SPR-16191] #20739

Closed
spring-projects-issues opened this issue Nov 13, 2017 · 2 comments
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 Nov 13, 2017

Artem Bilan opened SPR-16191 and commented

The test-case to reproduce:

@Test
public void testCompiledSpELForProxy() {
	Foo foo = new FooImpl();

	foo = (Foo) new ProxyFactory(foo).getProxy();

	SpelExpressionParser expressionParser =
			new SpelExpressionParser(new SpelParserConfiguration(SpelCompilerMode.IMMEDIATE, null));

	Expression expression = expressionParser.parseExpression("#target.handle(#root)");

	StandardEvaluationContext evaluationContext = new StandardEvaluationContext();
	evaluationContext.setVariable("target", foo);

	String result = expression.getValue(evaluationContext, "foo", String.class);
	result = expression.getValue(evaluationContext, "foo", String.class);

	assertEquals("FOO", result);
}

public interface Foo {

	String handle(String payload);

}

public class FooImpl implements Foo {

	@Override
	public String handle(String payload) {
		return payload.toUpperCase();
	}

}

The exception looks like:

java.lang.IllegalStateException: Failed to instantiate CompiledExpression

    at org.springframework.expression.spel.standard.SpelCompiler.compile(SpelCompiler.java:110)
    at org.springframework.expression.spel.standard.SpelExpression.compileExpression(SpelExpression.java:517)
    at org.springframework.expression.spel.standard.SpelExpression.checkCompile(SpelExpression.java:487)
    at org.springframework.expression.spel.standard.SpelExpression.getValue(SpelExpression.java:372)
    at org.springframework.integration.handler.MethodInvokingMessageProcessorTests.testCompiledSpELForProxy(MethodInvokingMessageProcessorTests.java:904)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
    at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
    at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
    at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
    at org.junit.rules.ExpectedException$ExpectedExceptionStatement.evaluate(ExpectedException.java:239)
    at org.junit.rules.RunRules.evaluate(RunRules.java:20)
    at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
    at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78)
    at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57)
    at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
    at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
    at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
    at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
    at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
    at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
    at org.junit.runner.JUnitCore.run(JUnitCore.java:137)
    at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:68)
    at com.intellij.rt.execution.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:47)
    at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:242)
    at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:70)
Caused by: java.lang.VerifyError: (class: spel/Ex2, method: getValue signature: (Ljava/lang/Object;Lorg/springframework/expression/EvaluationContext;)Ljava/lang/Object;) Illegal type in constant pool
    at java.lang.Class.getDeclaredConstructors0(Native Method)
    at java.lang.Class.privateGetDeclaredConstructors(Class.java:2671)
    at java.lang.Class.getConstructor0(Class.java:3075)
    at java.lang.Class.getDeclaredConstructor(Class.java:2178)
    at org.springframework.util.ReflectionUtils.accessibleConstructor(ReflectionUtils.java:503)
    at org.springframework.expression.spel.standard.SpelCompiler.compile(SpelCompiler.java:107)
    ... 28 more

The byte code for the compiled class:

����   1 !� �spel/Ex2� �� 6org/springframework/expression/spel/CompiledExpression� �� �<init>☃0001 �()V
getValue� X(Ljava/lang/Object;Lorg/springframework/expression/EvaluationContext;)Ljava/lang/Object;� 2org/springframework/expression/EvaluationException� �� �target
0org/springframework/expression/EvaluationContext� �� �lookupVariable� &(Ljava/lang/String;)Ljava/lang/Object; � �� � �� �com/sun/proxy/$Proxy5� �� Oorg/springframework/integration/handler/MethodInvokingMessageProcessorTests$Foo� �� �java/lang/String� �� �handle� &(Ljava/lang/String;)Ljava/lang/String; � �� � �� �Code
Exceptions � � �     � � � � � �   � � �   �*� ��
" � �   �,��� �� � �� �+� �� ��         � �   

With SF-5.0.1 it looks like (if that helps somehow..):

����   1 �� �spel/Ex2� �� 6org/springframework/expression/spel/CompiledExpression� �� �<init>� �()V
getValue� X(Ljava/lang/Object;Lorg/springframework/expression/EvaluationContext;)Ljava/lang/Object;� 2org/springframework/expression/EvaluationException� �� �target
0org/springframework/expression/EvaluationContext� �� �lookupVariable� &(Ljava/lang/String;)Ljava/lang/Object; � �� � �� �com/sun/proxy/$Proxy5� �� �java/lang/String� �� �handle� &(Ljava/lang/String;)Ljava/lang/String;
Code
Exceptions � � �     � � � � � �   � � �   ☃0005*� ��
,��� �� � �+� �� ��     �   � �   

It might be like a side-effect of the fix for the #20670 since we have the same problem with the 4.3.13 as well.


Affects: 4.3.13, 5.0.2

Issue Links:

Referenced from: commits c30145d, 6dc7346

Backported to: 4.3.13

@spring-projects-issues
Copy link
Collaborator Author

Juergen Hoeller commented

We're simply treating proxy-targeting expressions as non-compilable now. Fixed in master for 5.0.2.BUILD-SNAPSHOT; to be backported to 4.3.x ASAP.

@spring-projects-issues
Copy link
Collaborator Author

Artem Bilan commented

OK. Fine with me for now.

Just wonder if really someone will come back to us with the request to make them compilable one day :).

Thank you, Juergen!

@spring-projects-issues spring-projects-issues added type: bug A general bug status: backported An issue that has been backported to maintenance branches in: core Issues in core modules (aop, beans, core, context, expression) labels Jan 11, 2019
@spring-projects-issues spring-projects-issues added this to the 5.0.2 milestone Jan 11, 2019
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