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: Closed Closed
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: 1.6.4, 1.7-beta-1
    • Fix Version/s: 2.4.0-beta-2
    • 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 =&gt; 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 - - edited

        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 - - edited 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)
        Hide
        Paul King added a comment -

        add code tags

        Show
        Paul King added a comment - add code tags
        Hide
        Paul King added a comment -

        Confirming this is still an issue on master (currently 2.3.1-SNAPSHOT).

        Show
        Paul King added a comment - Confirming this is still an issue on master (currently 2.3.1-SNAPSHOT).
        Hide
        Paul King added a comment - - edited

        So removing ACC_SYNTHETIC from the generated addPropertyChangeListener method fixes this problem.

        Show
        Paul King added a comment - - edited So removing ACC_SYNTHETIC from the generated addPropertyChangeListener method fixes this problem.
        Hide
        Paul King added a comment -
        Show
        Paul King added a comment - Proposed fix: https://github.com/groovy/groovy-core/pull/457
        Hide
        Paul King added a comment -

        Made the publicly callable from Java methods not synthetic. The JLS says that members should be synthetic if not explicitly or implicitly represented in the source code. For these methods they are represented implicitly given the AST annotations and properties.

        Show
        Paul King added a comment - Made the publicly callable from Java methods not synthetic. The JLS says that members should be synthetic if not explicitly or implicitly represented in the source code. For these methods they are represented implicitly given the AST annotations and properties.

          People

          • Assignee:
            Paul King
            Reporter:
            Hubert Klein Ikkink
          • Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved: