Grails

CLONE -toString() not inherited properly

Details

  • Type: Bug Bug
  • Status: Closed Closed
  • Priority: Major Major
  • Resolution: Fixed
  • Affects Version/s: 1.0.4
  • Fix Version/s: 1.2 final
  • Component/s: Commons
  • Labels:
    None
  • Environment:
    Linux, JDK 6 (both Sun and JRockit)
  • Testcase included:
    yes

Description

It appears that toString() is not being inherited properly in domain object subclasses.

Domain objects:

class A {
String name
String toString() { 'original' }
}

class B extends A { }

Test code:

void test() {
def a = new A(name:'Object A')
def b = new B(name:'Object B')

println a.toString()
println b.toString()

assert a.toString() == 'original'
assert b.toString() == 'original'
}

Test output:

original
B : null
FAILURE
Tests failed: 1 errors, 0 failures

Issue Links

Activity

Hide
Fabien Benichou added a comment -

I reopened this issue because it occurs again in version 1.2-M2

class Person {

String firstName
String lastName

String toString() { return firstName + " " + lastName.toUpperCase() }
}

class Player extends Person{
}

void testToString() {
mockDomain(Person)
mockDomain(Player)

def person = new Person(firstName: "firstName", lastName: "lastName")
def player = new Player(firstName: "firstName", lastName: "lastName")
assertEquals "firstName LASTNAME", person.toString()
assertEquals "firstName LASTNAME", player.toString()
}

=> last assertion fails !!!

Show
Fabien Benichou added a comment - I reopened this issue because it occurs again in version 1.2-M2 class Person { String firstName String lastName String toString() { return firstName + " " + lastName.toUpperCase() } } class Player extends Person{ } void testToString() { mockDomain(Person) mockDomain(Player) def person = new Person(firstName: "firstName", lastName: "lastName") def player = new Player(firstName: "firstName", lastName: "lastName") assertEquals "firstName LASTNAME", person.toString() assertEquals "firstName LASTNAME", player.toString() } => last assertion fails !!!
Hide
Fabien Benichou added a comment - - edited

What is the status of this bug? Did you manage to reproduce it?

Show
Fabien Benichou added a comment - - edited What is the status of this bug? Did you manage to reproduce it?
Hide
Jeff Brown added a comment -

attaching a project which demonstrates that this works with Grails 1.2

Show
Jeff Brown added a comment - attaching a project which demonstrates that this works with Grails 1.2

People

Vote (0)
Watch (1)

Dates

  • Created:
    Updated:
    Resolved: