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

Object not bound with Groovy (but works fine in Java)

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Fixed
    • 3.0.6
    • 3.0.7, 4.0.0-alpha-2
    • None
    • None
    • OS: Windows 10
      AdoptJDK Hotspot 1.8.0.272

    Description

      Consider the following reproducer: https://github.com/ptomaszek/vertx-groovy

       As it can be seen, there are two main classes: one with Groovy and one with Java. Both of them are simple reproducers of Vert.x Promises. When an object of Promisse calls it's future() method, it seems to create a new Future instance everytime, instead of just returning the existing one.

       The code within the reproducer has similar codes in Groovy and Java. When MainJava runs, it prints true, which is the expected behaviour. When MainGroovy runs, it prints false unless the class is annotated with @CompileStatic. 

      Another reproducer is https://github.com/tienquanutc/vertx-promise-groovy-bug . This one also has two classes with similar codes. As promise.future() gets called four times, JMain classes prints 1 which is ok, but GMain prints 4. This one also works as expected with Groovy using @CompileStatic. 

      This can be related to the fact that Promise and Future share the same implementation (https://github.com/eclipse-vertx/vert.x/tree/3.9/src/main/java/io/vertx/core). Apparently when Groovy resolves the future() method call dynamically, it invokes the Future.future() static method instead of the instance Promise.future() method. 

      There's also some healthy discussion here https://github.com/vert-x3/vertx-lang-groovy/issues/113 

      I don't think it's a bug with Vert.x, since the code with Java works correctly.

      Attachments

        Activity

          People

            emilles Eric Milles
            aaloise André Filipe Aloise
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Time Tracking

                Estimated:
                Original Estimate - Not Specified
                Not Specified
                Remaining:
                Remaining Estimate - 0h
                0h
                Logged:
                Time Spent - 40m
                40m