Skip to content

NULL being returned for a Boolean object #4232

@scuniff

Description

@scuniff

public Boolean checkHeader() throws IOException {
if (in.length() < 4) return null;
// byte order must be II or MM
in.seek(0);
int endianOne = in.read();
int endianTwo = in.read();
boolean littleEndian = endianOne == TiffConstants.LITTLE &&
endianTwo == TiffConstants.LITTLE; // II
boolean bigEndian = endianOne == TiffConstants.BIG &&
endianTwo == TiffConstants.BIG; // MM
if (!littleEndian && !bigEndian) return null;
// check magic number (42)
in.order(littleEndian);
short magic = in.readShort();
bigTiff = magic == TiffConstants.BIG_TIFF_MAGIC_NUMBER;
if (magic != TiffConstants.MAGIC_NUMBER &&
magic != TiffConstants.BIG_TIFF_MAGIC_NUMBER)
{
return null;
}

Referring to above, there are 3 places in method checkHeader() a null is returned. This will cause a Null Pointer Exception for those callers that are returned the result to a boolean data type and not the Boolean object.

Here are 2 examples of callers expecting boolean data type and not Boolean object:

in.order(tp.checkHeader().booleanValue());

Here’s an example of code checking for NULL and taking appropriate action:

Boolean littleEndian = tiffParser.checkHeader();
if (littleEndian == null) {
throw new FormatException("Invalid TIFF file: " + id);
}
boolean little = littleEndian.booleanValue();

If it’s thought that this is an issue, my Eclipse seems to indicate there are about 10 other callers with this NPE situation.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions