0

I am trying to getting data based on EpcohSecond but it gives null pointer error, and a warning that

Here: billingPointValues = timeSeriesReadServiceFacade.fetchBillingPointValues(billingPoint, fromEpochSecond, toEpochSecond);

For this line I am getting warning that unboxing of fromEpochSecond may occur null pointer exception. No I idea about this issue at this situation.

The code block is as below:

Long fromEpochSecond = getStartExportEpochSecond(billingPoint, from);
    try {
        validateStartAndEnd(billingPoint, fromEpochSecond, toEpochSecond);
        billingPointValues = timeSeriesReadServiceFacade.fetchBillingPointValues(billingPoint, fromEpochSecond,toEpochSecond);
}

A solution will be a great help.

  • 1
    Most probably: `getStartExportEpochSecond(...)` returns a `null`, which is stored in `fromEpochSecond`. Then, when calling `validateStartAndEnd(...)`, I assume it takes a `long`, not a `Long`. At runtime, java tries to autounbox `fromEpochSecond` from `Long` to `long`, and this is where the `NullPointerException` occurs. The "proper" fix would be to rewrite `getStartExportEpochSecond(...)` to return a `long` (instead of `Long`), which would most probably mean to either return a default value or throwing an `Exception` if no start is found, – Turing85 Jan 01 '23 at 15:42
  • Thanks, It clears the problem. Hopefully now it will be solved. – facebook-100001191095620 Jan 01 '23 at 16:03
  • Why are you using `Long` which allows `null` as value and not the primitive `long` which only allows numbers? – knittl Jan 01 '23 at 18:00
  • Does this answer your question? [What is a NullPointerException, and how do I fix it?](https://stackoverflow.com/questions/218384/what-is-a-nullpointerexception-and-how-do-i-fix-it) – knittl Jan 08 '23 at 14:36

0 Answers0