groovy
  1. groovy
  2. GROOVY-3680

Cannot use Groovy class with @Bindable or @Vetoable in Java code: cannot find symbol for addPropertyChangeListener

    Details

    • Type: Bug Bug
    • Status: Open Open
    • Priority: Major Major
    • Resolution: Unresolved
    • Affects Version/s: 1.6.4, 1.7-beta-1
    • Fix Version/s: None
    • Component/s: groovy-jdk
    • Labels:
      None
    • Environment:
      Windows XP, Java 1.6
    • Number of attachments :
      0

      Description

      I compile GroovyBean with @Bindable and/or @Vetoable annotations to Java bytecode. I want to use this class in a Java application. But when I compile the Java class I get the following error:
      CarApp.java:11: cannot find symbol
      symbol : method addPropertyChangeListener(<anonymous java.beans.PropertyChangeListener>)
      location: class CarBean
      car.addPropertyChangeListener(new java.beans.PropertyChangeListener() {
      ^

      The strange thing is that when I look with javap in the generated Groovy class I see the method is available.

      Groovy class:

      import groovy.beans.*

      class Car {
      int numberOfDoors
      @Vetoable String model
      @Vetoable String brand
      boolean automatic
      @Bindable double price

      String toString() {
      "[Car details => brand: '$

      {brand}

      ', model: '$

      {model}

      ', #doors: '$

      {numberOfDoors}

      ', automatic: '$

      {automatic}

      ', price: '$

      {price}

      ']"
      }
      }

      Java class:

      import java.beans.*;

      public class CarApp {
      public static void main(String[] args) throws Exception {
      Car car = new Car();
      car.setNumberOfDoors(3);
      car.setModel("A3");
      car.setBrand("AUDI");
      car.setPrice(32010);

      car.addPropertyChangeListener(new java.beans.PropertyChangeListener() {
      public void propertyChange(java.beans.PropertyChangeEvent evt)

      { System.out.println(evt); }

      });
      }
      }

        Activity

        Hide
        Hubert Klein Ikkink added a comment -

        If I change the Java application and refactor the anonymous interface implementation to concrete implementations AND compile with groovyc the Java application as well, then it works.

        import java.beans.*;

        public class CarApp implements PropertyChangeListener {
        public static void main(String[] args) throws Exception

        { CarApp app = new CarApp(); Car car = new Car(); car.setNumberOfDoors(3); car.setModel("A3"); car.setBrand("AUDI"); car.setPrice(32010); car.addPropertyChangeListener(app); }

        public void propertyChange(java.beans.PropertyChangeEvent evt)

        { System.out.println(evt); }

        }

        Show
        Hubert Klein Ikkink added a comment - If I change the Java application and refactor the anonymous interface implementation to concrete implementations AND compile with groovyc the Java application as well, then it works. import java.beans.*; public class CarApp implements PropertyChangeListener { public static void main(String[] args) throws Exception { CarApp app = new CarApp(); Car car = new Car(); car.setNumberOfDoors(3); car.setModel("A3"); car.setBrand("AUDI"); car.setPrice(32010); car.addPropertyChangeListener(app); } public void propertyChange(java.beans.PropertyChangeEvent evt) { System.out.println(evt); } }
        Hide
        Danno Ferrin added a comment -

        This may be an issue with the joint compiler. Could you try compiling the Groovy class first, separately, and then compile the CarApp class? Whether it fails or works will give me a data point so I know where to work on the bug.

        Show
        Danno Ferrin added a comment - This may be an issue with the joint compiler. Could you try compiling the Groovy class first, separately, and then compile the CarApp class? Whether it fails or works will give me a data point so I know where to work on the bug.
        Hide
        Danno Ferrin added a comment -

        Also possibly related to GROOVY-3683, at least in root cause.

        Show
        Danno Ferrin added a comment - Also possibly related to GROOVY-3683 , at least in root cause.
        Hide
        Hubert Klein Ikkink added a comment -

        I frist compiled the Groovy class Car.groovy: groovyc Car.groovy.
        Next I compiled the Java class CarApp.java: groovyc CarApp.java
        Now I can run CarApp: java CarApp and it works fine.

        But I cannot compile the Java class with javac CarApp.java, because then the cannot find symbol error comes along:
        CarApp.java:11: cannot find symbol
        symbol : method addPropertyChangeListener(CarApp)

        Show
        Hubert Klein Ikkink added a comment - I frist compiled the Groovy class Car.groovy: groovyc Car.groovy. Next I compiled the Java class CarApp.java: groovyc CarApp.java Now I can run CarApp: java CarApp and it works fine. But I cannot compile the Java class with javac CarApp.java, because then the cannot find symbol error comes along: CarApp.java:11: cannot find symbol symbol : method addPropertyChangeListener(CarApp)

          People

          • Assignee:
            Unassigned
            Reporter:
            Hubert Klein Ikkink
          • Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

            • Created:
              Updated: