Skip to content

Commit

Permalink
Fixes issue with NPE
Browse files Browse the repository at this point in the history
  • Loading branch information
lukaszlenart committed Nov 24, 2016
1 parent ae5605f commit 1ff8a88
Showing 1 changed file with 12 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
}

Expand Down

0 comments on commit 1ff8a88

Please sign in to comment.