[Date Prev][Date Next]
[Chronological]
[Thread]
[Top]
(ITS#6008) LDIFReader throws NPE when trying to read an end of stream twice
- To: openldap-its@OpenLDAP.org
- Subject: (ITS#6008) LDIFReader throws NPE when trying to read an end of stream twice
- From: a8080@hushmail.com
- Date: Sat, 7 Mar 2009 20:20:21 GMT
- Auto-submitted: auto-generated (OpenLDAP-ITS)
Full_Name: Art Alliany
Version: CVS HEAD approx 2.4.14
OS: linux
URL: ftp://ftp.openldap.org/incoming/
Submission from: (NULL) (65.102.51.113)
If the end of a LDIF file stream is reached. LDIFReader returns a null which
is fine. The problem is that if the LDIFReader is called again after the end of
stream is reached it throws a NPE as shown below:
java.lang.NullPointerException
at com.novell.ldap.util.LDIFReader.readRecordFields(LDIFReader.java:333)
at com.novell.ldap.util.LDIFReader.readMessage(LDIFReader.java:273)
classes in java.io.* return -1 if you invoke them multiple times so invoking
LDIFReader should not throw a null pointer exception if invoked again on a
exhausted stream.
Here is the fix:
I, Art Allisany, hereby place the following modifications to OpenLDAP Software
(and only these modifications) into the public domain. Hence, these
modifications may be freely used and/or redistributed for any purpose with or
without attribution and/or other notice.
$ diff -u com/novell/ldap/util/LDIFReader.java.old
com/novell/ldap/util/LDIFReader.java.new
--- com/novell/ldap/util/LDIFReader.java.old 2009-03-06 02:30:22.000000000
-0800
+++ com/novell/ldap/util/LDIFReader.java.new 2009-03-06 02:34:29.000000000
-0800
@@ -270,6 +270,12 @@
public LDAPMessage readMessage()
throws IOException, LDAPException
{
+ if ( this.rFields == null ) {
+ // end of file has already been reached, this readMessage()
+ // call has been invoked after the end of the
+ // ldif file has been reached on previous calls to this method
+ return null;
+ }
readRecordFields(); // read record fields
if ( this.rFields == null ) { // end of file
return null;