[jboss-jira] [JBoss JIRA] (JASSIST-189) Bridge methods are proxied instead of desired methods

Donnchadh Ó Donnabháin (JIRA) jira-events at lists.jboss.org
Fri Dec 21 10:07:08 EST 2012


Donnchadh Ó Donnabháin created JASSIST-189:
----------------------------------------------

             Summary: Bridge methods are proxied instead of desired methods
                 Key: JASSIST-189
                 URL: https://issues.jboss.org/browse/JASSIST-189
             Project: Javassist
          Issue Type: Feature Request
    Affects Versions: 3.17.1-GA
         Environment: OS X, Java 1.7.0_09
            Reporter: Donnchadh Ó Donnabháin
            Assignee: Shigeru Chiba


The following test intermittently fails:
{code}
package org.javassist.test.covariantproxy;

import java.lang.reflect.Method;

import javassist.util.proxy.MethodHandler;
import javassist.util.proxy.ProxyFactory;
import javassist.util.proxy.ProxyObject;
import junit.framework.TestCase;

public class CovariantProxyTest extends TestCase {
    
    public interface TestProxy {
        
    }
    
    public static class TestMethodHandler implements MethodHandler {
        
        boolean invoked = false;

        public Object invoke(Object self, Method thisMethod, Method proceed, Object[] args) throws Throwable {
            invoked = true;
            return proceed.invoke(self, args);
        }
        
        public boolean wasInvoked() {
            return invoked;
        }

        public void reset() {
            invoked = false;
        }

    }

    public static class Issue {
    
        private Integer id;
    
        public Integer getId() {
            return id;
        }
    
        public void setId(Integer id) {
            this.id = id;
        }
    }
    
    public static class PublishedIssue extends Issue {
    
    }

    public static abstract class Article {
        
        private Integer id;
    
        public Integer getId() {
            return id;
        }
    
        public void setId(Integer id) {
            this.id = id;
        }
        
        public abstract Issue getIssue();
    }

    public static class PublishedArticle extends Article {
    
        private PublishedIssue issue;
        
        @Override
        public PublishedIssue getIssue() {
            return issue;
        }
    
        public void setIssue(PublishedIssue issue) {
            this.issue = issue;
        }
        
    }
    
    public void testThatCallingAMethodWithCovariantReturnTypeCallsProxy() throws Exception {
        Class persistentClass = PublishedArticle.class;
        ProxyFactory factory = new ProxyFactory();
        factory.setUseCache(false);
        factory.setSuperclass(persistentClass);
        factory.setInterfaces(new Class[] {TestProxy.class});
        Class cl = factory.createClass();
        TestProxy proxy = ( TestProxy ) cl.newInstance();
        TestMethodHandler methodHandler = new TestMethodHandler();
        ( ( ProxyObject ) proxy ).setHandler( methodHandler );
        
        ((Article)proxy).getIssue();
        assertTrue(methodHandler.wasInvoked());
        
        methodHandler.reset();
        
        PublishedArticle article = (PublishedArticle) proxy;
        
        article.getIssue();
        
        assertTrue(methodHandler.wasInvoked());
        
    }
    
}
{code}

Were there tests added for JASSIST-24 ? I don't see any associated source.

This bug causes a problem in hibernate, described in  https://hibernate.onjira.com/browse/HHH-7884 .

This may be related to JASSIST-162 but the circumstances are slightly different.

The problem occurs intermittently so it appears to depend on the order in which the methods are processed.

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see: http://www.atlassian.com/software/jira



More information about the jboss-jira mailing list