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

Can't create protocol session with SessionStatProxy #28

Open
abliznyuk opened this issue Sep 30, 2016 · 0 comments
Open

Can't create protocol session with SessionStatProxy #28

abliznyuk opened this issue Sep 30, 2016 · 0 comments
Labels

Comments

@abliznyuk
Copy link
Member

abliznyuk commented Sep 30, 2016

Problem

Creation of session proxy failed when in application uses target class proxies.

It happens because environment changes (by default used class interfaces proxies). E.g. add Spring Cloud components that use target class proxies.

How to reproduce

In context set property target-class-proxy=true.

Exception throws in DirectProtocolGateway when proxy casts to protocol type:
https://github.com/ametiste-oss/ametiste-lambda-platform/blob/master/lambda-platform-pgw/src/main/java/org/ametiste/laplatform/protocol/gateway/DirectProtocolGateway.java#L199

private <T extends Protocol> T proxySession(Protocol obj, SessionStatProxy sessionStatProxy, Class<T> protocolType) {
    T session = protocolType.cast(java.lang.reflect.Proxy.newProxyInstance(
            obj.getClass().getClassLoader(),
            obj.getClass().getInterfaces(),
            sessionStatProxy
    ));
    return session;
}

Stacktrace:

2016-09-06 00:23:55.198 ERROR 42606 --- [pool-3-thread-1] o.a.r.i.e.l.LocalLineExecutionGateway    : Error during task operation execution : mod-shredder-op-shredding-stale

java.lang.ClassCastException: Cannot cast com.sun.proxy.$Proxy131 to org.ametiste.routine.infrastructure.protocol.taskpool.TaskPoolProtocol
    at java.lang.Class.cast(Class.java:3369) ~[na:1.8.0_91]
    at org.ametiste.laplatform.protocol.gateway.DirectProtocolGateway.proxySession(DirectProtocolGateway.java:199) ~[lambda-platform-pgw-0.2.6.jar:na]
    at org.ametiste.laplatform.protocol.gateway.DirectProtocolGateway.protocolOptions(DirectProtocolGateway.java:158) ~[lambda-platform-pgw-0.2.6.jar:na]
    at org.ametiste.laplatform.protocol.gateway.DirectProtocolGateway.session(DirectProtocolGateway.java:54) ~[lambda-platform-pgw-0.2.6.jar:na]
    at org.ametiste.laplatform.protocol.ProtocolGateway.session(ProtocolGateway.java:24) ~[lambda-platform-pgw-0.2.6.jar:na]

It happens because protocol instance obj is Proxy too (e.g. metric aspects proxies, com.sun.proxy.$Proxy). So java.lang.reflect.Proxy.newProxyInstance creates proxy for Proxy target class and as result we get ClassCastException in cast method.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant