[1.2.4] Blog : NullPointerException on File init

15 views
Skip to first unread message

Neoh59

unread,
Feb 22, 2012, 5:21:35 AM2/22/12
to play-fr...@googlegroups.com
Hi all,

Could you help me on this problem.

I have a User entity with a photo member (Blob) ans some others members of course.

@Entity
public class User extends Model {
    ...
    public Blob photo;
    ...
 }

I override the save method, and want to resize the photo if needed :
    @Override
    public void _save() {
        ...
        resizePhoto(); // Line 66
        super._save();
    }

The resizePhoto() method is :
    private void resizePhoto() {
        try {
            if (photo != null) {
                File photoFile = photo.getFile(); // Line 205
                if (photoFile != null && photoFile.length() > getPhotoMaxSize()) {
                    // TODO
                }
            }
        } catch (Exception e) {
            Logger.warn("error when resizing photo for user %s : %s", username, e);
            if (Logger.isDebugEnabled()) {
                e.printStackTrace();
            }
        }
    }


Each time a User is saved, an exception is thrown. Here is a part of the stack trace :
11:07:50,518 WARN  ~ error when resizing photo for user 51000450 : java.lang.NullPointerException
java.lang.NullPointerException
    at java.io.File.<init>(File.java:305)
    at play.db.jpa.Blob.getFile(Blob.java:66)
    at models.Employee.resizePhoto(Employee.java:205)
    at models.Employee._save(Employee.java:197)


I check if photo member is not null. So why the line :
File photoFile = photo.getFile(); // Line 205
throws a NullPointerException ?

Thanks for your help

Reply all
Reply to author
Forward
0 new messages