Fixes issue with NPE

This commit is contained in:
Lukasz Lenart
2016-11-24 14:52:18 +01:00
parent ae5605ff88
commit 1ff8a88a9d
@@ -36,18 +36,22 @@ public class UploadedFileConverter extends DefaultTypeConverter {
@Override
public Object convertValue(Map<String, Object> context, Object target, Member member, String propertyName, Object value, Class toType) {
if (File.class.equals(toType)) {
LOG.warn("Converting {} into {}, consider switching to {} and do not access {} directly!",
LOG.debug("Converting {} into {}, consider switching to {} and do not access {} directly!",
File.class.getName(), UploadedFile.class.getName(), UploadedFile.class.getName(), File.class.getName());
Object obj;
if (value.getClass().isArray() && Array.getLength(value) == 1) {
Object obj = Array.get(value, 0);
if (obj instanceof UploadedFile) {
UploadedFile file = (UploadedFile) obj;
if (file.getContent() instanceof File) {
return file.getContent();
}
return new File(file.getAbsolutePath());
obj = Array.get(value, 0);
} else {
obj = value;
}
if (obj instanceof UploadedFile) {
UploadedFile file = (UploadedFile) obj;
if (file.getContent() instanceof File) {
return file.getContent();
}
return new File(file.getAbsolutePath());
}
}