groovy

Cant have a class method returning an array of complex type

Details

  • Type: Bug Bug
  • Status: Closed Closed
  • Priority: Blocker Blocker
  • Resolution: Fixed
  • Affects Version/s: 1.0-JSR-5
  • Fix Version/s: 1.0-JSR-6
  • Component/s: class generator
  • Labels:
    None
  • Environment:
    Windows XP/SP2 + jdk1.5.0_06
  • Number of attachments :
    0

Description

Here is a script returning a Caught: java.lang.ClassFormatError: Illegal field name "class$Person_]" in class PersonServiceImpl

class Person {
@Property String firstName
@Property int id

String toString() {"${firstName} has id ${id}"}
}

class PersonServiceImpl {
private List persons = new ArrayList()

PersonServiceImpl() { persons = [ new Person(firstName:"Guillaume", id:1), new Person(firstName:"Jochen", id:2), new Person(firstName:"Dierk", id:3), new Person(firstName:"Graeme", id:4)] }

Person[] getPersons() { return persons.toArray(new Person[persons.size()]) }

Person findPerson(int id) { return persons[id] }
}

def ps = new PersonServiceImpl()
println ps.findPerson(0)

NOTA1: Removung the Person[] getPersons() {} blocks makes the script working
NOTA2: Replacing the Person[] type by a native type (int for example) makes things going smooth.

Activity

Hide
blackdrag blackdrag added a comment -

fixed now

Show
blackdrag blackdrag added a comment - fixed now
Hide
Guillaume ALLEON added a comment -

Still not working got the following exception
Caught: java.lang.NullPointerException
at PersonServiceImpl.getPersons(JIRA_1242.groovy:25)
at JIRA_1242.run(JIRA_1242.groovy:43)
at JIRA_1242.main(JIRA_1242.groovy)

while the same construction is working for asic types.

see script

class Person {
@Property String firstName
@Property int id

String toString() {"${firstName} has id ${id}"}
}

class PersonServiceImpl {
private List persons = new ArrayList()
private List numbers = new ArrayList()

PersonServiceImpl() { persons = [ new Person(firstName:"Guillaume", id:1), new Person(firstName:"Jochen", id:2), new Person(firstName:"Dierk", id:3), new Person(firstName:"Graeme", id:4)] numbers = [1, 2, 3, 4] }

Person[] getPersons() { println persons.size() return (Person[])persons.toArray(new Person[persons.size()]) }

int[] getTruc() { return (int[])numbers.toArray(new int[numbers.size()]) }

Person findPerson(int id) { return persons[id] }

}

def ps = new PersonServiceImpl()
println ps.findPerson(0)
aa = ps.getTruc()
aa.each{println "${it}"}
bb = ps.getPersons()

Show
Guillaume ALLEON added a comment - Still not working got the following exception Caught: java.lang.NullPointerException at PersonServiceImpl.getPersons(JIRA_1242.groovy:25) at JIRA_1242.run(JIRA_1242.groovy:43) at JIRA_1242.main(JIRA_1242.groovy) while the same construction is working for asic types. see script class Person { @Property String firstName @Property int id String toString() {"${firstName} has id ${id}"} } class PersonServiceImpl { private List persons = new ArrayList() private List numbers = new ArrayList() PersonServiceImpl() { persons = [ new Person(firstName:"Guillaume", id:1), new Person(firstName:"Jochen", id:2), new Person(firstName:"Dierk", id:3), new Person(firstName:"Graeme", id:4)] numbers = [1, 2, 3, 4] } Person[] getPersons() { println persons.size() return (Person[])persons.toArray(new Person[persons.size()]) } int[] getTruc() { return (int[])numbers.toArray(new int[numbers.size()]) } Person findPerson(int id) { return persons[id] } } def ps = new PersonServiceImpl() println ps.findPerson(0) aa = ps.getTruc() aa.each{println "${it}"} bb = ps.getPersons()
Hide
blackdrag blackdrag added a comment -

ok, that is 1 a new error and 2 a duplicate I know. The vargs implementation is a bit buggy ... it seems I haven't added tests for this... stupid me.

Show
blackdrag blackdrag added a comment - ok, that is 1 a new error and 2 a duplicate I know. The vargs implementation is a bit buggy ... it seems I haven't added tests for this... stupid me.
Hide
blackdrag blackdrag added a comment -

as I have fixed that part of the vargs implementation it should work now

Show
blackdrag blackdrag added a comment - as I have fixed that part of the vargs implementation it should work now

People

Vote (0)
Watch (0)

Dates

  • Created:
    Updated:
    Resolved: