[JAVA-1813] GridFSInputFile.save() error when using createFile(File f) Created: 12/May/15  Updated: 01/Apr/16  Resolved: 13/May/15

Status: Closed
Project: Java Driver
Component/s: GridFS
Affects Version/s: 3.0.0
Fix Version/s: 3.0.2

Type: Bug Priority: Major - P3
Reporter: Augusto Decoud Assignee: Ross Lawley
Resolution: Done Votes: 0
Labels: regression
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified
Environment:

Tested in Windows 7, Java SE 1.8 but appñlies for all


Backwards Compatibility: Fully Compatible

 Description   

Problem introduced in driver version 3.0.1.
Drivers used: mongo-driver-code-3.0.1, mongo-driver-3.0.1, bson-3.0.1
Trying to save a file to a GridFS database give the following error: com.mongodb.MongoException: couldn't save chunks

Caused by: java.io.IOException: Stream Closed

Solution:
Change function;

    public GridFSInputFile createFile(final File file) throws IOException {
        FileInputStream fileInputStream = new FileInputStream(file);
        try {
            return createFile(new FileInputStream(file), file.getName(), true);
        } finally {
           fileInputStream.close();
        }
    }

for this one:

    public GridFSInputFile createFile(final File file) throws IOException {
            return createFile(new FileInputStream(file), file.getName(), true);
    }

as in older versions.

Problem dissapears.

I do not know the reason for the changes in the 3.0.1 version. I did some tests after the changes and it seems it do not affect the rest of the class.

This is my first post. I'm new to MongoDb, so excuse me if I did something wrong in this post.

Thanks,
Augusto



 Comments   
Comment by Githook User [ 13/May/15 ]

Author:

{u'username': u'rozza', u'name': u'Ross Lawley', u'email': u'ross.lawley@gmail.com'}

Message: Fixed testCreateFileWithFile to work with Java 1.6

JAVA-1813
Branch: 3.0.x
https://github.com/mongodb/mongo-java-driver/commit/8e5ce969bbfb195414656b19ff10f7336fa3ba2d

Comment by Githook User [ 13/May/15 ]

Author:

{u'username': u'rozza', u'name': u'Ross Lawley', u'email': u'ross.lawley@gmail.com'}

Message: Fixed testCreateFileWithFile to work with Java 1.6

JAVA-1813
Branch: master
https://github.com/mongodb/mongo-java-driver/commit/7672547af0e53db0a82287e1aeab9a90b94c3e2b

Comment by Ross Lawley [ 13/May/15 ]

Thanks again for the bug report adecoud

This has been fixed in 3.0.x and on master and will be released in 3.0.2 and later in 3.1

Comment by Githook User [ 13/May/15 ]

Author:

{u'username': u'rozza', u'name': u'Ross Lawley', u'email': u'ross.lawley@gmail.com'}

Message: Fixed GridFS.createFile bug

The underlying call handles the closure of the stream correctly

JAVA-1813
Branch: master
https://github.com/mongodb/mongo-java-driver/commit/0a759943e1d5a8b971798db82e8a89330545e558

Comment by Githook User [ 13/May/15 ]

Author:

{u'username': u'rozza', u'name': u'Ross Lawley', u'email': u'ross.lawley@gmail.com'}

Message: Fixed GridFS.createFile bug

The underlying call handles the closure of the stream correctly

JAVA-1813
Branch: 3.0.x
https://github.com/mongodb/mongo-java-driver/commit/2b6b69c1a6ed1da2068b48645af211b9d6c9283c

Comment by Ross Lawley [ 13/May/15 ]

Thanks adecoud, it is indeed a regression and your fix round is correct.

For other users of 3.0.0 or 3.0.1 please use:

createFile(final InputStream in, final String filename, final boolean closeStreamOnPersist)

Instead of:

createFile(final File file)

Until this is fixed.

Generated at Thu Feb 08 08:55:34 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.