Uploaded image for project: 'Groovy'
  1. Groovy
  2. GROOVY-7330

Incorrect dynamic proxy creation from map when there are default methods

    XMLWordPrintableJSON

Details

    Description

      package org.dimitrovchi.groovybugs;
      
      import groovy.lang.GroovyShell;
      import org.codehaus.groovy.control.CompilerConfiguration;
      import org.codehaus.groovy.runtime.DefaultGroovyMethods;
      import org.junit.Assert;
      import org.junit.Test;
      
      import java.util.Map;
      
      /**
       * @author Dmitry Ovchinnikov
       */
      public class MapToProxyTest {
      
          private final GroovyShell shell;
      
          public MapToProxyTest() {
              final CompilerConfiguration cc = new CompilerConfiguration();
              cc.setTargetBytecode(CompilerConfiguration.JDK8);
              shell = new GroovyShell(cc);
          }
      
          @Test
          public void testMapToProxy() {
              final Map map = (Map) shell.evaluate("[x: {10}, y: {20}]");
              final SomeInterface si = DefaultGroovyMethods.asType(map, SomeInterface.class);
              Assert.assertEquals(20, si.y());
              Assert.assertEquals(10, si.x()); // assertion error: si.x() == 1
          }
      
          public interface SomeInterface {
      
              default int x() {
                  return 1;
              }
      
              int y();
          }
      }
      

      JDK 1.8u31

      Attachments

        Issue Links

          Activity

            People

              paulk Paul King
              dmovchinn Dmitry Ovchinnikov
              Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: