[JAVA-2096] NullPointerException when calling GridFSInputFile.save Created: 21/Jan/16 Updated: 13/Sep/16 Resolved: 13/Sep/16 |
|
| Status: | Closed |
| Project: | Java Driver |
| Component/s: | GridFS |
| Affects Version/s: | 2.14.1 |
| Fix Version/s: | None |
| Type: | Bug | Priority: | Minor - P4 |
| Reporter: | Francisco Manuel Benitez Chico | Assignee: | Unassigned |
| Resolution: | Won't Fix | Votes: | 0 |
| Labels: | None | ||
| Remaining Estimate: | Not Specified | ||
| Time Spent: | Not Specified | ||
| Original Estimate: | Not Specified | ||
| Environment: |
Production |
||
| Description |
|
Hello, If I get an instance of GridFSInputFile from the method createFile() of GridFS, MongoDB Java Driver assigns null to the attribute _in. So, when I want to call the "save" method from GridFSInputFile, I always get a NullPointerException (line 295 - GridFSInputFile) because this value is null, and I cannot set it anywhere (the only place is the constructor and with by the method createFile() is always null) Does it make sense to have an method createFile without parameters if I always get a NullPointer when I try to save? Many thanks. Regards, |
| Comments |
| Comment by Jeffrey Yemin [ 13/Sep/16 ] | ||||||||||||||
|
With the addition of GridFSBuckets and its associated classes in the 3.1 driver, GridFS and its associated classes are effectively deprecated, and the bar for fixing issues there is pretty high. Given that, I'm going to close this minor bug as Won't Fix. | ||||||||||||||
| Comment by Francisco Manuel Benitez Chico [ 21/Jan/16 ] | ||||||||||||||
|
Many thanks Jeff! No problem, I can use another overloaded method It was just to inform your team about that. Have a nice day! Regards, | ||||||||||||||
| Comment by Jeffrey Yemin [ 21/Jan/16 ] | ||||||||||||||
|
Hi Francisco, It's nice to meet you too. I hope you enjoyed the courses, especially mine. What you've found is a bug, but based on the API all that the driver could do better is to throw a more informative exception. In order to use GridFSInputFile.save, you must use one of the overloaded GridFS.createFile methods that take either an InputStream or a File. For the other createFile overloads, it's expected that instead of calling GridFSInputFile.save you call GridFSInputFile.getOutputStream and write the file contents to that output stream. Regards, | ||||||||||||||
| Comment by Francisco Manuel Benitez Chico [ 21/Jan/16 ] | ||||||||||||||
|
Hello Jeff! Nice to meet you here by Jira! I finished three MongoDB online courses and one of them you were the teacher It is not common to do that, but it would be possible and throws a NullPointerException:
And here is the exception stack trace:
Thanks! Cheers, | ||||||||||||||
| Comment by Jeffrey Yemin [ 21/Jan/16 ] | ||||||||||||||
|
Can you share a code snippet that reproduces the exception? As you have probably noticed, there are a number of overloads of the createFile method, and I'd also like to see what else you're doing with the GridFSInputFile before you call save. | ||||||||||||||
| Comment by Jeffrey Yemin [ 21/Jan/16 ] | ||||||||||||||
|
I updated the description to reflect the correction. Thanks. | ||||||||||||||
| Comment by Francisco Manuel Benitez Chico [ 21/Jan/16 ] | ||||||||||||||
|
I had a mistake in the first paragraph: If I get an instance of GridFSInputFile from the method createFile() of *GridFS*, MongoDB Java Driver assigns null to the attribute _in. |