groovy

If one constructor calls another, instance variables may be initialized incorrectly

Details

  • Type: Bug Bug
  • Status: Closed Closed
  • Priority: Major Major
  • Resolution: Fixed
  • Affects Version/s: 1.0-JSR-4
  • Fix Version/s: 1.5.2
  • Component/s: None
  • Labels:
    None
  • Environment:
    Linux with JDK 1.5.0
  • Number of attachments :
    0

Description

Run the following Groovy program. The instance variable "success" changes value between the end of the second constructor and the end of the first constructor. This program works as expected in Java.

class Pinger {
boolean success

Pinger(String destHost) {
this(destHost, 1, 100)
println "at end of little constructor, success is type ${success.class} a\
nd value ${success}"
}

Pinger(String destHost, int in_n, int in_hops) {
success = true
println "at end of constructor, success is type ${success.class} and valu\
e ${success}"
}

}

Pinger p = new Pinger("www.yahoo.com")
println "Success is ${p.success}"

Activity

Hide
Andres Almiray added a comment -

Running the provided script in groovyConsole (1.1-final-SNAPSHOT, jdk1.6.0_03,winxp)

groovy> class Pinger {
groovy>    boolean success
groovy>    Pinger(String destHost) {
groovy>       this(destHost, 1, 100)
groovy>       println "at end of little constructor, success is type ${success.class} and value ${success}"
groovy>    }
groovy>    Pinger(String destHost, int in_n, int in_hops) {
groovy>       success = true
groovy>       println "at end of constructor, success is type ${success.class} and value ${success}"
groovy>    }
groovy> }
groovy> Pinger p = new Pinger("www.yahoo.com")
groovy> println "Success is ${p.success}"

at end of constructor, success is type class java.lang.Boolean and value true
at end of little constructor, success is type class java.lang.Boolean and value true
Success is true

seems like its working now

Show
Andres Almiray added a comment - Running the provided script in groovyConsole (1.1-final-SNAPSHOT, jdk1.6.0_03,winxp)
groovy> class Pinger {
groovy>    boolean success
groovy>    Pinger(String destHost) {
groovy>       this(destHost, 1, 100)
groovy>       println "at end of little constructor, success is type ${success.class} and value ${success}"
groovy>    }
groovy>    Pinger(String destHost, int in_n, int in_hops) {
groovy>       success = true
groovy>       println "at end of constructor, success is type ${success.class} and value ${success}"
groovy>    }
groovy> }
groovy> Pinger p = new Pinger("www.yahoo.com")
groovy> println "Success is ${p.success}"

at end of constructor, success is type class java.lang.Boolean and value true
at end of little constructor, success is type class java.lang.Boolean and value true
Success is true
seems like its working now
Hide
Paul King added a comment -

Works for me too. Please reopen if you find a problem.

Show
Paul King added a comment - Works for me too. Please reopen if you find a problem.
Hide
Paul King added a comment -

close off release 1.5.4

Show
Paul King added a comment - close off release 1.5.4

People

Vote (0)
Watch (1)

Dates

  • Created:
    Updated:
    Resolved: