ocpsoft / prettytime

Social Style Date and Time Formatting for Java
http://ocpsoft.org/prettytime/
Apache License 2.0
1.29k stars 252 forks source link

format(List<Duration>) always throws a NullPointerException #232

Closed astatio closed 1 year ago

astatio commented 2 years ago

When the result of a calculatePreciseDuration() is passed on to a format() a NullPointerException will be thrown. This happens due to not being able to find the corresponding TimeUnit (eg.: Month) in the map named "units" resulting in a null from getFormat(TimeUnit unit).

This specifically happens in this line:

return units.get(unit);

If the unit is a Month (as TimeUnit), this will not find Month (as TimeUnit) in units. Eventually because they're not exactly the same and have different properties.

The function for context:

public TimeFormat getFormat(TimeUnit unit)
   {
      if (unit != null && units.get(unit) != null) {
         return units.get(unit);
      }
      return null;
   }