Uploaded image for project: 'Aries'
  1. Aries
  2. ARIES-1849

Aries proxy does not work with interface default methods

    XMLWordPrintableJSON

    Details

    • Type: Bug
    • Status: Resolved
    • Priority: Major
    • Resolution: Fixed
    • Affects Version/s: proxy-impl-1.1.2
    • Fix Version/s: proxy-impl-1.1.4
    • Component/s: Proxy
    • Labels:
      None

      Description

      Since Java 8 it is possible to define default implementations inside interface definition.

      It seems that Aries proxy is not compatible with interface default methods. As a result it is not possible to use a blueprint reference to a service implementing an interface with default method.

      The following unit test demonstrates the issue :

      import java.util.Collections;
      import org.apache.aries.proxy.UnableToProxyException;
      import org.apache.aries.proxy.impl.interfaces.InterfaceProxyGenerator;
      import org.junit.Assert;
      import org.junit.Test;
      
      public class InterfaceProxyGeneratorTest {
          public static interface Service {
              String getName();
              
              default String getValue() {
                  return "default";
              }
          }
          
          public static class ServiceImpl implements Service {
              @Override
              public String getName() {
                  return "serviceimpl";
              }
              
              @Override
              public String getValue() {
                  return "value";
              }
          }
          
          @Test
          public void testProxy() throws UnableToProxyException {
              ServiceImpl serviceImpl = new ServiceImpl();
              Assert.assertEquals("serviceimpl", serviceImpl.getName());
              Assert.assertEquals("value", serviceImpl.getValue());
              
              Service proxy = (Service)InterfaceProxyGenerator.getProxyInstance(
                  null, null, Collections.singleton(Service.class),
                  () -> {
                      return serviceImpl;
                  },
                  null);
              
              Assert.assertNotNull(proxy);        
              Assert.assertEquals("serviceimpl", proxy.getName());
              Assert.assertEquals("value", proxy.getValue());
          }
      }

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                jbonofre Jean-Baptiste Onofré
                Reporter:
                nicolas.dutertry Nicolas Dutertry
              • Votes:
                0 Vote for this issue
                Watchers:
                4 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved: