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

[PATCH] Fix the problem in handling bridge methods

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Fixed
    • None
    • 1.8.3, 1.9-beta-4
    • None
    • None
    • Patch

    Description

      Groovy should ignore bridge methods.

      This eliminates redundant method calls, although that isn't why
      I need it.

      My primary reason for this change is bit unusual; I've got a little
      byte code post processor to inject synthetic bridge methods
      to help me evolve code without breaking existing binaries,
      <http://bridge-method-injector.infradna.com/>, and as a part of this
      I generate a bridge method whose return type is narrower, instead of
      wider.

      That is, whereas normally bridge methods are as follows:

      interface Base {
          Object foo();
      }
      
      class Impl implements Base {
          String foo() {...}
      
          // the above definition causes javac to insert the following
          // bridge method
          @Synthetic @Bridge
          Object foo() { return <String>foo(); }
      }
      

      my byte code post processing would produce this:

      class Impl /* no interface needed */ {
          Object foo() {...}
      
          @Synthetic @Bridge
          String foo() { return (String)<Object>foo(); }
      }
      

      This works with javac, in the sense that it'll invoke "Object foo()", by preferring non-bridge methods for resolution.

      Unfortunately, Grooovy doesn't discreminate against bridge methods, so it can end up calling "String foo()" depending on the exact implementation detail of the search.

      This fix eliminates this issue by making Groovy ignore all bridge methods. Would you please please include this?

      Attachments

        1. DIFF
          1 kB
          Kohsuke Kawaguchi

        Issue Links

          Activity

            People

              guillaume Guillaume Sauthier
              kohsuke Kohsuke Kawaguchi
              Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: