Hi,
If I have deleted the ISPF Statistics of PDS member names using option =3.5, then a null PdsDirectory.MemberInfo.Statistics object is created for the PDS member(s). This caused a Null Pointer Exception in a certain class and it took me sometime to guess the reason as missing statistics.
It would be nice if the class could throw an exception (such as NoStatsException) if statistics are not available for a PDS member.
Regards,
Nags.
Null PdsDirectory.MemberInfo.Statistics object
-
- Posts: 30
- Joined: Thu Jan 25, 2007 8:31 am
- Location: Bengaluru, India
Null PdsDirectory.MemberInfo.Statistics object
Debugging tip:
When you have eliminated all which is impossible, then whatever remains, however improbable, must be the truth.
--Sherlock Holmes
When you have eliminated all which is impossible, then whatever remains, however improbable, must be the truth.
--Sherlock Holmes
-
- Posts: 30
- Joined: Thu Jan 25, 2007 8:31 am
- Location: Bengaluru, India
Hi,
For this class :
I get an Exception as :
where line number 15 is :
I could confirm that pms is created as a null object by inserting an if statement after the creation of pms to see if it was null. The if statement evaluates to true.
For this class :
Code: Select all
package pdsStat;
import java.util.Date;
import java.util.Iterator;
import com.ibm.jzos.*;
import java.io.IOException;
public class PDSStatistics {
public static void main(String[] args) {
String pdsName = args[0];
try {
PdsDirectory pdir = new PdsDirectory(pdsName);
for (Iterator iter = pdir.iterator(); iter.hasNext();) {
PdsDirectory.MemberInfo pm = (PdsDirectory.MemberInfo) iter.next();
PdsDirectory.MemberInfo.Statistics pms = pm.getStatistics();
Date modifDate = pms.modificationDate;
System.out.println("Modification date : " + modifDate);
}
} catch (IOException i) {
i.printStackTrace();
}
}
}
Code: Select all
Exception in thread "main" java.lang.NullPointerException
.at pdsStat.PDSStatistics.main(PDSStatistics.java:15)
Code: Select all
Date modifDate = pms.modificationDate;
Debugging tip:
When you have eliminated all which is impossible, then whatever remains, however improbable, must be the truth.
--Sherlock Holmes
When you have eliminated all which is impossible, then whatever remains, however improbable, must be the truth.
--Sherlock Holmes
I think that the code is behaving as designed - the getStatistics() method returns null if there is no statistics. If it were changed to throw an exception, then it would break other applications that were expecting "null" to mean "not found".
My only suggestion would be to change your code to have something like this.
My only suggestion would be to change your code to have something like this.
Code: Select all
if (pms != null) {
Date modifDate = pms.modificationDate;
System.out.println("Modification date : " + modifDate);
}
-
- Posts: 30
- Joined: Thu Jan 25, 2007 8:31 am
- Location: Bengaluru, India