SQL - Mapper implementations suffer from NullPointerException potentially #96

Closed
olivergierke opened this Issue Feb 8, 2012 · 1 comment

Comments

Projects
None yet
2 participants
@olivergierke

Assume you have a domain class containing a property which doesn't have a corresponding metadata element in the query class. If an object of such a class is passed to a Mapper implementation (seems to be the case for all of them) you'll get a NullPointerException at the following code snippet (taken from DefaultMapper but the other implementations suffer from the same issue):

Map<String, Field> fields = getPathFields(entity.getClass());
…
Field field = fields.get(property);
Path path = (Path<?>) field.get(entity);
if (entry.getValue() != null) {
  values.put(path, entry.getValue());    
}

field will be null for the property mapped in the domain object but not included in the query class. So I think the relevant code snippet has to be changed to:

Field field = fields.get(property);

if (field != null && entry.getValue() != null) {
  Path path = (Path<?>) field.get(entity);
  values.put(path, entry.getValue());    
}

This is also avoiding the path lookup if not necessary although this is probably just a cosmetic issue.

timowest added a commit that referenced this issue Feb 8, 2012

@timowest

This comment has been minimized.

Show comment
Hide comment
@timowest

timowest Feb 19, 2012

Member

released in 2.3.2

Member

timowest commented Feb 19, 2012

released in 2.3.2

@timowest timowest closed this Feb 19, 2012

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment