Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
astatio opened this issue Dec 30, 2021 · 0 comments
Closed

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

astatio opened this issue Dec 30, 2021 · 0 comments

Comments

@astatio
Copy link
Contributor

astatio commented Dec 30, 2021

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;
   }
@astatio astatio changed the title calculatePreciseDuration() returns "Week" where "id = 6" but it should be "id = 18" calculatePreciseDuration(List<Duration>) always throws a NullPointerException Apr 24, 2022
@astatio astatio changed the title calculatePreciseDuration(List<Duration>) always throws a NullPointerException format(List<Duration>) always throws a NullPointerException Apr 24, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants