Uploaded image for project: 'Groovy'
  1. Groovy
  2. GROOVY-2503 MOP 2.0 design inflluencing issues
  3. GROOVY-2500

Assignment calls the wrong setter, depending on order of declaration

    XMLWordPrintableJSON

Details

    • Sub-task
    • Status: Closed
    • Major
    • Resolution: Fixed
    • 1.5.1
    • 2.4.0-beta-4
    • groovy-runtime
    • None
    • Windows XP, java 6 update 4, ant 1.7, groovy 1.6 beta 1

    Description

      The following build.xml fails:

      <?xml version="1.0" encoding="UTF-8"?>
      <project name="test" default="run">
      
      	<path id="groovy.classpath">
      		<fileset dir="." includes="groovy-*.jar"/>
      	</path>
      
      	<taskdef name="groovy" classname="org.codehaus.groovy.ant.Groovy" classpathref="groovy.classpath"/>
      
      	<target name="compile">
      		<echo file="Test.java">
      			public class Test
      			{
      				public void setField( String value )
      				{ 
      					System.out.println( "String" );
      				}
      			
      				public void setField( Integer value )
      				{ 
      					System.out.println( "Integer" );
      				}
      			}
      		</echo>
      		<javac srcdir="." includes="Test.java"/>
      	</target>
      
      	<target name="run" depends="compile">
      		<groovy>
      			try
      			{
      				new Test().setField( "sss" ) // This works
      				println "success 1"
      				new Test().field = "sss" // This gives exception
      				println "success 2"
      			}
      			catch( Exception e )
      			{
      				e.printStackTrace( System.out )
      			}
      		</groovy>
      	</target>
      
      </project>
      

      (you need to put the groovy.jar in the same folder)

      The setField() succeeds, but the assignment fails.

      If I change the order of the two setField() methods, both succeed.

      Attachments

        Issue Links

          Activity

            People

              melix Cédric Champeau
              rene.de.bloois René de Bloois
              Votes:
              2 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: