0.6.4: Range.combine() throws NullPointerException if both p

A discussion forum for the JCommon class library.
Locked
Chuanhao Chiu

0.6.4: Range.combine() throws NullPointerException if both p

Post by Chuanhao Chiu » Thu Aug 22, 2002 4:36 pm

Looking at the source code, it's clear that Range.combine() doesn't anticipate this case. The following code should fix the problem, returning null in this case:

public static Range combine(Range range1, Range range2)
{
if (range1 == null)
return range2;
else if (range2 == null)
return range1;
else
{
double l = Math.min(range1.getLowerBound(), range2.getLowerBound());
double u = Math.max(range1.getUpperBound(), range2.getUpperBound());
return new Range(l, u);
}
}

Locked