Skip to content

Commit e177d74

Browse files
JAVA-363: npe fix
1 parent da8fd05 commit e177d74

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

src/main/com/mongodb/gridfs/GridFSFile.java

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -67,11 +67,16 @@ public void validate() throws MongoException {
6767
DBObject cmd = new BasicDBObject( "filemd5" , _id );
6868
cmd.put( "root" , _fs._bucketName );
6969
DBObject res = _fs._db.command( cmd );
70-
String m = res.get( "md5" ).toString();
71-
if ( m.equals( _md5 ) )
72-
return;
70+
if ( res != null && res.containsField( "md5" ) ) {
71+
String m = res.get( "md5" ).toString();
72+
if ( m.equals( _md5 ) )
73+
return;
74+
throw new MongoException( "md5 differ. mine [" + _md5 + "] theirs [" + m + "]" );
75+
}
76+
77+
// no md5 from the server
78+
throw new MongoException( "no md5 returned from server: " + res );
7379

74-
throw new MongoException( "md5 differ. mine [" + _md5 + "] theirs [" + m + "]" );
7580
}
7681

7782
/**

0 commit comments

Comments
 (0)