Skip to content

GPMONGODB-83: NullPointer on Dynamic Properties on Domain Class with Unique Constraint #236

@graemerocher

Description

@graemerocher

Original Reporter: kensipe
Environment: Mac OSX (Lion), JDK 1.6, Grails 1.3.7
Version: 1.0.0.M6
Migrated From: http://jira.grails.org/browse/GPMONGODB-83

with a User domain class with the following constraint:
{code}
import org.bson.types.ObjectId

class User {

ObjectId id
String name
List<String> roles = []
Address address

static constraints = {

}

static embedded = ['address']

static mapping = {
    name index: true, indexAttributes: [unique: true, dropDups: true]
}

def addRole(Role role) {
    roles << role.toString()
}

def boolean hasRole(String role) {
    roles.contains(role)
}

def boolean hasRole(Role role) {
    hasRole(role.toString())
}

}
{code}

if the follow code is executed (ex. BootStrap)

{code}
def user = new User(name: 'ken')
user['foo'] = "xxx"
user.save(flush: true)
{code}

The first go works... the second will fail with a NPE bring down the web app. The issues is reported as the line with the save... it appears to me that the save is attempted, however based on the constraints the user object will not exist, take seems to be followed by the setting of the dynamic property causing the problem. I tried to get the source code but the source link for github is incorrect. My take on it... if the object is null, there none of the dynamic properties matter. let me know if you need more.

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions