mysema/querydsl — Issue #96: SQL - Mapper implementations suffer from NullPointerException potentially
Author: olivergierke
Created: 2012-02-08 15:37:19+00:00
State: open

Assume you have a domain class containing a propert 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):

```java
Map 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:

```java
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.