Menu

#8 NullPointer Exception due to getFormattedDisks()

open
nobody
None
5
2012-06-21
2012-06-21
Anonymous
No

When using -l on an invalid disk image we get:

Error: null
java.lang.NullPointerException
at com.webcodepro.applecommander.ui.ac.showDirectory(Unknown Source)
at com.webcodepro.applecommander.ui.ac.main(Unknown Source)
at com.webcodepro.applecommander.ui.AppleCommander.main(Unknown Source)

Reason is in class Dsik:
/**
* Determine type of disk, and return the appropriate
* FormattedDisk object. Returns null if none are
* recognized.
*/
public FormattedDisk[] getFormattedDisks() {

But none of the calling locations deals with null, they all expect an empty array instead.
So I'd suggest to change return null to return new FormattedDisk[0].

Best regards, Peter.

Discussion