Skip to content
This repository has been archived by the owner on Aug 31, 2018. It is now read-only.

IllegalArgumentException: not a proxy instance with @Proxiable @Scope config beans #122

Closed
glassfishrobot opened this issue Aug 24, 2012 · 14 comments

Comments

@glassfishrobot
Copy link
Contributor

Problem is that for @Proxiable @scope CGlib is used but hk2.config does not expect this.

Problem is that for @Proxiable @scope CGlib is used but hk2.config does not expect this.

Attached changes for ctm-example to reproduce the problem:

ConfigSupport.apply throws: java.lang.IllegalArgumentException: not a proxy instance
at java.lang.reflect.Proxy.getInvocationHandler(Proxy.java:657)
at org.jvnet.hk2.config.Dom.unwrap(Dom.java:401)
at org.jvnet.hk2.config.ConfigSupport.apply(ConfigSupport.java:133)
at org.jvnet.hk2.config.ConfigSupport.apply(ConfigSupport.java:113)
at org.glassfish.examples.ctm.runme.CTMTest.testProviderEngineUsesCorrectTenant(CTMTest.java:112)

Transactions.enroll() throws: java.lang.IllegalArgumentException: not a proxy instance
at java.lang.reflect.Proxy.getInvocationHandler(Proxy.java:657)
at org.jvnet.hk2.config.Transaction.enroll(Transaction.java:155)
at org.glassfish.examples.ctm.runme.CTMTest.testProviderEngineUsesCorrectTenant(CTMTest.java:124)

Affected Versions

[2.1.*]

@glassfishrobot
Copy link
Contributor Author

Reported by andriy.zhdanov

@glassfishrobot
Copy link
Contributor Author

File: ctm-example.patch
Attached By: andriy.zhdanov

@glassfishrobot
Copy link
Contributor Author

Was assigned to mk111283

@glassfishrobot
Copy link
Contributor Author

File: config-CGLib-Enhancer.patch
Attached By: andriy.zhdanov

@glassfishrobot
Copy link
Contributor Author

andriy.zhdanov said:
Attached proposed draft fix - reveal enhanced object.
May be if hk2-locator used java.lang.reflect.Proxy (instead of CGLib) it could be a bit simpler.
Core fix revealProxy() may need to be moved somewhere else also.

@glassfishrobot
Copy link
Contributor Author

@jwells131313 said:
So, we cannot use java.lang.reflect.Proxy because we are often proxying objects, not interfaces.

@glassfishrobot
Copy link
Contributor Author

andriy.zhdanov said:
Attached complete proposed fix - improved suggested fix itself and changes to pom.xml files to make ctm-example test work in maven. Using hk2-config test-jar is needed for SimpleConfigBeanDomDecorator which is needed to make config beans be writable.

@glassfishrobot
Copy link
Contributor Author

File: proposed-fix-complete.patch
Attached By: andriy.zhdanov

@glassfishrobot
Copy link
Contributor Author

@jwells131313 said:
Unfortunately, I don't like the way you did this. MethodInterceptorImpl is a detail of the implementation of the HK2 API that the config subsystem should not know anything about. It further assumes that cglib is being used to generate the proxy, which it should also not assume (we may use something different in the future). However, there is a mechanism to do this, though it does require a small change to the underlying API (which I will make).

That way is to use ProxyCtl#__make. All proxies generated for @Proxiable implement the ProxyCtl interface.

A lot of the code you have up there can be simplified (and all of the cglib specific stuff can be removed). All you would need to do is something like:

if (service instanceof ProxyCtl)

{ ProxyCtl pc = (ProxyCtl) service; return pc.__make(); }

This will give you back the "unwrapped" service (well, after I make my little change that will have __make return the underlying service anyway... which I will do in about five minutes).

I hope this helps!

@glassfishrobot
Copy link
Contributor Author

@jwells131313 said:
I have checked in the change to ProxyCtl#__make so that it now returns the underlying service. So there should be no more need to know about cglib or MethodInterceptorImpl at all, which should remain as implementation details.

@glassfishrobot
Copy link
Contributor Author

andriy.zhdanov said:
Thank you, works perfectly!

if (proxy instanceof ProxyCtl) {
  ProxyCtl proxyCtl = (ProxyCtl) proxy;
  proxy = (T) proxyCtl.__make();
}

Committed revision 3927: reveal ConfigBeanProxy from @Proxiable object

@glassfishrobot
Copy link
Contributor Author

@tlcksnyder said:
completed & available.

@glassfishrobot
Copy link
Contributor Author

Marked as fixed on Friday, December 6th 2013, 3:58:24 am

@glassfishrobot
Copy link
Contributor Author

This issue was imported from java.net JIRA HK2-78

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

No branches or pull requests

1 participant