You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@fury.apache.org by "cn-at-osmit (via GitHub)" <gi...@apache.org> on 2024/02/06 10:26:30 UTC

[I] [java] Java Proxy classes: Reference missing when InvocationHandler holds reference to the Proxy itself. [incubator-fury]

cn-at-osmit opened a new issue, #1364:
URL: https://github.com/apache/incubator-fury/issues/1364

   ### Search before asking
   
   - [X] I had searched in the [issues](https://github.com/apache/incubator-fury/issues) and found no similar issues.
   
   
   ### Version
   
   fury 0.4.1, Java 21, macOS 14.3
   
   ### Component(s)
   
   Java
   
   ### Minimal reproduce step
   
   Run this testcase: 
   
   ```java
   
   	public static class MyInvocationHandler implements InvocationHandler, Serializable {
   
   		private static final long	serialVersionUID	= 1L;
   
   		private Callable<String>	myProxy;
   
   		@Override
   		public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
   			return "Hello world from " + (myProxy == null ? "null" : proxy.getClass().getName() + "@" + System.identityHashCode(proxy));
   		}
   
   		public void setMyProxy(Callable<String> myProxy) {
   			this.myProxy = myProxy;
   		}
   
   		public Callable<String> getMyProxy() {
   			return myProxy;
   		}
   	}
   
   	public static void main(String[] args) throws Exception {
   
   		MyInvocationHandler handler = new MyInvocationHandler();
   		@SuppressWarnings("unchecked")
   		Callable<String> proxy = (Callable<String>) Proxy.newProxyInstance(Class.class.getClassLoader(), new Class<?>[] { Callable.class }, handler);
   		handler.setMyProxy(proxy);
   
   		System.out.println(proxy.call());
   		assert handler.getMyProxy() == proxy;
   
   		Fury fury = Fury.builder().withRefTracking(true).requireClassRegistration(false).build();
   		byte[] serData = fury.serialize(proxy);
   		@SuppressWarnings("unchecked")
   		Callable<String> proxyDeser = (Callable<String>) fury.deserialize(serData);
   
   		System.out.println(proxyDeser.call());
   		MyInvocationHandler handlerDeser = (MyInvocationHandler) Proxy.getInvocationHandler(proxyDeser);
   		if (handlerDeser.getMyProxy() != proxyDeser) {
   			throw new IllegalStateException("Inner reference not set");
   		}
   	}
   ```
   
   ### What did you expect to see?
   
   I expect the `myProxy` object to have a reference to the proxy instance after deserialization
   
   ### What did you see instead?
   
   A `null` value
   
   ### Anything Else?
   
   PR is on the way...
   
   ### Are you willing to submit a PR?
   
   - [X] I'm willing to submit a PR!


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@fury.apache.org.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@fury.apache.org
For additional commands, e-mail: commits-help@fury.apache.org


Re: [I] [java] Java Proxy classes: Reference missing when InvocationHandler holds reference to the Proxy itself. [incubator-fury]

Posted by "chaokunyang (via GitHub)" <gi...@apache.org>.
chaokunyang commented on issue #1364:
URL: https://github.com/apache/incubator-fury/issues/1364#issuecomment-1934206142

   Thanks for reporting this issue. This is tricky. 
   
   Normally, we can make reference graph right by set self reference first. But is't not easy for proxy object, since we can't create proxy in advance before we read its data:
   ![image](https://github.com/apache/incubator-fury/assets/12445254/d5636265-9817-4a42-8afc-ae6ccebfd4df)
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@fury.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@fury.apache.org
For additional commands, e-mail: commits-help@fury.apache.org


Re: [I] [java] Java Proxy classes: Reference missing when InvocationHandler holds reference to the Proxy itself. [incubator-fury]

Posted by "chaokunyang (via GitHub)" <gi...@apache.org>.
chaokunyang closed issue #1364: [java] Java Proxy classes: Reference missing when InvocationHandler holds reference to the Proxy itself.
URL: https://github.com/apache/incubator-fury/issues/1364


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@fury.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@fury.apache.org
For additional commands, e-mail: commits-help@fury.apache.org