JPASupport.edit() handle FileAttachment incorrectly

Bug #483172 reported by true_cp
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
play framework
Status tracked in 1.0
1.0
Fix Released
Undecided
Unassigned
1.1
Fix Committed
Undecided
Unassigned

Bug Description

Use "Job Board" sample as Test Case:
1. Visit admin page: http://localhost:9000/admin/
2. Click Companies link and add a new Company with uploading a new logo.
3. Return to the Company list page.
4. Click the link of new add Company.
5. Leave nothing change and click "Save". (Alternativly can change other fileds, to trigger "saveFileAttachment" method.)
6. Return to Company list page.
7. Click the link of new add Company and observer the logo field.
Except Result:
 - The logo filed is not changed.
Actual Result:
 - The logo is empty.

Bug analysis:
In step 5, when save object, the line 66 in JPASupport.edit()
            bw.bind(name, o.getClass(), params, "", o);
will flush "logo" field to null. And in the following if-else closure from line 124-141 cannot find upload file attributes from params.

Proposed solution:
1. in BeanWrapper.bind() method, add a check of fileds, if its type is FileAttachment and it's not null, don't set value of it. If the FileAttachment filed is changed, it would be updated in the JPASupport.edit() handle fileAttachment closure(124-141).
2. There is a potential problem: FileAttachment.save() invokes Files.copy(), in this method, if from and to is the same, the file will be flush to 0 size.

Revision history for this message
true_cp (true-cp) wrote :
Revision history for this message
true_cp (true-cp) wrote :
Changed in play:
status: New → Fix Committed
Revision history for this message
true_cp (true-cp) wrote :

The bug is still out there.

Changed in play:
status: Fix Committed → Incomplete
Revision history for this message
true_cp (true-cp) wrote :

This bug isn't fixed completely. "BeanWrapper.bean()" must handle FileAttachment type.

Revision history for this message
Guillaume Bort (guillaume-bort) wrote :

Fixed in #489175

Changed in play:
status: Incomplete → Fix Committed
Revision history for this message
true_cp (true-cp) wrote :

The provieded test case can't pass in Rev.709

The actuall result is changed: The logo field is existed by the file name is missing, but the file size is there.

Additionally, choose a new file and click "Save" to upload another file, an IllegalStateException will throw.

Changed in play:
status: Fix Committed → Incomplete
Revision history for this message
Guillaume Bort (guillaume-bort) wrote :

Thank you. I missed that point ...

Changed in play:
status: Incomplete → Fix Committed
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.